fix: conditionally enable reasoning middleware for OpenAI and Azure providers

- Added a check to enable the 'thinking-tag-extraction' middleware only if reasoning is enabled in the configuration for OpenAI and Azure providers.
- Commented out the provider type check in `getAiSdkProviderId` to prevent issues with retrieving provider options.
This commit is contained in:
suyao 2025-07-21 14:20:33 +08:00
parent 786bc8dca9
commit 61e3309cd2
No known key found for this signature in database
2 changed files with 11 additions and 8 deletions

View File

@ -146,11 +146,13 @@ function addProviderSpecificMiddlewares(builder: AiSdkMiddlewareBuilder, config:
break break
case 'openai': case 'openai':
case 'azure-openai': { case 'azure-openai': {
const tagName = config.model?.id.includes('gemini') ? tagNameArray[1] : tagNameArray[0] if (config.enableReasoning) {
builder.add({ const tagName = config.model?.id.includes('gemini') ? tagNameArray[1] : tagNameArray[0]
name: 'thinking-tag-extraction', builder.add({
middleware: extractReasoningMiddleware({ tagName }) name: 'thinking-tag-extraction',
}) middleware: extractReasoningMiddleware({ tagName })
})
}
break break
} }
case 'gemini': case 'gemini':

View File

@ -26,9 +26,10 @@ export function getAiSdkProviderId(provider: Provider): ProviderId | 'openai-com
if (AiCore.isSupported(provider.id)) { if (AiCore.isSupported(provider.id)) {
return provider.id as ProviderId return provider.id as ProviderId
} }
if (AiCore.isSupported(provider.type)) { // 先注释掉会影响获取providerOptions
return provider.type as ProviderId // if (AiCore.isSupported(provider.type)) {
} // return provider.type as ProviderId
// }
return provider.id as ProviderId return provider.id as ProviderId
} }