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
+47
View File
@@ -0,0 +1,47 @@
package chat
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestComputeCost_BasicMath(t *testing.T) {
m := LLMModel{
PromptPricePerMillionUSD: 3.0,
CompletionPricePerMillionUSD: 15.0,
ThinkingPricePerMillionUSD: 3.0,
}
// 1000 prompt tokens × $3/M = $0.003
got := computeCost(m, 1000, 0, 0)
require.InDelta(t, 0.003, got, 1e-9)
// 1000 completion tokens × $15/M = $0.015
got = computeCost(m, 0, 1000, 0)
require.InDelta(t, 0.015, got, 1e-9)
// 1000 thinking tokens × $3/M = $0.003
got = computeCost(m, 0, 0, 1000)
require.InDelta(t, 0.003, got, 1e-9)
// combined: 1000+1000+1000 = $0.021
got = computeCost(m, 1000, 1000, 1000)
require.InDelta(t, 0.021, got, 1e-9)
}
func TestComputeCost_ZeroTokens(t *testing.T) {
m := LLMModel{
PromptPricePerMillionUSD: 3.0,
CompletionPricePerMillionUSD: 15.0,
ThinkingPricePerMillionUSD: 3.0,
}
require.Equal(t, 0.0, computeCost(m, 0, 0, 0))
}
func TestInt64ToString(t *testing.T) {
require.Equal(t, "0", int64ToString(0))
require.Equal(t, "42", int64ToString(42))
require.Equal(t, "-1", int64ToString(-1))
require.Equal(t, "9223372036854775807", int64ToString(9223372036854775807))
}