ScuttleBot

scuttlebot / internal / llm / anthropic_test.go
Blame History Raw 78 lines
1
package llm
2
3
import (
4
"context"
5
"encoding/json"
6
"net/http"
7
"net/http/httptest"
8
"testing"
9
)
10
11
func TestAnthropicSummarize(t *testing.T) {
12
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
13
if r.Method != "POST" {
14
t.Errorf("expected POST request, got %s", r.Method)
15
}
16
if r.URL.Path != "/v1/messages" {
17
t.Errorf("unexpected path: %s", r.URL.Path)
18
}
19
if r.Header.Get("x-api-key") != "test-api-key" {
20
t.Errorf("expected api key test-api-key, got %s", r.Header.Get("x-api-key"))
21
}
22
if r.Header.Get("anthropic-version") != "2023-06-01" {
23
t.Errorf("expected anthropic-version 2023-06-01, got %s", r.Header.Get("anthropic-version"))
24
}
25
26
resp := map[string]any{
27
"content": []map[string]any{
28
{
29
"type": "text",
30
"text": "anthropic response",
31
},
32
},
33
}
34
_ = json.NewEncoder(w).Encode(resp)
35
}))
36
defer srv.Close()
37
38
p := newAnthropicProvider(BackendConfig{
39
Backend: "anthropic",
40
APIKey: "test-api-key",
41
BaseURL: srv.URL,
42
}, srv.Client())
43
44
got, err := p.Summarize(context.Background(), "test prompt")
45
if err != nil {
46
t.Fatalf("Summarize failed: %v", err)
47
}
48
if got != "anthropic response" {
49
t.Errorf("got %q, want %q", got, "anthropic response")
50
}
51
}
52
53
func TestAnthropicDiscoverModels(t *testing.T) {
54
p := newAnthropicProvider(BackendConfig{
55
Backend: "anthropic",
56
APIKey: "test-api-key",
57
}, http.DefaultClient)
58
59
models, err := p.DiscoverModels(context.Background())
60
if err != nil {
61
t.Fatalf("DiscoverModels failed: %v", err)
62
}
63
64
if len(models) == 0 {
65
t.Error("expected non-empty model list")
66
}
67
found := false
68
for _, m := range models {
69
if m.ID == "claude-3-5-sonnet-20241022" {
70
found = true
71
break
72
}
73
}
74
if !found {
75
t.Error("expected to find claude-3-5-sonnet-20241022 in model list")
76
}
77
}
78

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button