mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-28 05:11:24 +08:00
feat(aiCore): 添加对文本增量累积的可配置支持
根据模型是否支持文本增量来决定是否累积文本内容,新增accumulate参数控制行为
This commit is contained in:
parent
e653a52265
commit
7a5050d2a2
@ -28,11 +28,14 @@ export interface CherryStudioChunk {
|
||||
*/
|
||||
export class AiSdkToChunkAdapter {
|
||||
toolCallHandler: ToolCallChunkHandler
|
||||
private accumulate: boolean | undefined
|
||||
constructor(
|
||||
private onChunk: (chunk: Chunk) => void,
|
||||
mcpTools: MCPTool[] = []
|
||||
mcpTools: MCPTool[] = [],
|
||||
accumulate?: boolean
|
||||
) {
|
||||
this.toolCallHandler = new ToolCallChunkHandler(onChunk, mcpTools)
|
||||
this.accumulate = accumulate
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +98,11 @@ export class AiSdkToChunkAdapter {
|
||||
})
|
||||
break
|
||||
case 'text-delta':
|
||||
final.text += chunk.text || ''
|
||||
if (this.accumulate) {
|
||||
final.text += chunk.text || ''
|
||||
} else {
|
||||
final.text = chunk.text || ''
|
||||
}
|
||||
this.onChunk({
|
||||
type: ChunkType.TEXT_DELTA,
|
||||
text: final.text || ''
|
||||
|
||||
@ -43,10 +43,12 @@ export default class ModernAiProvider {
|
||||
private legacyProvider: LegacyAiProvider
|
||||
private config: ReturnType<typeof providerToAiSdkConfig>
|
||||
private actualProvider: Provider
|
||||
private model: Model
|
||||
|
||||
constructor(model: Model, provider?: Provider) {
|
||||
this.actualProvider = provider || getActualProvider(model)
|
||||
this.legacyProvider = new LegacyAiProvider(this.actualProvider)
|
||||
this.model = model
|
||||
|
||||
// 只保存配置,不预先创建executor
|
||||
this.config = providerToAiSdkConfig(this.actualProvider, model)
|
||||
@ -237,7 +239,8 @@ export default class ModernAiProvider {
|
||||
topicId: config.topicId
|
||||
})
|
||||
|
||||
const adapter = new AiSdkToChunkAdapter(config.onChunk, config.mcpTools)
|
||||
const accumulate = this.model.supported_text_delta !== false // true and undefined
|
||||
const adapter = new AiSdkToChunkAdapter(config.onChunk, config.mcpTools, accumulate)
|
||||
|
||||
logger.debug('Final params before streamText', {
|
||||
modelId,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user