Skip to content

Commit 181fc2a

Browse files
authored
docs: explanation about LogitBias. (129) (#426)
1 parent 7b22898 commit 181fc2a

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

chat.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ type ChatCompletionRequest struct {
5252
Stop []string `json:"stop,omitempty"`
5353
PresencePenalty float32 `json:"presence_penalty,omitempty"`
5454
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"`
55-
LogitBias map[string]int `json:"logit_bias,omitempty"`
56-
User string `json:"user,omitempty"`
57-
Functions []FunctionDefinition `json:"functions,omitempty"`
58-
FunctionCall any `json:"function_call,omitempty"`
55+
// LogitBias is must be a token id string (specified by their token ID in the tokenizer), not a word string.
56+
// incorrect: `"logit_bias":{"You": 6}`, correct: `"logit_bias":{"1639": 6}`
57+
// refs: https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias
58+
LogitBias map[string]int `json:"logit_bias,omitempty"`
59+
User string `json:"user,omitempty"`
60+
Functions []FunctionDefinition `json:"functions,omitempty"`
61+
FunctionCall any `json:"function_call,omitempty"`
5962
}
6063

6164
type FunctionDefinition struct {

completion.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,25 @@ func checkPromptType(prompt any) bool {
109109

110110
// CompletionRequest represents a request structure for completion API.
111111
type CompletionRequest struct {
112-
Model string `json:"model"`
113-
Prompt any `json:"prompt,omitempty"`
114-
Suffix string `json:"suffix,omitempty"`
115-
MaxTokens int `json:"max_tokens,omitempty"`
116-
Temperature float32 `json:"temperature,omitempty"`
117-
TopP float32 `json:"top_p,omitempty"`
118-
N int `json:"n,omitempty"`
119-
Stream bool `json:"stream,omitempty"`
120-
LogProbs int `json:"logprobs,omitempty"`
121-
Echo bool `json:"echo,omitempty"`
122-
Stop []string `json:"stop,omitempty"`
123-
PresencePenalty float32 `json:"presence_penalty,omitempty"`
124-
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"`
125-
BestOf int `json:"best_of,omitempty"`
126-
LogitBias map[string]int `json:"logit_bias,omitempty"`
127-
User string `json:"user,omitempty"`
112+
Model string `json:"model"`
113+
Prompt any `json:"prompt,omitempty"`
114+
Suffix string `json:"suffix,omitempty"`
115+
MaxTokens int `json:"max_tokens,omitempty"`
116+
Temperature float32 `json:"temperature,omitempty"`
117+
TopP float32 `json:"top_p,omitempty"`
118+
N int `json:"n,omitempty"`
119+
Stream bool `json:"stream,omitempty"`
120+
LogProbs int `json:"logprobs,omitempty"`
121+
Echo bool `json:"echo,omitempty"`
122+
Stop []string `json:"stop,omitempty"`
123+
PresencePenalty float32 `json:"presence_penalty,omitempty"`
124+
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"`
125+
BestOf int `json:"best_of,omitempty"`
126+
// LogitBias is must be a token id string (specified by their token ID in the tokenizer), not a word string.
127+
// incorrect: `"logit_bias":{"You": 6}`, correct: `"logit_bias":{"1639": 6}`
128+
// refs: https://platform.openai.com/docs/api-reference/completions/create#completions/create-logit_bias
129+
LogitBias map[string]int `json:"logit_bias,omitempty"`
130+
User string `json:"user,omitempty"`
128131
}
129132

130133
// CompletionChoice represents one of possible completions.

0 commit comments

Comments
 (0)