# chatgpt-java
**Repository Path**: m9d2/chatgpt-java
## Basic Information
- **Project Name**: chatgpt-java
- **Description**: ChatGPT Spring boot starter - ChatGPT Java版本SDK,开箱即用,支持Spring Boot项目快速集成
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 38
- **Forks**: 18
- **Created**: 2023-03-11
- **Last Updated**: 2024-06-25
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Java ChatGPT
[](https://github.com/m9d2/chatgpt/releases)
[](https://mvnrepository.com/artifact/cn.m9d2.chatgpt/chatgpt)
[](https://github.com/m9d2/chatgpt/blob/main/LICENSE)
This library provides unofficial Java clients for OpenAI's apis.
Languages: English | [中文](README_CN.md)
## Supported APIs
- [Audio](https://platform.openai.com/docs/api-reference/audio)
- [Chat](https://platform.openai.com/docs/api-reference/chat)
- [Completions](https://platform.openai.com/docs/api-reference/completions)
- [images](https://platform.openai.com/docs/api-reference/images)
## Quick start
### Introducing Dependencies
```xml
io.github.m9d2
chatgpt-spring-boot-starter
{release-version}
```
### Configure application.yml
```yaml
chatpgt:
config:
api-key: "YOUR OWNER KEY"
proxy:
enable: true
type: http
hostname: 127.0.0.1
port: 1087
connect-timeout: 60000
read-timeout: 60000
```
### Sample
```java
@SpringBootApplication
public class SampleApplication implements ApplicationRunner {
@Autowired
private OpenAIService openAIService;
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
Completions completions = new Completions();
List messages = new ArrayList<>();
Message message = new Message();
message.setContent("hello");
message.setRole("user");
messages.add(message);
completions.setMessages(messages);
CompletionsResponse response = openAIService.completions(completions);
for (CompletionsResponse.Choice choice : response.getChoices()) {
System.out.print(choice.getMessage().getContent());
}
}
}
```