mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
d12092870f
- Update LLMClient test to match NewLLMClient signature by passing nil logger - Add nil check for logger in NewLLMClient to prevent panic, defaulting to slog.Default()
34 lines
835 B
Go
34 lines
835 B
Go
package memory
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestLLMClientExtract(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/chat/completions" {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
return
|
|
}
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write([]byte(`{"choices":[{"message":{"content":"{\"facts\":[\"hello\"]}"}}]}`))
|
|
}))
|
|
defer server.Close()
|
|
|
|
client := NewLLMClient(nil, server.URL, "test-key", "gpt-4.1-nano-2025-04-14", 0)
|
|
resp, err := client.Extract(context.Background(), ExtractRequest{
|
|
Messages: []Message{{Role: "user", Content: "hi"}},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("extract: %v", err)
|
|
}
|
|
if len(resp.Facts) != 1 || resp.Facts[0] != "hello" {
|
|
t.Fatalf("unexpected response: %+v", resp)
|
|
}
|
|
}
|