feat: support cloudflare AI Gateway flavored azure openai (#715)
* feat: support cloudflare AI Gateway flavored azure openai Signed-off-by: STRRL <im@strrl.dev> * test: add test for cloudflare azure fullURL --------- Signed-off-by: STRRL <im@strrl.dev> Co-authored-by: STRRL <im@strrl.dev>
This commit is contained in:
10
client.go
10
client.go
@@ -182,7 +182,7 @@ func sendRequestStream[T streamable](client *Client, req *http.Request) (*stream
|
||||
func (c *Client) setCommonHeaders(req *http.Request) {
|
||||
// https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#authentication
|
||||
// Azure API Key authentication
|
||||
if c.config.APIType == APITypeAzure {
|
||||
if c.config.APIType == APITypeAzure || c.config.APIType == APITypeCloudflareAzure {
|
||||
req.Header.Set(AzureAPIKeyHeader, c.config.authToken)
|
||||
} else if c.config.authToken != "" {
|
||||
// OpenAI or Azure AD authentication
|
||||
@@ -246,7 +246,13 @@ func (c *Client) fullURL(suffix string, args ...any) string {
|
||||
)
|
||||
}
|
||||
|
||||
// c.config.APIType == APITypeOpenAI || c.config.APIType == ""
|
||||
// https://developers.cloudflare.com/ai-gateway/providers/azureopenai/
|
||||
if c.config.APIType == APITypeCloudflareAzure {
|
||||
baseURL := c.config.BaseURL
|
||||
baseURL = strings.TrimRight(baseURL, "/")
|
||||
return fmt.Sprintf("%s%s?api-version=%s", baseURL, suffix, c.config.APIVersion)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s%s", c.config.BaseURL, suffix)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user