This commit is contained in:
2026-06-22 08:55:57 +08:00
parent dbb87823e8
commit 6ade6e8fa9
325 changed files with 41131 additions and 855 deletions
+11 -3
View File
@@ -2,14 +2,22 @@ package chat
import "strconv"
// computeCost returns the cost in USD for a single LLM call.
// Prices on LLMModel are expressed in USD per million tokens.
func computeCost(m LLMModel, ptok, ctok, ttok int) float64 {
// ComputeCost returns the cost in USD for a single LLM call.
// Prices on LLMModel are expressed in USD per million tokens. Exported so other
// modules (e.g. internal/acp session cost accounting) reuse the single pricing
// formula instead of replicating it.
func ComputeCost(m LLMModel, ptok, ctok, ttok int) float64 {
return (float64(ptok)*m.PromptPricePerMillionUSD +
float64(ctok)*m.CompletionPricePerMillionUSD +
float64(ttok)*m.ThinkingPricePerMillionUSD) / 1_000_000
}
// computeCost is a thin alias kept for the existing internal caller (streamer.go)
// so that change stays untouched while ComputeCost is the public entry point.
func computeCost(m LLMModel, ptok, ctok, ttok int) float64 {
return ComputeCost(m, ptok, ctok, ttok)
}
// int64ToString converts an int64 to its decimal string representation.
// Uses strconv.FormatInt rather than fmt.Sprintf for efficiency.
func int64ToString(v int64) string { return strconv.FormatInt(v, 10) }