Add option to set BaseURL in NewMistralClient
This commit is contained in:
+16
-3
@@ -127,13 +127,24 @@ type MistralClientImpl struct {
|
|||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a new Mistral API client
|
type MistralClientOption = func(*MistralClientImpl)
|
||||||
func NewMistralClient(apiKey string) *MistralClientImpl {
|
|
||||||
return &MistralClientImpl{
|
func BaseUrlOption(url string) MistralClientOption {
|
||||||
|
return func(c *MistralClientImpl) {
|
||||||
|
c.BaseURL = url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMistralClient(apiKey string, options ...MistralClientOption) *MistralClientImpl {
|
||||||
|
client := &MistralClientImpl{
|
||||||
APIKey: apiKey,
|
APIKey: apiKey,
|
||||||
BaseURL: "https://api.mistral.ai",
|
BaseURL: "https://api.mistral.ai",
|
||||||
HTTPClient: &http.Client{},
|
HTTPClient: &http.Client{},
|
||||||
}
|
}
|
||||||
|
for _, option := range options {
|
||||||
|
option(client)
|
||||||
|
}
|
||||||
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateChatCompletion sends a chat completion request to the API
|
// CreateChatCompletion sends a chat completion request to the API
|
||||||
@@ -150,6 +161,8 @@ func (c *MistralClientImpl) CreateChatCompletion(req *ChatCompletionRequest) (*C
|
|||||||
|
|
||||||
request.Header.Set("Content-Type", "application/json")
|
request.Header.Set("Content-Type", "application/json")
|
||||||
request.Header.Set("Authorization", "Bearer "+c.APIKey)
|
request.Header.Set("Authorization", "Bearer "+c.APIKey)
|
||||||
|
ersteller.Debug("authorization", "Bearer ", c.APIKey)
|
||||||
|
ersteller.Debug("base url", c.BaseURL)
|
||||||
|
|
||||||
response, err := c.HTTPClient.Do(request)
|
response, err := c.HTTPClient.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user