This library provides unofficial Java clients for OpenAI's apis.
Languages: English | 中文
<dependency>
<groupId>io.github.m9d2</groupId>
<artifactId>chatgpt-spring-boot-starter</artifactId>
<version>{release-version}</version>
</dependency>
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
@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<Message> 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());
}
}
}