diff --git a/src/renderer/src/aiCore/clients/openai/OpenAIApiClient.ts b/src/renderer/src/aiCore/clients/openai/OpenAIApiClient.ts index 7fcae3823c..e9133400dc 100644 --- a/src/renderer/src/aiCore/clients/openai/OpenAIApiClient.ts +++ b/src/renderer/src/aiCore/clients/openai/OpenAIApiClient.ts @@ -26,7 +26,8 @@ import { isSupportedThinkingTokenQwenModel, isSupportedThinkingTokenZhipuModel, isVisionModel, - MODEL_SUPPORTED_REASONING_EFFORT + MODEL_SUPPORTED_REASONING_EFFORT, + ZHIPU_RESULT_TOKENS } from '@renderer/config/models' import { isSupportArrayContentProvider, @@ -896,10 +897,22 @@ export class OpenAIAPIClient extends OpenAIBaseClient< accumulatingText = true } // logger.silly('enqueue TEXT_DELTA') - controller.enqueue({ - type: ChunkType.TEXT_DELTA, - text: contentSource.content - }) + // 处理特殊token + // 智谱api的一个chunk中只会输出一个token,因而使用 ===,避免正常内容被误判 + if ( + context.provider.id === SystemProviderIds.zhipu && + ZHIPU_RESULT_TOKENS.some((pattern) => contentSource.content === pattern) + ) { + controller.enqueue({ + type: ChunkType.TEXT_DELTA, + text: '**' // strong + }) + } else { + controller.enqueue({ + type: ChunkType.TEXT_DELTA, + text: contentSource.content + }) + } } else { accumulatingText = false } diff --git a/src/renderer/src/config/models.ts b/src/renderer/src/config/models.ts index d424cf1402..a4fdcf0fb9 100644 --- a/src/renderer/src/config/models.ts +++ b/src/renderer/src/config/models.ts @@ -3238,3 +3238,6 @@ export const isGPT5SeriesModel = (model: Model) => { const modelId = getLowerBaseModelName(model.id) return modelId.includes('gpt-5') } + +// zhipu 视觉推理模型用这组 special token 标记推理结果 +export const ZHIPU_RESULT_TOKENS = ['<|begin_of_box|>', '<|end_of_box|>'] as const