-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathbuilders_test.go
More file actions
48 lines (40 loc) · 1.31 KB
/
builders_test.go
File metadata and controls
48 lines (40 loc) · 1.31 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
package providertests
import (
"net/http"
"os"
"github.com/charmbracelet/ai/ai"
"github.com/charmbracelet/ai/anthropic"
"github.com/charmbracelet/ai/openai"
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
)
type builderFunc func(r *recorder.Recorder) (ai.LanguageModel, error)
type builderPair struct {
name string
builder builderFunc
}
var languageModelBuilders = []builderPair{
{"openai-gpt-4o", builderOpenaiGpt4o},
{"openai-gpt-4o-mini", builderOpenaiGpt4oMini},
{"anthropic-claude-sonnet", builderAnthropicClaudeSonnet4},
}
func builderOpenaiGpt4o(r *recorder.Recorder) (ai.LanguageModel, error) {
provider := openai.New(
openai.WithAPIKey(os.Getenv("OPENAI_API_KEY")),
openai.WithHTTPClient(&http.Client{Transport: r}),
)
return provider.LanguageModel("gpt-4o")
}
func builderOpenaiGpt4oMini(r *recorder.Recorder) (ai.LanguageModel, error) {
provider := openai.New(
openai.WithAPIKey(os.Getenv("OPENAI_API_KEY")),
openai.WithHTTPClient(&http.Client{Transport: r}),
)
return provider.LanguageModel("gpt-4o-mini")
}
func builderAnthropicClaudeSonnet4(r *recorder.Recorder) (ai.LanguageModel, error) {
provider := anthropic.New(
anthropic.WithAPIKey(os.Getenv("ANTHROPIC_API_KEY")),
anthropic.WithHTTPClient(&http.Client{Transport: r}),
)
return provider.LanguageModel("claude-sonnet-4-20250514")
}