Skip to content

Commit fcdf057

Browse files
committed
refactor(openaicompat): ask base url via an option
1 parent 4e6b149 commit fcdf057

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

openaicompat/openaicompat.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
)
88

99
type options struct {
10+
baseURL string
1011
openaiOptions []openai.Option
1112
languageModelOptions []openai.LanguageModelOption
1213
}
@@ -17,11 +18,10 @@ const (
1718

1819
type Option = func(*options)
1920

20-
func New(url string, opts ...Option) ai.Provider {
21+
func New(opts ...Option) ai.Provider {
2122
providerOptions := options{
2223
openaiOptions: []openai.Option{
2324
openai.WithName(Name),
24-
openai.WithBaseURL(url),
2525
},
2626
languageModelOptions: []openai.LanguageModelOption{
2727
openai.WithLanguageModelPrepareCallFunc(languagePrepareModelCall),
@@ -37,6 +37,12 @@ func New(url string, opts ...Option) ai.Provider {
3737
return openai.New(providerOptions.openaiOptions...)
3838
}
3939

40+
func WithBaseURL(url string) Option {
41+
return func(o *options) {
42+
o.openaiOptions = append(o.openaiOptions, openai.WithBaseURL(url))
43+
}
44+
}
45+
4046
func WithAPIKey(apiKey string) Option {
4147
return func(o *options) {
4248
o.openaiOptions = append(o.openaiOptions, openai.WithAPIKey(apiKey))

providertests/openaicompat_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ func testOpenAICompatThinking(t *testing.T, result *ai.AgentResult) {
4444
}
4545
}
4646
}
47-
require.Greater(t, reasoningContentCount, 0)
47+
require.Greater(t, reasoningContentCount, 0, "expected reasoning content, got none")
4848
}
4949

5050
func builderXAIGrokCodeFast(r *recorder.Recorder) (ai.LanguageModel, error) {
5151
provider := openaicompat.New(
52-
"https://api.x.ai/v1",
52+
openaicompat.WithBaseURL("https://api.x.ai/v1"),
5353
openaicompat.WithAPIKey(os.Getenv("FANTASY_XAI_API_KEY")),
5454
openaicompat.WithHTTPClient(&http.Client{Transport: r}),
5555
)
@@ -58,7 +58,7 @@ func builderXAIGrokCodeFast(r *recorder.Recorder) (ai.LanguageModel, error) {
5858

5959
func builderXAIGrok4Fast(r *recorder.Recorder) (ai.LanguageModel, error) {
6060
provider := openaicompat.New(
61-
"https://api.x.ai/v1",
61+
openaicompat.WithBaseURL("https://api.x.ai/v1"),
6262
openaicompat.WithAPIKey(os.Getenv("FANTASY_XAI_API_KEY")),
6363
openaicompat.WithHTTPClient(&http.Client{Transport: r}),
6464
)
@@ -67,7 +67,7 @@ func builderXAIGrok4Fast(r *recorder.Recorder) (ai.LanguageModel, error) {
6767

6868
func builderXAIGrok3Mini(r *recorder.Recorder) (ai.LanguageModel, error) {
6969
provider := openaicompat.New(
70-
"https://api.x.ai/v1",
70+
openaicompat.WithBaseURL("https://api.x.ai/v1"),
7171
openaicompat.WithAPIKey(os.Getenv("FANTASY_XAI_API_KEY")),
7272
openaicompat.WithHTTPClient(&http.Client{Transport: r}),
7373
)
@@ -76,7 +76,7 @@ func builderXAIGrok3Mini(r *recorder.Recorder) (ai.LanguageModel, error) {
7676

7777
func builderZAIGLM45(r *recorder.Recorder) (ai.LanguageModel, error) {
7878
provider := openaicompat.New(
79-
"https://api.z.ai/api/coding/paas/v4",
79+
openaicompat.WithBaseURL("https://api.z.ai/api/coding/paas/v4"),
8080
openaicompat.WithAPIKey(os.Getenv("FANTASY_ZAI_API_KEY")),
8181
openaicompat.WithHTTPClient(&http.Client{Transport: r}),
8282
)
@@ -85,7 +85,7 @@ func builderZAIGLM45(r *recorder.Recorder) (ai.LanguageModel, error) {
8585

8686
func builderGroq(r *recorder.Recorder) (ai.LanguageModel, error) {
8787
provider := openaicompat.New(
88-
"https://api.groq.com/openai/v1",
88+
openaicompat.WithBaseURL("https://api.groq.com/openai/v1"),
8989
openaicompat.WithAPIKey(os.Getenv("FANTASY_GROQ_API_KEY")),
9090
openaicompat.WithHTTPClient(&http.Client{Transport: r}),
9191
)

0 commit comments

Comments
 (0)