mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-28 13:31:32 +08:00
fix: update reasoningTimePlugin and smoothReasoningPlugin for improved performance tracking
- Changed the invocation of `reasoningTimePlugin` to a direct reference in `ModernAiProvider`. - Initialized `thinkingStartTime` with `performance.now()` in `reasoningTimePlugin` for accurate timing. - Removed `thinking_millsec` from the enqueued chunks in `smoothReasoningPlugin` to streamline data handling. - Added console logging for performance tracking in `reasoningTimePlugin` to aid in debugging.
This commit is contained in:
parent
dc106a8af7
commit
ef616e1c3b
@ -133,7 +133,7 @@ export default class ModernAiProvider {
|
||||
delayInMs: 80,
|
||||
chunkingRegex: /([\u4E00-\u9FFF]{3})|\S+\s+/
|
||||
}),
|
||||
reasoningTimePlugin()
|
||||
reasoningTimePlugin
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { definePlugin } from '@cherrystudio/ai-core'
|
||||
|
||||
export default definePlugin(() => ({
|
||||
export default definePlugin({
|
||||
name: 'reasoningTimePlugin',
|
||||
transformStream: () => () => {
|
||||
let thinkingStartTime = 0
|
||||
let thinkingStartTime = performance.now()
|
||||
let hasStartedThinking = false
|
||||
let accumulatedThinkingContent = ''
|
||||
return new TransformStream({
|
||||
@ -11,9 +11,10 @@ export default definePlugin(() => ({
|
||||
if (chunk.type === 'reasoning') {
|
||||
if (!hasStartedThinking) {
|
||||
hasStartedThinking = true
|
||||
thinkingStartTime = performance.now()
|
||||
// thinkingStartTime = performance.now()
|
||||
}
|
||||
accumulatedThinkingContent += chunk.textDelta
|
||||
console.log('performance.now() - thinkingStartTime', performance.now() - thinkingStartTime)
|
||||
controller.enqueue({
|
||||
...chunk,
|
||||
thinking_millsec: performance.now() - thinkingStartTime
|
||||
@ -34,4 +35,4 @@ export default definePlugin(() => ({
|
||||
}
|
||||
})
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
@ -19,7 +19,7 @@ export default definePlugin(({ delayInMs, chunkingRegex }: { delayInMs: number;
|
||||
async transform(chunk, controller) {
|
||||
if (chunk.type !== 'reasoning') {
|
||||
if (buffer.length > 0) {
|
||||
controller.enqueue({ type: 'reasoning', textDelta: buffer, thinking_millsec: chunk.thinking_millsec })
|
||||
controller.enqueue({ type: 'reasoning', textDelta: buffer })
|
||||
buffer = ''
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ export default definePlugin(({ delayInMs, chunkingRegex }: { delayInMs: number;
|
||||
let match
|
||||
|
||||
while ((match = detectChunk(buffer)) != null) {
|
||||
controller.enqueue({ type: 'reasoning', textDelta: match, thinking_millsec: chunk.thinking_millsec })
|
||||
controller.enqueue({ type: 'reasoning', textDelta: match })
|
||||
buffer = buffer.slice(match.length)
|
||||
|
||||
await delay(delayInMs)
|
||||
|
||||
@ -306,12 +306,13 @@ export async function fetchChatCompletion({
|
||||
enableTools: isEnabledToolUse(assistant),
|
||||
requestOptions: options
|
||||
})
|
||||
|
||||
console.log('assistant.settings?.reasoning_effort', assistant.settings?.reasoning_effort)
|
||||
const middlewareConfig: AiSdkMiddlewareConfig = {
|
||||
streamOutput: assistant.settings?.streamOutput ?? true,
|
||||
onChunk: onChunkReceived,
|
||||
model: assistant.model,
|
||||
provider: provider,
|
||||
// FIXME: 这里需要根据模型来判断是否启用推理
|
||||
enableReasoning: assistant.settings?.reasoning_effort !== undefined,
|
||||
enableTool: assistant.settings?.toolUseMode === 'prompt',
|
||||
mcpTools
|
||||
|
||||
Loading…
Reference in New Issue
Block a user