@@ -200,7 +200,15 @@ type ChatCompletionRequest struct {
200
200
// incorrect: `"logit_bias":{"You": 6}`, correct: `"logit_bias":{"1639": 6}`
201
201
// refs: https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias
202
202
LogitBias map [string ]int `json:"logit_bias,omitempty"`
203
- User string `json:"user,omitempty"`
203
+ // LogProbs indicates whether to return log probabilities of the output tokens or not.
204
+ // If true, returns the log probabilities of each output token returned in the content of message.
205
+ // This option is currently not available on the gpt-4-vision-preview model.
206
+ LogProbs bool `json:"logprobs,omitempty"`
207
+ // TopLogProbs is an integer between 0 and 5 specifying the number of most likely tokens to return at each
208
+ // token position, each with an associated log probability.
209
+ // logprobs must be set to true if this parameter is used.
210
+ TopLogProbs int `json:"top_logprobs,omitempty"`
211
+ User string `json:"user,omitempty"`
204
212
// Deprecated: use Tools instead.
205
213
Functions []FunctionDefinition `json:"functions,omitempty"`
206
214
// Deprecated: use ToolChoice instead.
@@ -244,6 +252,28 @@ type FunctionDefinition struct {
244
252
// Deprecated: use FunctionDefinition instead.
245
253
type FunctionDefine = FunctionDefinition
246
254
255
+ type TopLogProbs struct {
256
+ Token string `json:"token"`
257
+ LogProb float64 `json:"logprob"`
258
+ Bytes []byte `json:"bytes,omitempty"`
259
+ }
260
+
261
+ // LogProb represents the probability information for a token.
262
+ type LogProb struct {
263
+ Token string `json:"token"`
264
+ LogProb float64 `json:"logprob"`
265
+ Bytes []byte `json:"bytes,omitempty"` // Omitting the field if it is null
266
+ // TopLogProbs is a list of the most likely tokens and their log probability, at this token position.
267
+ // In rare cases, there may be fewer than the number of requested top_logprobs returned.
268
+ TopLogProbs []TopLogProbs `json:"top_logprobs"`
269
+ }
270
+
271
+ // LogProbs is the top-level structure containing the log probability information.
272
+ type LogProbs struct {
273
+ // Content is a list of message content tokens with log probability information.
274
+ Content []LogProb `json:"content"`
275
+ }
276
+
247
277
type FinishReason string
248
278
249
279
const (
@@ -273,6 +303,7 @@ type ChatCompletionChoice struct {
273
303
// content_filter: Omitted content due to a flag from our content filters
274
304
// null: API response still in progress or incomplete
275
305
FinishReason FinishReason `json:"finish_reason"`
306
+ LogProbs * LogProbs `json:"logprobs,omitempty"`
276
307
}
277
308
278
309
// ChatCompletionResponse represents a response structure for chat completion API.
0 commit comments