File tree Expand file tree Collapse file tree 4 files changed +48
-3
lines changed
Filter options
api/src/main/java/openai/completion Expand file tree Collapse file tree 4 files changed +48
-3
lines changed
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ Includes the following artifacts:
8
8
as well as an example project using the client.
9
9
10
10
## Usage
11
+ ### Using OpenAiService
11
12
If you're looking for the fastest solution, import the ` client ` and use [ OpenAiService] ( client/src/main/java/openai/OpenAiService.java ) .
12
13
```
13
14
OpenAiService service = new OpenAiService(your_token)
@@ -17,11 +18,14 @@ completionRequest.setEcho(true);
17
18
service.createCompletion("ada", completionRequest).getChoices().forEach(System.out::println);
18
19
```
19
20
21
+ ### Using OpenAiApi Retrofit client
20
22
If you're using retrofit, you can import the ` client ` module and use the [ OpenAiApi] ( client/src/main/java/openai/OpenAiApi.java ) .
21
23
You'll have to add your auth token as a header (see [ AuthenticationInterceptor] ( client/src/main/java/openai/AuthenticationInterceptor.java ) )
22
24
and set your converter factory to use snake case and only include non-null fields.
23
25
24
- If you want to make your own client, just import the POJOs from the ` api ` module.
26
+ ### Using data classes only
27
+ If you want to make your own client, just import the POJOs from the ` api ` module.
28
+ Your client will need to use snake case to work with the OpenAI API.
25
29
26
30
## Running the example project
27
31
All the [ example] ( example/src/main/java/example/OpenAiApiExample.java ) project requires is your OpenAI api token
Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ public class CompletionChoice {
18
18
* This index of this completion in the returned list.
19
19
*/
20
20
Integer index ;
21
- // todo add logprobs
21
+
22
+ /**
23
+ * The log probabilities of the chosen tokens and the top {@link CompletionRequest#logprobs} tokens
24
+ */
25
+ LogProbResult logprobs ;
22
26
23
27
/**
24
28
* The reason why GPT-3 stopped generating, for example "length".
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ public class CompletionRequest {
74
74
* Up to 4 sequences where the API will stop generating further tokens.
75
75
* The returned text will not contain the stop sequence.
76
76
*/
77
- List <String > stop ; //todo test this
77
+ List <String > stop ;
78
78
79
79
/**
80
80
* Number between 0 and 1 (default 0) that penalizes new tokens based on whether they appear in the text so far.
Original file line number Diff line number Diff line change
1
+ package openai .completion ;
2
+
3
+ import lombok .Data ;
4
+
5
+ import java .util .List ;
6
+ import java .util .Map ;
7
+
8
+ /**
9
+ * Log probabilities of different token options
10
+ * Returned if {@link CompletionRequest#logprobs} is greater than zero
11
+ *
12
+ * https://beta.openai.com/docs/api-reference/create-completion
13
+ */
14
+ @ Data
15
+ public class LogProbResult {
16
+
17
+ /**
18
+ * The tokens chosen by the completion api
19
+ */
20
+ List <String > tokens ;
21
+
22
+ /**
23
+ * The log probability of each token in {@link tokens}
24
+ */
25
+ List <Double > tokenLogprobs ;
26
+
27
+ /**
28
+ * A map for each index in the completion result.
29
+ * The map contains the top {@link CompletionRequest#logprobs} tokens and their probabilities
30
+ */
31
+ List <Map <String , Double >> topLogprobs ;
32
+
33
+ /**
34
+ * The character offset from the start of the returned text for each of the chosen tokens.
35
+ */
36
+ List <Integer > textOffset ;
37
+ }
You can’t perform that action at this time.
0 commit comments