Skip to content

Commit 567b10b

Browse files
committed
refactor: use cmp.Or in more places
1 parent 999fe4a commit 567b10b

2 files changed

Lines changed: 8 additions & 20 deletions

File tree

providers/anthropic/anthropic.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package anthropic
22

33
import (
4+
"cmp"
45
"context"
56
"encoding/base64"
67
"encoding/json"
@@ -37,17 +38,11 @@ func New(opts ...Option) ai.Provider {
3738
for _, o := range opts {
3839
o(&options)
3940
}
40-
if options.baseURL == "" {
41-
options.baseURL = "https://api.anthropic.com"
42-
}
4341

44-
if options.name == "" {
45-
options.name = "anthropic"
46-
}
42+
options.baseURL = cmp.Or(options.baseURL, "https://api.anthropic.com")
43+
options.name = cmp.Or(options.name, "anthropic")
4744

48-
return &provider{
49-
options: options,
50-
}
45+
return &provider{options: options}
5146
}
5247

5348
func WithBaseURL(baseURL string) Option {

providers/openai/openai.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package openai
22

33
import (
4+
"cmp"
45
"context"
56
"encoding/base64"
67
"encoding/json"
@@ -43,25 +44,17 @@ func New(opts ...Option) ai.Provider {
4344
o(&options)
4445
}
4546

46-
if options.baseURL == "" {
47-
options.baseURL = "https://api.openai.com/v1"
48-
}
49-
50-
if options.name == "" {
51-
options.name = "openai"
52-
}
47+
options.baseURL = cmp.Or(options.baseURL, "https://api.openai.com/v1")
48+
options.name = cmp.Or(options.name, "openai")
5349

5450
if options.organization != "" {
5551
options.headers["OpenAi-Organization"] = options.organization
5652
}
57-
5853
if options.project != "" {
5954
options.headers["OpenAi-Project"] = options.project
6055
}
6156

62-
return &provider{
63-
options: options,
64-
}
57+
return &provider{options: options}
6558
}
6659

6760
func WithBaseURL(baseURL string) Option {

0 commit comments

Comments
 (0)