-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider_integration_test.go
More file actions
131 lines (103 loc) · 3.45 KB
/
provider_integration_test.go
File metadata and controls
131 lines (103 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"context"
"os"
"testing"
"time"
)
// TestOpenAIProvider tests the OpenAI provider with a real API call
// Requires OPENAI_KEY environment variable
func TestOpenAIProvider(t *testing.T) {
apiKey := os.Getenv("OPENAI_KEY")
if apiKey == "" {
t.Skip("OPENAI_KEY not set, skipping integration test")
}
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
cfg := &ProviderConfig{
Provider: ProviderOpenAI,
APIKey: apiKey,
Models: ModelSettings{Generate: "gpt-5.1"},
}
provider, err := NewProvider(ctx, cfg)
if err != nil {
t.Fatalf("Failed to create OpenAI provider: %v", err)
}
t.Logf("Provider: %s", provider.Name())
messages := []Message{
{Role: "user", Content: "Say 'Hello from bjarne!' - respond with exactly those 3 words."},
}
result, err := provider.Generate(ctx, "gpt-5.1", "You are a helpful assistant. Follow instructions exactly.", messages, 500)
if err != nil {
t.Fatalf("Generate failed: %v", err)
}
t.Logf("Response: %s", result.Text)
t.Logf("Tokens: %d in, %d out", result.InputTokens, result.OutputTokens)
if result.Text == "" {
t.Error("Expected non-empty response")
}
}
// TestAnthropicProvider tests the Anthropic provider with a real API call
// Requires ANTHROPIC_KEY environment variable
func TestAnthropicProvider(t *testing.T) {
apiKey := os.Getenv("ANTHROPIC_KEY")
if apiKey == "" {
t.Skip("ANTHROPIC_KEY not set, skipping integration test")
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
cfg := &ProviderConfig{
Provider: ProviderAnthropic,
APIKey: apiKey,
Models: ModelSettings{Generate: "claude-3-5-haiku-latest"},
}
provider, err := NewProvider(ctx, cfg)
if err != nil {
t.Fatalf("Failed to create Anthropic provider: %v", err)
}
t.Logf("Provider: %s", provider.Name())
messages := []Message{
{Role: "user", Content: "Say 'Hello from bjarne!' - respond with exactly those 3 words."},
}
result, err := provider.Generate(ctx, "claude-3-5-haiku-latest", "You are a helpful assistant. Follow instructions exactly.", messages, 50)
if err != nil {
t.Fatalf("Generate failed: %v", err)
}
t.Logf("Response: %s", result.Text)
t.Logf("Tokens: %d in, %d out", result.InputTokens, result.OutputTokens)
if result.Text == "" {
t.Error("Expected non-empty response")
}
}
// TestGeminiProvider tests the Gemini provider with a real API call
// Requires GEMINI_KEY environment variable
func TestGeminiProvider(t *testing.T) {
apiKey := os.Getenv("GEMINI_KEY")
if apiKey == "" {
t.Skip("GEMINI_KEY not set, skipping integration test")
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
cfg := &ProviderConfig{
Provider: ProviderGemini,
APIKey: apiKey,
Models: ModelSettings{Generate: "gemini-2.5-flash"},
}
provider, err := NewProvider(ctx, cfg)
if err != nil {
t.Fatalf("Failed to create Gemini provider: %v", err)
}
t.Logf("Provider: %s", provider.Name())
messages := []Message{
{Role: "user", Content: "Say 'Hello from bjarne!' - respond with exactly those 3 words."},
}
result, err := provider.Generate(ctx, "gemini-2.5-flash", "You are a helpful assistant. Follow instructions exactly.", messages, 50)
if err != nil {
t.Fatalf("Generate failed: %v", err)
}
t.Logf("Response: %s", result.Text)
t.Logf("Tokens: %d in, %d out", result.InputTokens, result.OutputTokens)
if result.Text == "" {
t.Error("Expected non-empty response")
}
}