Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 30e5a92

Browse filesBrowse files
authored
Update README with info about service module (TheoKanning#102)
1 parent 2c6ed51 commit 30e5a92
Copy full SHA for 30e5a92

File tree

Expand file treeCollapse file tree

1 file changed

+36
-26
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+36
-26
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+36-26Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
Java libraries for using OpenAI's GPT-3 api.
77

88
Includes the following artifacts:
9-
- `api` : request/response POJOs for the GPT-3 engine, completion, and search APIs.
9+
- `api` : request/response POJOs for the GPT-3 APIs.
1010
- `client` : a basic retrofit client for the GPT-3 endpoints, includes the `api` module
11+
- `service` : A basic service class that creates and calls the client. This is the easiest way to get started.
1112

12-
as well as an example project using the client.
13+
as well as an example project using the service.
1314

1415
## Supported APIs
1516
- [Models](https://beta.openai.com/docs/api-reference/models)
@@ -24,34 +25,34 @@ as well as an example project using the client.
2425
#### Deprecated by OpenAI
2526
- [Engines](https://beta.openai.com/docs/api-reference/engines)
2627

27-
## Usage
28+
## Importing
2829

29-
### Importing into a gradle project
30-
`implementation 'com.theokanning.openai-gpt3-java:api:<version>'`
31-
or
32-
`implementation 'com.theokanning.openai-gpt3-java:client:<version>'`
30+
### Gradle
31+
`implementation 'com.theokanning.openai-gpt3-java:<api|client|service>:<version>'`
3332

34-
### Importing into a Maven project
33+
### Maven
3534
```xml
3635
<dependency>
3736
<groupId>com.theokanning.openai-gpt3-java</groupId>
38-
<artifactId>api</artifactId>
37+
<artifactId>{api|client|service}</artifactId>
3938
<version>version</version>
4039
</dependency>
4140
```
4241

43-
or
42+
## Usage
43+
### Data classes only
44+
If you want to make your own client, just import the POJOs from the `api` module.
45+
Your client will need to use snake case to work with the OpenAI API.
4446

45-
```xml
46-
<dependency>
47-
<groupId>com.theokanning.openai-gpt3-java</groupId>
48-
<artifactId>client</artifactId>
49-
<version>version</version>
50-
</dependency>
51-
```
47+
### Retrofit client
48+
If you're using retrofit, you can import the `client` module and use the [OpenAiApi](client/src/main/java/com/theokanning/openai/OpenAiApi.java).
49+
You'll have to add your auth token as a header (see [AuthenticationInterceptor](client/src/main/java/com/theokanning/openai/AuthenticationInterceptor.java))
50+
and set your converter factory to use snake case and only include non-null fields.
5251

53-
### Using OpenAiService
54-
If you're looking for the fastest solution, import the `client` and use [OpenAiService](client/src/main/java/com/theokanning/openai/OpenAiService.java).
52+
### OpenAiService
53+
If you're looking for the fastest solution, import the `service` module and use [OpenAiService](client/src/main/java/com/theokanning/openai/OpenAiService.java).
54+
55+
> ⚠️The OpenAiService in the client module is deprecated, please switch to the new version in the service module.
5556
```
5657
OpenAiService service = new OpenAiService("your_token");
5758
CompletionRequest completionRequest = CompletionRequest.builder()
@@ -62,14 +63,23 @@ CompletionRequest completionRequest = CompletionRequest.builder()
6263
service.createCompletion(completionRequest).getChoices().forEach(System.out::println);
6364
```
6465

65-
### Using OpenAiApi Retrofit client
66-
If you're using retrofit, you can import the `client` module and use the [OpenAiApi](client/src/main/java/com/theokanning/openai/OpenAiApi.java).
67-
You'll have to add your auth token as a header (see [AuthenticationInterceptor](client/src/main/java/com/theokanning/openai/AuthenticationInterceptor.java))
68-
and set your converter factory to use snake case and only include non-null fields.
66+
### Customizing OpenAiService
67+
If you need to customize OpenAiService, create your own Retrofit client and pass it in to the constructor.
68+
For example, do the following to add request logging (after adding the logging gradle dependency):
69+
```
70+
ObjectMapper mapper = defaultObjectMapper();
71+
OkHttpClient client = defaultClient(token, timeout)
72+
.newBuilder()
73+
.interceptor(HttpLoggingInterceptor())
74+
.build();
75+
Retrofit retrofit = defaultRetrofit(client, mapper);
76+
77+
OpenAiApi api = retrofit.create(OpenAiApi.class);
78+
OpenAiService service = new OpenAiService(api);
79+
```
80+
81+
6982

70-
### Using data classes only
71-
If you want to make your own client, just import the POJOs from the `api` module.
72-
Your client will need to use snake case to work with the OpenAI API.
7383

7484
## Running the example project
7585
All the [example](example/src/main/java/example/OpenAiApiExample.java) project requires is your OpenAI api token

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.