Skip to content

Commit

Permalink
fix(accumulateDelta): AssistantStream accumulateDelta toolCall (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
A4F54B authored and RobertCraigie committed Sep 3, 2024
1 parent 3ba96a7 commit 639448c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/lib/AssistantStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,20 @@ export class AssistantStream
if (accValue.every((x) => typeof x === 'string' || typeof x === 'number')) {
accValue.push(...deltaValue); // Use spread syntax for efficient addition
continue;
} else if (accValue.every((x) => Core.isObj(x))) {
deltaValue.forEach(item => {
if (item.hasOwnProperty('index')) {
const obj = accValue.find((x: any) => x['index'] === item['index']);
if (obj) {
accValue[accValue.indexOf(obj)] = this.accumulateDelta(obj, item);
} else {
accValue.push(item);
}
} else {
accValue.push(item);
}
});
continue;
}
} else {
throw Error(`Unhandled record type: ${key}, deltaValue: ${deltaValue}, accValue: ${accValue}`);
Expand Down

0 comments on commit 639448c

Please sign in to comment.