Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

43 lines
1.2 KiB
Go

package ollama
import (
"context"
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/zzet/gortex/internal/llm"
)
// TestComplete_UsageStaysZero confirms ollama — a separate impl that does
// not decode a usage block — reports zero usage and does not error, even
// when the response carries token counts. This is the graceful-zero
// contract for the not-yet-decoded HTTP providers.
func TestComplete_UsageStaysZero(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = io.WriteString(w, `{"message":{"role":"assistant","content":"hi there"},
"prompt_eval_count":1234,"eval_count":456}`)
}))
defer srv.Close()
p, err := New(llm.OllamaConfig{Model: "qwen", Host: srv.URL})
if err != nil {
t.Fatal(err)
}
defer p.Close()
resp, err := p.Complete(context.Background(), llm.CompletionRequest{
Messages: []llm.Message{{Role: llm.RoleUser, Content: "hi"}},
})
if err != nil {
t.Fatal(err)
}
if resp.Text != "hi there" {
t.Errorf("text=%q want 'hi there'", resp.Text)
}
if !resp.Usage.IsZero() {
t.Errorf("usage=%+v want zero (ollama does not decode usage)", resp.Usage)
}
}