Skip to content

Commit b5f1ff2

Browse files
A4F54BA4F54B
authored andcommitted
fix(accumulateDelta): AssistantStream accumulateDelta toolCall (#771)
1 parent 22cf036 commit b5f1ff2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/lib/AssistantStream.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,20 @@ export class AssistantStream
686686
if (accValue.every((x) => typeof x === 'string' || typeof x === 'number')) {
687687
accValue.push(...deltaValue); // Use spread syntax for efficient addition
688688
continue;
689+
} else if (accValue.every((x) => Core.isObj(x))) {
690+
deltaValue.forEach(item => {
691+
if (item.hasOwnProperty('index')) {
692+
const obj = accValue.find((x: any) => x['index'] === item['index']);
693+
if (obj) {
694+
accValue[accValue.indexOf(obj)] = this.accumulateDelta(obj, item);
695+
} else {
696+
accValue.push(item);
697+
}
698+
} else {
699+
accValue.push(item);
700+
}
701+
});
702+
continue;
689703
}
690704
} else {
691705
throw Error(`Unhandled record type: ${key}, deltaValue: ${deltaValue}, accValue: ${accValue}`);

0 commit comments

Comments
 (0)