diff --git a/providers/anthropic/anthropic.go b/providers/anthropic/anthropic.go index 7e17013b6557e4224a0d43b5151224f6e829424a..b2d089da17de66b35048e474162d488075fdcd63 100644 --- a/providers/anthropic/anthropic.go +++ b/providers/anthropic/anthropic.go @@ -1,6 +1,7 @@ package anthropic import ( + "cmp" "context" "encoding/base64" "encoding/json" @@ -37,17 +38,11 @@ func New(opts ...Option) ai.Provider { for _, o := range opts { o(&options) } - if options.baseURL == "" { - options.baseURL = "https://api.anthropic.com" - } - if options.name == "" { - options.name = "anthropic" - } + options.baseURL = cmp.Or(options.baseURL, "https://api.anthropic.com") + options.name = cmp.Or(options.name, "anthropic") - return &provider{ - options: options, - } + return &provider{options: options} } func WithBaseURL(baseURL string) Option { diff --git a/providers/openai/openai.go b/providers/openai/openai.go index d8e30cedd7607bd0cf8335425e2f67da6193207f..3c27222a1f4f4d24fb24a74c741f515a3a3e5f58 100644 --- a/providers/openai/openai.go +++ b/providers/openai/openai.go @@ -1,6 +1,7 @@ package openai import ( + "cmp" "context" "encoding/base64" "encoding/json" @@ -43,25 +44,17 @@ func New(opts ...Option) ai.Provider { o(&options) } - if options.baseURL == "" { - options.baseURL = "https://api.openai.com/v1" - } - - if options.name == "" { - options.name = "openai" - } + options.baseURL = cmp.Or(options.baseURL, "https://api.openai.com/v1") + options.name = cmp.Or(options.name, "openai") if options.organization != "" { options.headers["OpenAi-Organization"] = options.organization } - if options.project != "" { options.headers["OpenAi-Project"] = options.project } - return &provider{ - options: options, - } + return &provider{options: options} } func WithBaseURL(baseURL string) Option {