mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-28 13:31:32 +08:00
feat: enhance OpenAI model handling with utility function
- Introduced `isOpenAIChatCompletionOnlyModel` utility function to determine if a model ID corresponds to OpenAI's chat completion-only models. - Updated `createBaseModel` function to utilize the new utility for improved handling of OpenAI provider responses in strict mode. - Refactored reasoning parameters in `getOpenAIReasoningParams` for consistency and clarity.
This commit is contained in:
parent
ff3b1fc38f
commit
ac15930692
@ -6,6 +6,7 @@ import type { ImageModelV1 } from '@ai-sdk/provider'
|
||||
import { type LanguageModelV1, LanguageModelV1Middleware, wrapLanguageModel } from 'ai'
|
||||
|
||||
import { type ProviderId, type ProviderSettingsMap } from '../../types'
|
||||
import { isOpenAIChatCompletionOnlyModel } from '../../utils/model'
|
||||
import { aiProviderRegistry, type ProviderConfig } from '../providers/registry'
|
||||
|
||||
// 错误类型
|
||||
@ -69,7 +70,7 @@ export async function createBaseModel(
|
||||
let provider = creatorFunction(options)
|
||||
|
||||
// 加一个特判
|
||||
if (providerConfig.id === 'openai' && options.compatibility === 'strict') {
|
||||
if (providerConfig.id === 'openai' && !isOpenAIChatCompletionOnlyModel(modelId)) {
|
||||
provider = provider.responses
|
||||
}
|
||||
// 返回模型实例
|
||||
|
||||
12
packages/aiCore/src/utils/model.ts
Normal file
12
packages/aiCore/src/utils/model.ts
Normal file
@ -0,0 +1,12 @@
|
||||
export function isOpenAIChatCompletionOnlyModel(modelId: string): boolean {
|
||||
if (!modelId) {
|
||||
return false
|
||||
}
|
||||
|
||||
return (
|
||||
modelId.includes('gpt-4o-search-preview') ||
|
||||
modelId.includes('gpt-4o-mini-search-preview') ||
|
||||
modelId.includes('o1-mini') ||
|
||||
modelId.includes('o1-preview')
|
||||
)
|
||||
}
|
||||
@ -180,7 +180,7 @@ export function getOpenAIReasoningParams(assistant: Assistant, model: Model): Re
|
||||
// OpenAI 推理参数
|
||||
if (isSupportedReasoningEffortOpenAIModel(model)) {
|
||||
return {
|
||||
reasoning_effort: reasoningEffort
|
||||
reasoningEffort
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user