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 44ad762

Browse filesBrowse files
committed
Add logprobs field
1 parent f33aea1 commit 44ad762
Copy full SHA for 44ad762

File tree

Expand file treeCollapse file tree

4 files changed

+48
-3
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+48
-3
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Includes the following artifacts:
88
as well as an example project using the client.
99

1010
## Usage
11+
### Using OpenAiService
1112
If you're looking for the fastest solution, import the `client` and use [OpenAiService](client/src/main/java/openai/OpenAiService.java).
1213
```
1314
OpenAiService service = new OpenAiService(your_token)
@@ -17,11 +18,14 @@ completionRequest.setEcho(true);
1718
service.createCompletion("ada", completionRequest).getChoices().forEach(System.out::println);
1819
```
1920

21+
### Using OpenAiApi Retrofit client
2022
If you're using retrofit, you can import the `client` module and use the [OpenAiApi](client/src/main/java/openai/OpenAiApi.java).
2123
You'll have to add your auth token as a header (see [AuthenticationInterceptor](client/src/main/java/openai/AuthenticationInterceptor.java))
2224
and set your converter factory to use snake case and only include non-null fields.
2325

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.
2529

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

‎api/src/main/java/openai/completion/CompletionChoice.java

Copy file name to clipboardExpand all lines: api/src/main/java/openai/completion/CompletionChoice.java
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public class CompletionChoice {
1818
* This index of this completion in the returned list.
1919
*/
2020
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;
2226

2327
/**
2428
* The reason why GPT-3 stopped generating, for example "length".

‎api/src/main/java/openai/completion/CompletionRequest.java

Copy file name to clipboardExpand all lines: api/src/main/java/openai/completion/CompletionRequest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class CompletionRequest {
7474
* Up to 4 sequences where the API will stop generating further tokens.
7575
* The returned text will not contain the stop sequence.
7676
*/
77-
List<String> stop; //todo test this
77+
List<String> stop;
7878

7979
/**
8080
* Number between 0 and 1 (default 0) that penalizes new tokens based on whether they appear in the text so far.
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0 commit comments

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