mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-01 17:59:09 +08:00
fix: enhance OpenAIResponseAPIClient for Azure API version (#8108)
* feat: enhance OpenAIResponseAPIClient and update localization for Azure API version - Added a new method `formatApiHost` in OpenAIResponseAPIClient to ensure correct API host formatting. - Updated localization files for English, Japanese, Russian, and Chinese to include tips for Azure OpenAI API version usage. - Modified ProviderSetting component to display the new Azure API version tip in the settings interface. * chore: clean log
This commit is contained in:
parent
706f8e1482
commit
3d3182095d
@ -61,13 +61,31 @@ export class OpenAIResponseAPIClient extends OpenAIBaseClient<
|
||||
this.client = new OpenAIAPIClient(provider)
|
||||
}
|
||||
|
||||
private formatApiHost() {
|
||||
const host = this.provider.apiHost
|
||||
if (host.endsWith('/openai/v1')) {
|
||||
return host
|
||||
} else {
|
||||
if (host.endsWith('/')) {
|
||||
return host + 'openai/v1'
|
||||
} else {
|
||||
return host + '/openai/v1'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模型特征选择合适的客户端
|
||||
*/
|
||||
public getClient(model: Model) {
|
||||
if (isOpenAILLMModel(model) && !isOpenAIChatCompletionOnlyModel(model)) {
|
||||
if (this.provider.id === 'azure-openai' || this.provider.type === 'azure-openai') {
|
||||
this.provider = { ...this.provider, apiVersion: 'preview' }
|
||||
this.provider = { ...this.provider, apiHost: this.formatApiHost() }
|
||||
if (this.provider.apiVersion === 'preview') {
|
||||
return this
|
||||
} else {
|
||||
return this.client
|
||||
}
|
||||
}
|
||||
return this
|
||||
} else {
|
||||
@ -81,7 +99,6 @@ export class OpenAIResponseAPIClient extends OpenAIBaseClient<
|
||||
}
|
||||
|
||||
if (this.provider.id === 'azure-openai' || this.provider.type === 'azure-openai') {
|
||||
this.provider = { ...this.provider, apiHost: `${this.provider.apiHost}/openai/v1` }
|
||||
return new AzureOpenAI({
|
||||
dangerouslyAllowBrowser: true,
|
||||
apiKey: this.apiKey,
|
||||
|
||||
@ -2115,6 +2115,7 @@
|
||||
"api_key": "API Key",
|
||||
"api_key.tip": "Multiple keys separated by commas or spaces",
|
||||
"api_version": "API Version",
|
||||
"azure.apiversion.tip": "The API version of Azure OpenAI, if you want to use Response API, please enter the preview version",
|
||||
"basic_auth": "HTTP authentication",
|
||||
"basic_auth.password": "Password",
|
||||
"basic_auth.password.tip": "",
|
||||
|
||||
@ -2211,7 +2211,8 @@
|
||||
"private_key_placeholder": "サービスアカウントの秘密鍵を入力してください",
|
||||
"title": "サービスアカウント設定"
|
||||
}
|
||||
}
|
||||
},
|
||||
"azure.apiversion.tip": "Azure OpenAIのAPIバージョン。Response APIを使用する場合は、previewバージョンを入力してください"
|
||||
},
|
||||
"proxy": {
|
||||
"mode": {
|
||||
|
||||
@ -2211,7 +2211,8 @@
|
||||
"private_key_placeholder": "Введите приватный ключ Service Account",
|
||||
"title": "Конфигурация Service Account"
|
||||
}
|
||||
}
|
||||
},
|
||||
"azure.apiversion.tip": "Версия API Azure OpenAI. Если вы хотите использовать Response API, введите версию preview"
|
||||
},
|
||||
"proxy": {
|
||||
"mode": {
|
||||
|
||||
@ -2115,6 +2115,7 @@
|
||||
"api_key": "API 密钥",
|
||||
"api_key.tip": "多个密钥使用逗号或空格分隔",
|
||||
"api_version": "API 版本",
|
||||
"azure.apiversion.tip": "Azure OpenAI 的 API 版本,如果想要使用 Response API,请输入 preview 版本",
|
||||
"basic_auth": "HTTP 认证",
|
||||
"basic_auth.password": "密码",
|
||||
"basic_auth.password.tip": "",
|
||||
|
||||
@ -2211,7 +2211,8 @@
|
||||
"private_key_placeholder": "輸入服務帳戶私密金鑰",
|
||||
"title": "服務帳戶設定"
|
||||
}
|
||||
}
|
||||
},
|
||||
"azure.apiversion.tip": "Azure OpenAI 的 API 版本,如果想要使用 Response API,請輸入 preview 版本"
|
||||
},
|
||||
"proxy": {
|
||||
"mode": {
|
||||
|
||||
@ -286,6 +286,10 @@ const ProviderSetting: FC<Props> = ({ providerId }) => {
|
||||
if (provider.type === 'openai') {
|
||||
return formatApiHost(apiHost) + 'chat/completions'
|
||||
}
|
||||
|
||||
if (provider.type === 'azure-openai') {
|
||||
return formatApiHost(apiHost) + 'openai/v1'
|
||||
}
|
||||
return formatApiHost(apiHost) + 'responses'
|
||||
}
|
||||
|
||||
@ -446,6 +450,11 @@ const ProviderSetting: FC<Props> = ({ providerId }) => {
|
||||
onBlur={onUpdateApiVersion}
|
||||
/>
|
||||
</Space.Compact>
|
||||
<SettingHelpTextRow style={{ justifyContent: 'space-between' }}>
|
||||
<SettingHelpText style={{ minWidth: 'fit-content' }}>
|
||||
{t('settings.provider.azure.apiversion.tip')}
|
||||
</SettingHelpText>
|
||||
</SettingHelpTextRow>
|
||||
</>
|
||||
)}
|
||||
{provider.id === 'lmstudio' && <LMStudioSettings />}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user