Skip to content
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

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

rileytomasek
Copy link
Contributor

This fixes the logic for merging chat completion chunks when streaming
is used with responses that contain function or tool calls.

This fixes the logic for merging chat completion chunks when streaming
is used with responses that contain function or tool calls.
Copy link

vercel bot commented Jul 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dexter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2024 2:32pm

@@ -136,6 +136,10 @@ export class ChatModel<

const delta = value.choices[0].delta;

if (Object.keys(chunk).length === 0) {
Copy link
Contributor

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?

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@cfortuner cfortuner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good.

@rileytomasek rileytomasek merged commit 0300984 into master Jul 17, 2024
6 checks passed
@rileytomasek rileytomasek deleted the fix-functions-tools-streaming branch October 13, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants