Go to file
YuCheng Hu 0dda9fc1f4 Delete all code use for lombok 2023-01-06 12:46:06 -05:00
openai-j-api Delete all code use for lombok 2023-01-06 12:46:06 -05:00
openai-j-client New code for maven 2023-01-06 12:36:47 -05:00
openai-j-example New code for maven 2023-01-06 12:36:47 -05:00
.gitattributes Initial commit 2020-09-14 17:52:09 -05:00
.gitignore Switch to publishing plugin (#8) 2022-04-28 14:19:36 -05:00
LICENSE Fix typo in the LICENSE.md (#22) 2022-08-19 09:31:56 -05:00
README.md Remove deprecated endpoints from example project (#40) 2022-12-04 12:44:30 -06:00
build.gradle Switch to publishing plugin (#8) 2022-04-28 14:19:36 -05:00
gradle.properties Bump version to 0.8.1 (#43) 2022-12-04 13:41:14 -06:00
gradlew Initial commit 2020-09-14 17:52:09 -05:00
gradlew.bat Initial commit 2020-09-14 17:52:09 -05:00
pom.xml Delete all code use for lombok 2023-01-06 12:46:06 -05:00
settings.gradle Rename modules to api and client 2020-10-04 21:30:20 -05:00

README.md

Maven Central

⚠️The Answers, Classifications, and Searches APIs are deprecated, and will stop working on December 3rd, 2022.

⚠️OpenAI has deprecated all Engine-based APIs. See Deprecated Endpoints below for more info.

OpenAI-Java

Java libraries for using OpenAI's GPT-3 api.

Includes the following artifacts:

  • api : request/response POJOs for the GPT-3 engine, completion, and search APIs.
  • client : a basic retrofit client for the GPT-3 endpoints, includes the api module

as well as an example project using the client.

Supported APIs

Deprecated by OpenAI

Usage

Importing into a gradle project

implementation 'com.theokanning.openai-gpt3-java:api:<version>'
or
implementation 'com.theokanning.openai-gpt3-java:client:<version>'

Using OpenAiService

If you're looking for the fastest solution, import the client and use OpenAiService.

OpenAiService service = new OpenAiService("your_token");
CompletionRequest completionRequest = CompletionRequest.builder()
        .prompt("Somebody once told me the world is gonna roll me")
        .model("ada")
        .echo(true)
        .build();
service.createCompletion(completionRequest).getChoices().forEach(System.out::println);

Using OpenAiApi Retrofit client

If you're using retrofit, you can import the client module and use the OpenAiApi.
You'll have to add your auth token as a header (see AuthenticationInterceptor) and set your converter factory to use snake case and only include non-null fields.

Using data classes only

If you want to make your own client, just import the POJOs from the api module.
Your client will need to use snake case to work with the OpenAI API.

Running the example project

All the example project requires is your OpenAI api token

export OPENAI_TOKEN="sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
./gradlew example:run

Deprecated Endpoints

OpenAI has deprecated engine-based endpoints in favor of model-based endpoints. For example, instead of using v1/engines/{engine_id}/completions, switch to v1/completions and specify the model in the CompletionRequest. The code includes upgrade instructions for all deprecated endpoints.

I won't remove the old endpoints from this library until OpenAI shuts them down.

License

Published under the MIT License