fix: openai-gemini support

This commit is contained in:
suyao 2025-07-07 18:42:31 +08:00
parent c72156b2da
commit fce8f2411c
No known key found for this signature in database
4 changed files with 16 additions and 10 deletions

View File

@ -1,4 +1,8 @@
import { LanguageModelV2Middleware, simulateStreamingMiddleware } from '@cherrystudio/ai-core' import {
extractReasoningMiddleware,
LanguageModelV2Middleware,
simulateStreamingMiddleware
} from '@cherrystudio/ai-core'
import type { MCPTool, Model, Provider } from '@renderer/types' import type { MCPTool, Model, Provider } from '@renderer/types'
import type { Chunk } from '@renderer/types/chunk' import type { Chunk } from '@renderer/types/chunk'
@ -127,6 +131,8 @@ export function buildAiSdkMiddlewares(config: AiSdkMiddlewareConfig): LanguageMo
return builder.build() return builder.build()
} }
const tagNameArray = ['think', 'thought']
/** /**
* provider特定的中间件 * provider特定的中间件
*/ */
@ -139,10 +145,11 @@ function addProviderSpecificMiddlewares(builder: AiSdkMiddlewareBuilder, config:
// Anthropic特定中间件 // Anthropic特定中间件
break break
case 'openai': case 'openai':
// builder.add({ const tagName = config.model?.id.includes('gemini') ? tagNameArray[1] : tagNameArray[0]
// name: 'thinking-tag-extraction', builder.add({
// middleware: extractReasoningMiddleware({ tagName: 'think' }) name: 'thinking-tag-extraction',
// }) middleware: extractReasoningMiddleware({ tagName })
})
break break
case 'gemini': case 'gemini':
// Gemini特定中间件 // Gemini特定中间件

View File

@ -47,7 +47,9 @@ export default definePlugin({
hasStartedThinking = false hasStartedThinking = false
thinkingStartTime = 0 thinkingStartTime = 0
reasoningBlockId = '' reasoningBlockId = ''
controller.enqueue(chunk) if (chunk.type !== 'reasoning-end') {
controller.enqueue(chunk)
}
} else { } else {
if (chunk.type !== 'reasoning-end') { if (chunk.type !== 'reasoning-end') {
controller.enqueue(chunk) controller.enqueue(chunk)

View File

@ -27,5 +27,5 @@ export function getAiSdkProviderId(provider: Provider): ProviderId | 'openai-com
return provider.id as ProviderId return provider.id as ProviderId
} }
return 'openai-compatible' return provider.id as ProviderId
} }

View File

@ -8,12 +8,9 @@ import {
FilePart, FilePart,
ImagePart, ImagePart,
ModelMessage, ModelMessage,
ReasoningPart,
stepCountIs, stepCountIs,
type StreamTextParams, type StreamTextParams,
TextPart, TextPart,
ToolCallPart,
ToolResultPart,
UserModelMessage UserModelMessage
} from '@cherrystudio/ai-core' } from '@cherrystudio/ai-core'
import { DEFAULT_MAX_TOKENS } from '@renderer/config/constant' import { DEFAULT_MAX_TOKENS } from '@renderer/config/constant'