mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 23:10:20 +08:00
refactor(aiCore): streamline provider options and enhance OpenAI handling
- Simplified the OpenAI mode handling in the provider configuration. - Added service tier settings to provider-specific options for better configuration management. - Refactored the `buildOpenAIProviderOptions` function to remove redundant parameters and improve clarity.
This commit is contained in:
parent
efeada281a
commit
2ca5116769
@ -85,7 +85,7 @@ export function providerToAiSdkConfig(
|
|||||||
baseURL: actualProvider.apiHost,
|
baseURL: actualProvider.apiHost,
|
||||||
apiKey: actualProvider.apiKey
|
apiKey: actualProvider.apiKey
|
||||||
}
|
}
|
||||||
// 处理OpenAI模式(简化逻辑)
|
// 处理OpenAI模式
|
||||||
const extraOptions: any = {}
|
const extraOptions: any = {}
|
||||||
if (actualProvider.type === 'openai-response' && !isOpenAIChatCompletionOnlyModel(model)) {
|
if (actualProvider.type === 'openai-response' && !isOpenAIChatCompletionOnlyModel(model)) {
|
||||||
extraOptions.mode = 'responses'
|
extraOptions.mode = 'responses'
|
||||||
|
|||||||
@ -70,13 +70,15 @@ export function buildProviderOptions(
|
|||||||
const providerId = getAiSdkProviderId(actualProvider)
|
const providerId = getAiSdkProviderId(actualProvider)
|
||||||
// 构建 provider 特定的选项
|
// 构建 provider 特定的选项
|
||||||
let providerSpecificOptions: Record<string, any> = {}
|
let providerSpecificOptions: Record<string, any> = {}
|
||||||
|
const serviceTierSetting = getServiceTier(model, actualProvider)
|
||||||
|
providerSpecificOptions.serviceTier = serviceTierSetting
|
||||||
// 根据 provider 类型分离构建逻辑
|
// 根据 provider 类型分离构建逻辑
|
||||||
switch (providerId) {
|
switch (providerId) {
|
||||||
case 'openai':
|
case 'openai':
|
||||||
case 'azure':
|
case 'azure':
|
||||||
providerSpecificOptions = {
|
providerSpecificOptions = {
|
||||||
...buildOpenAIProviderOptions(assistant, model, capabilities, actualProvider)
|
...buildOpenAIProviderOptions(assistant, model, capabilities),
|
||||||
|
serviceTier: serviceTierSetting
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -95,7 +97,10 @@ export function buildProviderOptions(
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
// 对于其他 provider,使用通用的构建逻辑
|
// 对于其他 provider,使用通用的构建逻辑
|
||||||
providerSpecificOptions = buildGenericProviderOptions(assistant, model, capabilities)
|
providerSpecificOptions = {
|
||||||
|
...buildGenericProviderOptions(assistant, model, capabilities),
|
||||||
|
serviceTier: serviceTierSetting
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,19 +126,16 @@ function buildOpenAIProviderOptions(
|
|||||||
enableReasoning: boolean
|
enableReasoning: boolean
|
||||||
enableWebSearch: boolean
|
enableWebSearch: boolean
|
||||||
enableGenerateImage: boolean
|
enableGenerateImage: boolean
|
||||||
},
|
}
|
||||||
actualProvider: Provider
|
|
||||||
): Record<string, any> {
|
): Record<string, any> {
|
||||||
const { enableReasoning } = capabilities
|
const { enableReasoning } = capabilities
|
||||||
let providerOptions: Record<string, any> = {}
|
let providerOptions: Record<string, any> = {}
|
||||||
const serviceTierSetting = getServiceTier(model, actualProvider)
|
|
||||||
// OpenAI 推理参数
|
// OpenAI 推理参数
|
||||||
if (enableReasoning) {
|
if (enableReasoning) {
|
||||||
const reasoningParams = getOpenAIReasoningParams(assistant, model)
|
const reasoningParams = getOpenAIReasoningParams(assistant, model)
|
||||||
providerOptions = {
|
providerOptions = {
|
||||||
...providerOptions,
|
...providerOptions,
|
||||||
...reasoningParams,
|
...reasoningParams
|
||||||
serviceTier: serviceTierSetting
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user