Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Add logit bias parameter to CompletionRequest (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoKanning authored Dec 4, 2022
1 parent c769239 commit 8d7f240
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

/**
* A request for OpenAi to generate a predicted completion for a prompt.
Expand Down Expand Up @@ -110,6 +111,15 @@ public class CompletionRequest {
*/
Integer bestOf;

/**
* Modify the likelihood of specified tokens appearing in the completion.
*
* Maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100.
*
* https://beta.openai.com/docs/api-reference/completions/create#completions/create-logit_bias
*/
Map<String, Integer> logitBias;

/**
* A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.theokanning.openai.completion.CompletionRequest;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -21,6 +22,7 @@ void createCompletion() {
.prompt("Somebody once told me the world is gonna roll me")
.echo(true)
.user("testing")
.logitBias(new HashMap<>())
.build();

List<CompletionChoice> choices = service.createCompletion(completionRequest).getChoices();
Expand Down

0 comments on commit 8d7f240

Please sign in to comment.