Add logprobs field
This commit is contained in:
parent
f33aea18cb
commit
44ad76258c
@ -8,6 +8,7 @@ Includes the following artifacts:
|
|||||||
as well as an example project using the client.
|
as well as an example project using the client.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
### Using OpenAiService
|
||||||
If you're looking for the fastest solution, import the `client` and use [OpenAiService](client/src/main/java/openai/OpenAiService.java).
|
If you're looking for the fastest solution, import the `client` and use [OpenAiService](client/src/main/java/openai/OpenAiService.java).
|
||||||
```
|
```
|
||||||
OpenAiService service = new OpenAiService(your_token)
|
OpenAiService service = new OpenAiService(your_token)
|
||||||
@ -17,11 +18,14 @@ completionRequest.setEcho(true);
|
|||||||
service.createCompletion("ada", completionRequest).getChoices().forEach(System.out::println);
|
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](client/src/main/java/openai/OpenAiApi.java).
|
If you're using retrofit, you can import the `client` module and use the [OpenAiApi](client/src/main/java/openai/OpenAiApi.java).
|
||||||
You'll have to add your auth token as a header (see [AuthenticationInterceptor](client/src/main/java/openai/AuthenticationInterceptor.java))
|
You'll have to add your auth token as a header (see [AuthenticationInterceptor](client/src/main/java/openai/AuthenticationInterceptor.java))
|
||||||
and set your converter factory to use snake case and only include non-null fields.
|
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.
|
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
|
## Running the example project
|
||||||
All the [example](example/src/main/java/example/OpenAiApiExample.java) project requires is your OpenAI api token
|
All the [example](example/src/main/java/example/OpenAiApiExample.java) project requires is your OpenAI api token
|
||||||
|
@ -18,7 +18,11 @@ public class CompletionChoice {
|
|||||||
* This index of this completion in the returned list.
|
* This index of this completion in the returned list.
|
||||||
*/
|
*/
|
||||||
Integer index;
|
Integer index;
|
||||||
// todo add logprobs
|
|
||||||
|
/**
|
||||||
|
* The log probabilities of the chosen tokens and the top {@link CompletionRequest#logprobs} tokens
|
||||||
|
*/
|
||||||
|
LogProbResult logprobs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reason why GPT-3 stopped generating, for example "length".
|
* The reason why GPT-3 stopped generating, for example "length".
|
||||||
|
@ -74,7 +74,7 @@ public class CompletionRequest {
|
|||||||
* Up to 4 sequences where the API will stop generating further tokens.
|
* Up to 4 sequences where the API will stop generating further tokens.
|
||||||
* The returned text will not contain the stop sequence.
|
* The returned text will not contain the stop sequence.
|
||||||
*/
|
*/
|
||||||
List<String> stop; //todo test this
|
List<String> stop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number between 0 and 1 (default 0) that penalizes new tokens based on whether they appear in the text so far.
|
* Number between 0 and 1 (default 0) that penalizes new tokens based on whether they appear in the text so far.
|
||||||
|
37
api/src/main/java/openai/completion/LogProbResult.java
Normal file
37
api/src/main/java/openai/completion/LogProbResult.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package openai.completion;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log probabilities of different token options
|
||||||
|
* Returned if {@link CompletionRequest#logprobs} is greater than zero
|
||||||
|
*
|
||||||
|
* https://beta.openai.com/docs/api-reference/create-completion
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LogProbResult {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tokens chosen by the completion api
|
||||||
|
*/
|
||||||
|
List<String> tokens;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The log probability of each token in {@link tokens}
|
||||||
|
*/
|
||||||
|
List<Double> tokenLogprobs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A map for each index in the completion result.
|
||||||
|
* The map contains the top {@link CompletionRequest#logprobs} tokens and their probabilities
|
||||||
|
*/
|
||||||
|
List<Map<String, Double>> topLogprobs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The character offset from the start of the returned text for each of the chosen tokens.
|
||||||
|
*/
|
||||||
|
List<Integer> textOffset;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user