mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 06:49:02 +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 { 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特定中间件
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user