Skip to content

openai jvm(java, kotlin) client / spring boot starter openai

License

Notifications You must be signed in to change notification settings

herbaccara/openai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7a3558a Β· Apr 11, 2023

History

43 Commits
Mar 10, 2023
Apr 11, 2023
Apr 11, 2023
Mar 8, 2023
Mar 8, 2023
Mar 10, 2023
Apr 11, 2023
Mar 10, 2023
Mar 8, 2023
Mar 8, 2023
Mar 9, 2023

Repository files navigation

OpenAI

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.

How to

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'
}

Supported APIs

To use

// 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()

Spring boot configuration

@EnableOpenAi

@EnableOpenAi
public class SpringBootApp {
    
    @Autowired
    private OpenAiService openAiService;
}

application.yml

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

License

Published under the MIT License