fix
This commit is contained in:
@@ -43,10 +43,14 @@ type EnableChecker interface {
|
||||
type Completion struct {
|
||||
Text string
|
||||
PromptTokens int
|
||||
OutputTokens int
|
||||
TotalTokens int
|
||||
Model string
|
||||
Raw any
|
||||
// CachedPromptTokens is the cached subset of PromptTokens (OpenAI
|
||||
// usage.prompt_tokens_details.cached_tokens). Billed far cheaper than fresh
|
||||
// input, so cost accounting must subtract it. 0 when the provider omits it.
|
||||
CachedPromptTokens int
|
||||
OutputTokens int
|
||||
TotalTokens int
|
||||
Model string
|
||||
Raw any
|
||||
}
|
||||
|
||||
// Embedder turns text into vectors (OpenAI-compatible /v1/embeddings).
|
||||
|
||||
@@ -242,6 +242,11 @@ type chatResponse struct {
|
||||
PromptTokens int `json:"prompt_tokens"`
|
||||
CompletionTokens int `json:"completion_tokens"`
|
||||
TotalTokens int `json:"total_tokens"`
|
||||
// Cached prompt tokens bill at roughly a tenth of fresh input, and enhance
|
||||
// re-sends a large shared system prompt, so cost is wrong without them.
|
||||
PromptTokensDetails struct {
|
||||
CachedTokens int `json:"cached_tokens"`
|
||||
} `json:"prompt_tokens_details"`
|
||||
} `json:"usage"`
|
||||
Error *openAIErrorBody `json:"error"`
|
||||
}
|
||||
@@ -557,11 +562,12 @@ func (c *OpenAIClient) doComplete(ctx context.Context, system, user string, temp
|
||||
log.Printf("openai: chat content ok model=%s finish_reason=%s content_runes=%d prompt_tokens=%d completion_tokens=%d total_tokens=%d",
|
||||
c.Model, finishReason, len([]rune(text)), usagePrompt, usageOut, usageTotal)
|
||||
return Completion{
|
||||
Text: text,
|
||||
PromptTokens: usagePrompt,
|
||||
OutputTokens: usageOut,
|
||||
TotalTokens: usageTotal,
|
||||
Model: parsed.Model,
|
||||
Text: text,
|
||||
PromptTokens: usagePrompt,
|
||||
CachedPromptTokens: parsed.Usage.PromptTokensDetails.CachedTokens,
|
||||
OutputTokens: usageOut,
|
||||
TotalTokens: usageTotal,
|
||||
Model: parsed.Model,
|
||||
Raw: map[string]any{
|
||||
"model": parsed.Model,
|
||||
"usage": parsed.Usage,
|
||||
|
||||
Reference in New Issue
Block a user