mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-20 14:13:23 +00:00
hanzo-inc/cloud#460 (moved from #116) listed eight defects at c7f85eed. Seven
were still on main; this fixes them.
A LocalModelProvider of type Zen, Enso or Hanzo had no client, and neither did
DeepSeek with a model other than chat or reasoner, so the first call
dereferenced nil. dialect() now names each type's client and flush once, with
typed values in place of an `any` asserted in each loop, and QueryText refuses
a type with no client. That also ends the assertion panics: OpenAI completion
models asserted the answer-only flush while holding the think one, and so did
Local and DigitalOcean completion models in local.go. Both completion loops
now skip a chunk with no choice, and local.go's no longer returns a nil result
with no error when the count fails.
DeepSeek, Mistral, SiliconFlow, Baichuan and BaiduCloud priced the total token
count at both the input and the output rate. The prompt is now priced at the
input rate and the answer at the output rate. gpt-4.5's case sat after
gpt-4's, which also matches it, so gpt-4.5 billed as gpt-4; it now comes first
and bills at the rate the pricing table publishes.
GetMessagesForChats bound the chat names to a bare "{:p0}" WHERE; it is
dbx.In("chat", ...). updateErrorText's branches were inverted, so a record
with no id updated WHERE id = 0. The Guacamole handshake returned nil on a
failed write, and UploadVideo returned "", nil on each failure; both return
the error.
Item 7 (gateway frames) is left: the gateway's own errors are gateway frames
now, but its chat, models and balance fast paths still answer with cloud
frames. That needs hanzoai/gateway's side confirmed first.
66 lines
2.5 KiB
Go
66 lines
2.5 KiB
Go
// Copyright 2026 Hanzo AI Inc. All Rights Reserved.
|
|
|
|
package model
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
// A thousand tokens asked and three thousand answered: the prompt is priced at
|
|
// the input rate and the answer at the output rate. These five priced the TOTAL
|
|
// at both rates, so every call was charged for its whole length twice over.
|
|
func TestPromptAndAnswerArePricedAtTheirOwnRates(t *testing.T) {
|
|
for _, c := range []struct {
|
|
name string
|
|
price func(*ModelResult, string) error
|
|
in, out float64 // the table's per-thousand rates for that model
|
|
currency string
|
|
}{
|
|
{"deepseek-chat", (&DeepSeekProvider{subType: "deepseek-chat"}).calculatePrice, 0.002, 0.003, "CNY"},
|
|
{"mistral-large-latest", (&MistralModelProvider{modelName: "mistral-large-latest"}).calculatePrice, 0.002, 0.006, "USD"},
|
|
{"deepseek-ai/DeepSeek-R1", (&SiliconFlowProvider{subType: "deepseek-ai/DeepSeek-R1"}).calculatePrice, 0.004, 0.016, "CNY"},
|
|
{"Baichuan4-Air", (&BaichuanModelProvider{subType: "Baichuan4-Air"}).calculatePrice, 0.00098, 0.00098, "CNY"},
|
|
{"ernie-4.0-8k", (&BaiduCloudModelProvider{subType: "ernie-4.0-8k"}).calculatePrice, 0.03, 0.09, "CNY"},
|
|
} {
|
|
result := &ModelResult{PromptTokenCount: 1000, ResponseTokenCount: 3000, TotalTokenCount: 4000}
|
|
if err := c.price(result, "en"); err != nil {
|
|
t.Errorf("%s: %v", c.name, err)
|
|
continue
|
|
}
|
|
want := 1*c.in + 3*c.out
|
|
if math.Abs(result.TotalPrice-want) > 1e-9 {
|
|
t.Errorf("%s: 1k in + 3k out = %v, want %v", c.name, result.TotalPrice, want)
|
|
}
|
|
if result.Currency != c.currency {
|
|
t.Errorf("%s: currency %q, want %q", c.name, result.Currency, c.currency)
|
|
}
|
|
}
|
|
}
|
|
|
|
// gpt-4.5 is billed at the rate the pricing table publishes for it. Its case sat
|
|
// after gpt-4's, which matches "gpt-4.5" too, so it was never reached and
|
|
// gpt-4.5 was charged as gpt-4. The neighbours keep their own rates.
|
|
func TestGpt45IsBilledAtItsOwnRate(t *testing.T) {
|
|
for _, c := range []struct {
|
|
model string
|
|
in, out float64
|
|
}{
|
|
{"gpt-4.5-preview", 0.002, 0.008},
|
|
{"gpt-4.5-mini", 0.0004, 0.0016},
|
|
{"gpt-4.5-nano", 0.0001, 0.0004},
|
|
{"gpt-4", 0.03, 0.06},
|
|
{"gpt-4-turbo", 0.01, 0.03},
|
|
{"gpt-4o", 0.0025, 0.0075},
|
|
{"gpt-4.1", 0.002, 0.008},
|
|
} {
|
|
result := &ModelResult{PromptTokenCount: 1000, ResponseTokenCount: 1000, TotalTokenCount: 2000}
|
|
if err := CalculateOpenAIModelPrice(c.model, result, "en"); err != nil {
|
|
t.Fatalf("%s: %v", c.model, err)
|
|
}
|
|
if want := c.in + c.out; math.Abs(result.TotalPrice-want) > 1e-9 {
|
|
t.Errorf("%s: 1k in + 1k out = %v, want %v", c.model, result.TotalPrice, want)
|
|
}
|
|
}
|
|
}
|