Files
2026-06-22 08:55:57 +08:00

24 lines
993 B
Go

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. 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) }