mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 10:40:07 +08:00
fix(azure-openai): normalize Azure endpoint (#12055)
Co-authored-by: William Wang <WilliamOnline1721@hotmail.com>
This commit is contained in:
parent
9f948e1ce7
commit
a35bf4afa1
@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { normalizeAzureOpenAIEndpoint } from '../openai/azureOpenAIEndpoint'
|
||||
|
||||
describe('normalizeAzureOpenAIEndpoint', () => {
|
||||
it.each([
|
||||
{
|
||||
apiHost: 'https://example.openai.azure.com/openai',
|
||||
expectedEndpoint: 'https://example.openai.azure.com'
|
||||
},
|
||||
{
|
||||
apiHost: 'https://example.openai.azure.com/openai/',
|
||||
expectedEndpoint: 'https://example.openai.azure.com'
|
||||
},
|
||||
{
|
||||
apiHost: 'https://example.openai.azure.com/openai/v1',
|
||||
expectedEndpoint: 'https://example.openai.azure.com'
|
||||
},
|
||||
{
|
||||
apiHost: 'https://example.openai.azure.com/openai/v1/',
|
||||
expectedEndpoint: 'https://example.openai.azure.com'
|
||||
},
|
||||
{
|
||||
apiHost: 'https://example.openai.azure.com',
|
||||
expectedEndpoint: 'https://example.openai.azure.com'
|
||||
},
|
||||
{
|
||||
apiHost: 'https://example.openai.azure.com/',
|
||||
expectedEndpoint: 'https://example.openai.azure.com'
|
||||
},
|
||||
{
|
||||
apiHost: 'https://example.openai.azure.com/OPENAI/V1',
|
||||
expectedEndpoint: 'https://example.openai.azure.com'
|
||||
}
|
||||
])('strips trailing /openai from $apiHost', ({ apiHost, expectedEndpoint }) => {
|
||||
expect(normalizeAzureOpenAIEndpoint(apiHost)).toBe(expectedEndpoint)
|
||||
})
|
||||
})
|
||||
@ -29,6 +29,7 @@ import { withoutTrailingSlash } from '@renderer/utils/api'
|
||||
import { isOllamaProvider } from '@renderer/utils/provider'
|
||||
|
||||
import { BaseApiClient } from '../BaseApiClient'
|
||||
import { normalizeAzureOpenAIEndpoint } from './azureOpenAIEndpoint'
|
||||
|
||||
const logger = loggerService.withContext('OpenAIBaseClient')
|
||||
|
||||
@ -213,7 +214,7 @@ export abstract class OpenAIBaseClient<
|
||||
dangerouslyAllowBrowser: true,
|
||||
apiKey: apiKeyForSdkInstance,
|
||||
apiVersion: this.provider.apiVersion,
|
||||
endpoint: this.provider.apiHost
|
||||
endpoint: normalizeAzureOpenAIEndpoint(this.provider.apiHost)
|
||||
}) as TSdkInstance
|
||||
} else {
|
||||
this.sdkInstance = new OpenAI({
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
export function normalizeAzureOpenAIEndpoint(apiHost: string): string {
|
||||
const normalizedHost = apiHost.replace(/\/+$/, '')
|
||||
return normalizedHost.replace(/\/openai(?:\/v1)?$/i, '')
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user