Skip to content

Commit

Permalink
slight refactor of handling the final token counts chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobzim-stl committed Sep 13, 2024
1 parent 51f42e3 commit 61e9377
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions examples/tool-calls-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ function messageReducer(previous: ChatCompletionMessage, item: ChatCompletionChu
return acc;
};

if (item.choices.length == 0) {
const choice = item.choices[0];
if (!choice) {
// chunk contains information about usage and token counts
return previous;
}
return reduce(previous, item.choices[0]!.delta) as ChatCompletionMessage;
return reduce(previous, choice.delta) as ChatCompletionMessage;
}

function lineRewriter() {
Expand Down

0 comments on commit 61e9377

Please sign in to comment.