Skip to content

Commit 92f4830

Browse files
authored
fix: #794 (#797)
1 parent 27c1c56 commit 92f4830

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

client.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10+
"net/url"
1011
"strings"
1112

1213
utils "github.com/sashabaranov/go-openai/internal"
@@ -228,10 +229,13 @@ func (c *Client) fullURL(suffix string, args ...any) string {
228229
if c.config.APIType == APITypeAzure || c.config.APIType == APITypeAzureAD {
229230
baseURL := c.config.BaseURL
230231
baseURL = strings.TrimRight(baseURL, "/")
232+
parseURL, _ := url.Parse(baseURL)
233+
query := parseURL.Query()
234+
query.Add("api-version", c.config.APIVersion)
231235
// if suffix is /models change to {endpoint}/openai/models?api-version=2022-12-01
232236
// https://learn.microsoft.com/en-us/rest/api/cognitiveservices/azureopenaistable/models/list?tabs=HTTP
233237
if containsSubstr([]string{"/models", "/assistants", "/threads", "/files"}, suffix) {
234-
return fmt.Sprintf("%s/%s%s?api-version=%s", baseURL, azureAPIPrefix, suffix, c.config.APIVersion)
238+
return fmt.Sprintf("%s/%s%s?%s", baseURL, azureAPIPrefix, suffix, query.Encode())
235239
}
236240
azureDeploymentName := "UNKNOWN"
237241
if len(args) > 0 {
@@ -240,9 +244,9 @@ func (c *Client) fullURL(suffix string, args ...any) string {
240244
azureDeploymentName = c.config.GetAzureDeploymentByModel(model)
241245
}
242246
}
243-
return fmt.Sprintf("%s/%s/%s/%s%s?api-version=%s",
247+
return fmt.Sprintf("%s/%s/%s/%s%s?%s",
244248
baseURL, azureAPIPrefix, azureDeploymentsPrefix,
245-
azureDeploymentName, suffix, c.config.APIVersion,
249+
azureDeploymentName, suffix, query.Encode(),
246250
)
247251
}
248252

0 commit comments

Comments
 (0)