Skip to content

Commit 9913264

Browse files
authored
Completion API: add new params (sashabaranov#870)
* Completion API: add 'store' param This param allows you to opt a completion request in to being stored, for use in distillations and evals. * Add cached and audio tokens to usage structs These have been added to the completions API recently: https://platform.openai.com/docs/api-reference/chat/object#chat/object-usage
1 parent 7c145eb commit 9913264

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

common.go

+8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ type Usage struct {
77
PromptTokens int `json:"prompt_tokens"`
88
CompletionTokens int `json:"completion_tokens"`
99
TotalTokens int `json:"total_tokens"`
10+
PromptTokensDetails *PromptTokensDetails `json:"prompt_tokens_details"`
1011
CompletionTokensDetails *CompletionTokensDetails `json:"completion_tokens_details"`
1112
}
1213

1314
// CompletionTokensDetails Breakdown of tokens used in a completion.
1415
type CompletionTokensDetails struct {
16+
AudioTokens int `json:"audio_tokens"`
1517
ReasoningTokens int `json:"reasoning_tokens"`
1618
}
19+
20+
// PromptTokensDetails Breakdown of tokens used in the prompt.
21+
type PromptTokensDetails struct {
22+
AudioTokens int `json:"audio_tokens"`
23+
CachedTokens int `json:"cached_tokens"`
24+
}

completion.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,21 @@ type CompletionRequest struct {
238238
// LogitBias is must be a token id string (specified by their token ID in the tokenizer), not a word string.
239239
// incorrect: `"logit_bias":{"You": 6}`, correct: `"logit_bias":{"1639": 6}`
240240
// refs: https://platform.openai.com/docs/api-reference/completions/create#completions/create-logit_bias
241-
LogitBias map[string]int `json:"logit_bias,omitempty"`
242-
LogProbs int `json:"logprobs,omitempty"`
243-
MaxTokens int `json:"max_tokens,omitempty"`
244-
N int `json:"n,omitempty"`
245-
PresencePenalty float32 `json:"presence_penalty,omitempty"`
246-
Seed *int `json:"seed,omitempty"`
247-
Stop []string `json:"stop,omitempty"`
248-
Stream bool `json:"stream,omitempty"`
249-
Suffix string `json:"suffix,omitempty"`
250-
Temperature float32 `json:"temperature,omitempty"`
251-
TopP float32 `json:"top_p,omitempty"`
252-
User string `json:"user,omitempty"`
241+
LogitBias map[string]int `json:"logit_bias,omitempty"`
242+
// Store can be set to true to store the output of this completion request for use in distillations and evals.
243+
// https://platform.openai.com/docs/api-reference/chat/create#chat-create-store
244+
Store bool `json:"store,omitempty"`
245+
LogProbs int `json:"logprobs,omitempty"`
246+
MaxTokens int `json:"max_tokens,omitempty"`
247+
N int `json:"n,omitempty"`
248+
PresencePenalty float32 `json:"presence_penalty,omitempty"`
249+
Seed *int `json:"seed,omitempty"`
250+
Stop []string `json:"stop,omitempty"`
251+
Stream bool `json:"stream,omitempty"`
252+
Suffix string `json:"suffix,omitempty"`
253+
Temperature float32 `json:"temperature,omitempty"`
254+
TopP float32 `json:"top_p,omitempty"`
255+
User string `json:"user,omitempty"`
253256
}
254257

255258
// CompletionChoice represents one of possible completions.

0 commit comments

Comments
 (0)