Go to file
Theo Kanning 427883b253 Removed unused dependencies 2020-10-04 19:51:35 -05:00
example Add search objects and endpoint 2020-10-04 18:25:40 -05:00
gradle/wrapper Initial commit 2020-09-14 17:52:09 -05:00
openai-api Add comments explaining the api object fields 2020-10-04 19:24:24 -05:00
openai-client Removed unused dependencies 2020-10-04 19:51:35 -05:00
.gitattributes Initial commit 2020-09-14 17:52:09 -05:00
.gitignore Initial commit 2020-09-14 17:52:09 -05:00
LICENSE Add MIT License 2020-10-04 18:35:04 -05:00
README.md Update README 2020-10-04 19:50:49 -05:00
build.gradle Add OpenAiService and OpenAiApiExample 2020-09-14 19:22:46 -05:00
gradlew Initial commit 2020-09-14 17:52:09 -05:00
gradlew.bat Initial commit 2020-09-14 17:52:09 -05:00
settings.gradle Move data objects into separate openai-api package 2020-10-04 18:09:48 -05:00

README.md

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

as well as an example project using the client.

How to use this

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

OpenAiService service = new OpenAiService(your_token)
CompletionRequest completionRequest = new CompletionRequest();
completionRequest.setPrompt("Somebody once told me the world is gonna roll me");
completionRequest.setEcho(true);
service.createCompletion("ada", completionRequest).getChoices().forEach(System.out::println);

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.

If you want to make your own client, just import the POJOs from the api module.

Running the example project

All the example project requires is your OpenAI api token

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