Skip to content

Commit

Permalink
fix: #794 (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiixy authored Jul 19, 2024
1 parent 27c1c56 commit 92f4830
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"strings"

utils "github.com/sashabaranov/go-openai/internal"
Expand Down Expand Up @@ -228,10 +229,13 @@ func (c *Client) fullURL(suffix string, args ...any) string {
if c.config.APIType == APITypeAzure || c.config.APIType == APITypeAzureAD {
baseURL := c.config.BaseURL
baseURL = strings.TrimRight(baseURL, "/")
parseURL, _ := url.Parse(baseURL)
query := parseURL.Query()
query.Add("api-version", c.config.APIVersion)
// if suffix is /models change to {endpoint}/openai/models?api-version=2022-12-01
// https://learn.microsoft.com/en-us/rest/api/cognitiveservices/azureopenaistable/models/list?tabs=HTTP
if containsSubstr([]string{"/models", "/assistants", "/threads", "/files"}, suffix) {
return fmt.Sprintf("%s/%s%s?api-version=%s", baseURL, azureAPIPrefix, suffix, c.config.APIVersion)
return fmt.Sprintf("%s/%s%s?%s", baseURL, azureAPIPrefix, suffix, query.Encode())
}
azureDeploymentName := "UNKNOWN"
if len(args) > 0 {
Expand All @@ -240,9 +244,9 @@ func (c *Client) fullURL(suffix string, args ...any) string {
azureDeploymentName = c.config.GetAzureDeploymentByModel(model)
}
}
return fmt.Sprintf("%s/%s/%s/%s%s?api-version=%s",
return fmt.Sprintf("%s/%s/%s/%s%s?%s",
baseURL, azureAPIPrefix, azureDeploymentsPrefix,
azureDeploymentName, suffix, c.config.APIVersion,
azureDeploymentName, suffix, query.Encode(),
)
}

Expand Down

0 comments on commit 92f4830

Please sign in to comment.