OpenAI jvm (java, kotlin) client / spring boot starter openai
The code is written in kotlin, but it's okay to use it in java
Made with API version 2023-3-9.
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.herbaccara.openai:openai:Tag'
// if you want to use spring boot auto-configuration
implementation 'com.github.herbaccara.openai:spring-boot-starter-openai:Tag'
}
// java
final OpenAiService openAiService = OpenAiService
.builder()
.apiKey(apiKey)
.validate(true)
.logging(new Logging(true, LoggingLevel.BASIC))
.baseUrl("https://api.openai.com")
.timeout(Duration.ofSeconds(30))
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)))
.build();
final ListModels listModels = openAiService.listModels();
// kotlin
val openAiService = OpenAiService(apiKey)
val listModels: ListModels = openAiService.listModels()
@EnableOpenAi
public class SpringBootApp {
@Autowired
private OpenAiService openAiService;
}
openai:
api-key: your api key
root-uri: https://api.openai.com # optional
timeout: 30s # optional
validate: false # optional
proxy: # optional
host: 123.123.123.123
port: 123
logging: # optional
enable: true
level: BASIC
Published under the MIT License