mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-28 05:11:24 +08:00
fix: openai-gemini support
This commit is contained in:
parent
c72156b2da
commit
fce8f2411c
@ -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 { Chunk } from '@renderer/types/chunk'
|
||||
|
||||
@ -127,6 +131,8 @@ export function buildAiSdkMiddlewares(config: AiSdkMiddlewareConfig): LanguageMo
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
const tagNameArray = ['think', 'thought']
|
||||
|
||||
/**
|
||||
* 添加provider特定的中间件
|
||||
*/
|
||||
@ -139,10 +145,11 @@ function addProviderSpecificMiddlewares(builder: AiSdkMiddlewareBuilder, config:
|
||||
// Anthropic特定中间件
|
||||
break
|
||||
case 'openai':
|
||||
// builder.add({
|
||||
// name: 'thinking-tag-extraction',
|
||||
// middleware: extractReasoningMiddleware({ tagName: 'think' })
|
||||
// })
|
||||
const tagName = config.model?.id.includes('gemini') ? tagNameArray[1] : tagNameArray[0]
|
||||
builder.add({
|
||||
name: 'thinking-tag-extraction',
|
||||
middleware: extractReasoningMiddleware({ tagName })
|
||||
})
|
||||
break
|
||||
case 'gemini':
|
||||
// Gemini特定中间件
|
||||
|
||||
@ -47,7 +47,9 @@ export default definePlugin({
|
||||
hasStartedThinking = false
|
||||
thinkingStartTime = 0
|
||||
reasoningBlockId = ''
|
||||
controller.enqueue(chunk)
|
||||
if (chunk.type !== 'reasoning-end') {
|
||||
controller.enqueue(chunk)
|
||||
}
|
||||
} else {
|
||||
if (chunk.type !== 'reasoning-end') {
|
||||
controller.enqueue(chunk)
|
||||
|
||||
@ -27,5 +27,5 @@ export function getAiSdkProviderId(provider: Provider): ProviderId | 'openai-com
|
||||
return provider.id as ProviderId
|
||||
}
|
||||
|
||||
return 'openai-compatible'
|
||||
return provider.id as ProviderId
|
||||
}
|
||||
|
||||
@ -8,12 +8,9 @@ import {
|
||||
FilePart,
|
||||
ImagePart,
|
||||
ModelMessage,
|
||||
ReasoningPart,
|
||||
stepCountIs,
|
||||
type StreamTextParams,
|
||||
TextPart,
|
||||
ToolCallPart,
|
||||
ToolResultPart,
|
||||
UserModelMessage
|
||||
} from '@cherrystudio/ai-core'
|
||||
import { DEFAULT_MAX_TOKENS } from '@renderer/config/constant'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user