feat(chat): StreamerHub with ring buffer + cond + Done/Error/Cancel flows

This commit is contained in:
2026-05-04 17:27:50 +08:00
parent d1be9e6eb0
commit 617794c7a3
5 changed files with 1181 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
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 {
return (float64(ptok)*m.PromptPricePerMillionUSD +
float64(ctok)*m.CompletionPricePerMillionUSD +
float64(ttok)*m.ThinkingPricePerMillionUSD) / 1_000_000
}
// 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) }