mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 21:01:32 +08:00
fix: enhance anthropic provider configuration and middleware handling
- Updated providerToAiSdkConfig to support both OpenAI and Anthropic providers, improving flexibility in API host formatting. - Refactored thinkingTimeMiddleware to ensure all chunks are correctly enqueued, enhancing middleware functionality. - Corrected parameter naming in getAnthropicReasoningParams for consistency and clarity in configuration.
This commit is contained in:
parent
09080f0755
commit
ebe85ba24a
@ -45,7 +45,7 @@ function providerToAiSdkConfig(provider: Provider): {
|
||||
actualProvider = createVertexProvider(provider)
|
||||
}
|
||||
|
||||
if (actualProvider.type === 'openai') {
|
||||
if (actualProvider.type === 'openai' || actualProvider.type === 'anthropic') {
|
||||
actualProvider.apiHost = formatApiHost(actualProvider.apiHost)
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,8 @@ export default function thinkingTimeMiddleware(): LanguageModelV1Middleware {
|
||||
thinkingStartTime = Date.now()
|
||||
}
|
||||
accumulatedThinkingContent += chunk.textDelta || ''
|
||||
// 将所有 chunk 原样传递下去
|
||||
controller.enqueue(chunk)
|
||||
} else {
|
||||
if (hasThinkingContent && thinkingStartTime > 0) {
|
||||
const thinkingTime = Date.now() - thinkingStartTime
|
||||
@ -37,10 +39,10 @@ export default function thinkingTimeMiddleware(): LanguageModelV1Middleware {
|
||||
hasThinkingContent = false
|
||||
thinkingStartTime = 0
|
||||
accumulatedThinkingContent = ''
|
||||
} else {
|
||||
controller.enqueue(chunk)
|
||||
}
|
||||
}
|
||||
// 将所有 chunk 原样传递下去
|
||||
controller.enqueue(chunk)
|
||||
},
|
||||
flush(controller) {
|
||||
// 如果流的末尾都是 reasoning,也需要发送 complete 事件
|
||||
|
||||
@ -382,7 +382,7 @@ function getAnthropicReasoningParams(assistant: Assistant, model: Model): Record
|
||||
return {
|
||||
thinking: {
|
||||
type: 'enabled',
|
||||
budget_tokens: budgetTokens
|
||||
budgetTokens: budgetTokens
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user