refactor: use `cmp.Or` in more places

Andrey Nering created

Change summary

providers/anthropic/anthropic.go | 13 ++++---------
providers/openai/openai.go       | 15 ++++-----------
2 files changed, 8 insertions(+), 20 deletions(-)

Detailed changes

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 {

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 {