Go to file
Theo Kanning 4e070027c4 Add github action to publish artifacts after a release 2020-10-05 18:26:56 -05:00
.github/workflows Add github action to publish artifacts after a release 2020-10-05 18:26:56 -05:00
api Add github action to publish artifacts after a release 2020-10-05 18:26:56 -05:00
client Add github action to publish artifacts after a release 2020-10-05 18:26:56 -05:00
example Update package names 2020-10-05 17:44:18 -05:00
gradle/wrapper Include gradle-wrapper.jar 2020-10-05 17:52:21 -05:00
.gitattributes Initial commit 2020-09-14 17:52:09 -05:00
.gitignore Include gradle-wrapper.jar 2020-10-05 17:52:21 -05:00
LICENSE Add MIT License 2020-10-04 18:35:04 -05:00
README.md Add builders to request objects 2020-10-05 17:41:16 -05:00
build.gradle Add bintray publishing tasks to gradle 2020-10-04 20:57:57 -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 Rename modules to api and client 2020-10-04 21:30:20 -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.

Usage

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")
        .echo(true)
        .build();
service.createCompletion("ada", 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

License

Published under the MIT License