mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-22 17:00:14 +08:00
feat(openai): handle special tokens for zhipu api (#9323)
* feat(openai): 添加对智谱特殊token的过滤处理 在OpenAIAPIClient中添加对智谱AI特殊token的过滤逻辑,避免不需要的token被输出 * docs(OpenAIApiClient): 添加注释 * refactor(zhipu): 重命名并更新智谱特殊token处理逻辑 将 ZHIPU_SPECIAL_TOKENS_TO_FILTER 重命名为 ZHIPU_RESULT_TOKENS 以更准确描述用途 修改智谱API特殊token处理逻辑,不再过滤而是用**标记结果token
This commit is contained in:
parent
f8120c2ebb
commit
1da1721ec2
@ -26,7 +26,8 @@ import {
|
|||||||
isSupportedThinkingTokenQwenModel,
|
isSupportedThinkingTokenQwenModel,
|
||||||
isSupportedThinkingTokenZhipuModel,
|
isSupportedThinkingTokenZhipuModel,
|
||||||
isVisionModel,
|
isVisionModel,
|
||||||
MODEL_SUPPORTED_REASONING_EFFORT
|
MODEL_SUPPORTED_REASONING_EFFORT,
|
||||||
|
ZHIPU_RESULT_TOKENS
|
||||||
} from '@renderer/config/models'
|
} from '@renderer/config/models'
|
||||||
import {
|
import {
|
||||||
isSupportArrayContentProvider,
|
isSupportArrayContentProvider,
|
||||||
@ -896,10 +897,22 @@ export class OpenAIAPIClient extends OpenAIBaseClient<
|
|||||||
accumulatingText = true
|
accumulatingText = true
|
||||||
}
|
}
|
||||||
// logger.silly('enqueue TEXT_DELTA')
|
// logger.silly('enqueue TEXT_DELTA')
|
||||||
|
// 处理特殊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({
|
controller.enqueue({
|
||||||
type: ChunkType.TEXT_DELTA,
|
type: ChunkType.TEXT_DELTA,
|
||||||
text: contentSource.content
|
text: contentSource.content
|
||||||
})
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
accumulatingText = false
|
accumulatingText = false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3238,3 +3238,6 @@ export const isGPT5SeriesModel = (model: Model) => {
|
|||||||
const modelId = getLowerBaseModelName(model.id)
|
const modelId = getLowerBaseModelName(model.id)
|
||||||
return modelId.includes('gpt-5')
|
return modelId.includes('gpt-5')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// zhipu 视觉推理模型用这组 special token 标记推理结果
|
||||||
|
export const ZHIPU_RESULT_TOKENS = ['<|begin_of_box|>', '<|end_of_box|>'] as const
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user