44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package llm
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestChatResultIncludesSchemaVersion(t *testing.T) {
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/v1/chat/completions" {
|
|
t.Fatalf("path = %q, want /v1/chat/completions", r.URL.Path)
|
|
}
|
|
_ = json.NewEncoder(w).Encode(map[string]any{
|
|
"model": "qwen2.5-14b",
|
|
"choices": []map[string]any{
|
|
{"message": map[string]string{"role": "assistant", "content": `{"ok":true}`}},
|
|
},
|
|
"usage": map[string]int{
|
|
"prompt_tokens": 10,
|
|
"completion_tokens": 2,
|
|
"total_tokens": 12,
|
|
},
|
|
})
|
|
}))
|
|
defer server.Close()
|
|
|
|
client := New(server.URL, "", "fallback-model", 0)
|
|
got, err := client.Chat(t.Context(), ChatInput{User: "test", MaxTokens: 32})
|
|
if err != nil {
|
|
t.Fatalf("Chat: %v", err)
|
|
}
|
|
if got.SchemaVersion != ChatResultSchemaVersion {
|
|
t.Fatalf("schema_version = %q, want %q", got.SchemaVersion, ChatResultSchemaVersion)
|
|
}
|
|
if got.Content != `{"ok":true}` {
|
|
t.Fatalf("content = %q", got.Content)
|
|
}
|
|
if got.Usage == nil || got.Usage.TotalTokens != 12 {
|
|
t.Fatalf("usage = %#v", got.Usage)
|
|
}
|
|
}
|