-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix streaming for function & tool chat completions #43
Conversation
This fixes the logic for merging chat completion chunks when streaming is used with responses that contain function or tool calls.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -136,6 +136,10 @@ export class ChatModel< | |||
|
|||
const delta = value.choices[0].delta; | |||
|
|||
if (Object.keys(chunk).length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious whats this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's when the first chunk is received. chunk is initialized to {}
above.
chunk.choices[0].delta.function_call, | ||
function_call | ||
); | ||
const existingFunctionCall = chunk.choices[0].delta.function_call; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so i understand, this is the code for streaming function calls right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for when stream=true
on the request, and the assistant message is returns is a function or tool call, instead of just content. these are harder to do the merge+patch because the value that is being patched is more nested than just delta.content
for the basic assistant string response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good.
This fixes the logic for merging chat completion chunks when streaming
is used with responses that contain function or tool calls.