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

Commit 8d7f240

Browse files
authored
Add logit bias parameter to CompletionRequest (#41)
1 parent c769239 commit 8d7f240

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

api/src/main/java/com/theokanning/openai/completion/CompletionRequest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import lombok.NoArgsConstructor;
77

88
import java.util.List;
9+
import java.util.Map;
910

1011
/**
1112
* A request for OpenAi to generate a predicted completion for a prompt.
@@ -110,6 +111,15 @@ public class CompletionRequest {
110111
*/
111112
Integer bestOf;
112113

114+
/**
115+
* Modify the likelihood of specified tokens appearing in the completion.
116+
*
117+
* Maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100.
118+
*
119+
* https://beta.openai.com/docs/api-reference/completions/create#completions/create-logit_bias
120+
*/
121+
Map<String, Integer> logitBias;
122+
113123
/**
114124
* A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse.
115125
*/

client/src/test/java/com/theokanning/openai/CompletionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.theokanning.openai.completion.CompletionRequest;
55
import org.junit.jupiter.api.Test;
66

7+
import java.util.HashMap;
78
import java.util.List;
89

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

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

0 commit comments

Comments
 (0)