feat: Translation does not show the thinking content

This commit is contained in:
ousugo 2025-03-04 17:57:26 +08:00 committed by 亢奋猫
parent 46c7d35bb8
commit 32749d65a4

View File

@ -520,12 +520,35 @@ export default class OpenAIProvider extends BaseProvider {
}
let text = ''
let isThinking = false
const isReasoning = isReasoningModel(model)
for await (const chunk of response) {
text += chunk.choices[0]?.delta?.content || ''
const deltaContent = chunk.choices[0]?.delta?.content || ''
if (!deltaContent.trim()) {
continue
}
if (isReasoning) {
if (deltaContent.includes('<think>')) {
isThinking = true
}
if (!isThinking) {
text += deltaContent
onResponse?.(text)
}
if (deltaContent.includes('</think>')) {
isThinking = false
}
} else {
text += deltaContent
onResponse?.(text)
}
}
return text
}