A minimalistic unofficial OpenAI API client for the JVM, written in Java
Java 17+ is a prerequisite
implementation("io.github.stefanbratanov:jvm-openai:${version}")
<dependency>
<groupId>io.github.stefanbratanov</groupId>
<artifactId>jvm-openai</artifactId>
<version>${version}</version>
</dependency>
OpenAI openAI = OpenAI.newBuilder(System.getenv("OPENAI_API_KEY")).build();
ChatClient chatClient = openAI.chatClient();
CreateChatCompletionRequest createChatCompletionRequest = CreateChatCompletionRequest.newBuilder()
.model("gpt-3.5-turbo")
.message(ChatMessage.userMessage("Who won the world series in 2020?"))
.build();
ChatCompletion chatCompletion = chatClient.createChatCompletion(createChatCompletionRequest);
// ChatCompletion[id=chatcmpl-123, created=1703506594, model=gpt-3.5-turbo-0613, systemFingerprint=fp_44709d6fcb, choices=[Choice[index=0, message=Message[content=The Los Angeles Dodgers won the World Series in 2020., toolCalls=null, role=assistant], logProbs=null, finishReason=stop]], usage=Usage[promptTokens=17, completionTokens=13, totalTokens=30]]
ImagesClient imagesClient = openAI.imagesClient();
CreateImageRequest createImageRequest = CreateImageRequest.newBuilder()
.model("dall-e-3")
.prompt("A cute baby sea otter")
.build();
Images images = imagesClient.createImage(createImageRequest);
// Images[created=1704009569, data=[Image[b64Json=null, url=https://foo.bar/cute-baby-sea-otter.png, revisedPrompt=Generate an image of a baby sea otter, exuding cuteness. The small, furry creature should be floating blissfully on its back in clear, calm waters, its round button eyes are brimming with innocence and curiosity.]]]
API | Status |
---|---|
Audio | ✔️ |
Chat | ️ ✔️ |
Embeddings | ✔️ |
Fine-tuning | ✔️ |
Files | ✔️ |
Images | ✔️ |
Models | ✔️ |
Moderations | ✔️ |
API | Status |
---|---|
Assistants | ✔️ |
Threads | ️ ✔️ |
Messages | ✔️ |
Runs | ✔️ |