mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 23:10:20 +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)
|
actualProvider = createVertexProvider(provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actualProvider.type === 'openai') {
|
if (actualProvider.type === 'openai' || actualProvider.type === 'anthropic') {
|
||||||
actualProvider.apiHost = formatApiHost(actualProvider.apiHost)
|
actualProvider.apiHost = formatApiHost(actualProvider.apiHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,8 @@ export default function thinkingTimeMiddleware(): LanguageModelV1Middleware {
|
|||||||
thinkingStartTime = Date.now()
|
thinkingStartTime = Date.now()
|
||||||
}
|
}
|
||||||
accumulatedThinkingContent += chunk.textDelta || ''
|
accumulatedThinkingContent += chunk.textDelta || ''
|
||||||
|
// 将所有 chunk 原样传递下去
|
||||||
|
controller.enqueue(chunk)
|
||||||
} else {
|
} else {
|
||||||
if (hasThinkingContent && thinkingStartTime > 0) {
|
if (hasThinkingContent && thinkingStartTime > 0) {
|
||||||
const thinkingTime = Date.now() - thinkingStartTime
|
const thinkingTime = Date.now() - thinkingStartTime
|
||||||
@ -37,10 +39,10 @@ export default function thinkingTimeMiddleware(): LanguageModelV1Middleware {
|
|||||||
hasThinkingContent = false
|
hasThinkingContent = false
|
||||||
thinkingStartTime = 0
|
thinkingStartTime = 0
|
||||||
accumulatedThinkingContent = ''
|
accumulatedThinkingContent = ''
|
||||||
|
} else {
|
||||||
|
controller.enqueue(chunk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 将所有 chunk 原样传递下去
|
|
||||||
controller.enqueue(chunk)
|
|
||||||
},
|
},
|
||||||
flush(controller) {
|
flush(controller) {
|
||||||
// 如果流的末尾都是 reasoning,也需要发送 complete 事件
|
// 如果流的末尾都是 reasoning,也需要发送 complete 事件
|
||||||
|
|||||||
@ -382,7 +382,7 @@ function getAnthropicReasoningParams(assistant: Assistant, model: Model): Record
|
|||||||
return {
|
return {
|
||||||
thinking: {
|
thinking: {
|
||||||
type: 'enabled',
|
type: 'enabled',
|
||||||
budget_tokens: budgetTokens
|
budgetTokens: budgetTokens
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user