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 OpenAI functions + streaming #62

Merged
merged 1 commit into from
Jan 8, 2024

Conversation

RyanKadri
Copy link
Contributor

When using OpenAI functions with streaming, it looks like some of our assumptions about the chunk data break.

@RyanKadri RyanKadri requested a review from bonczj January 5, 2024 22:52
content += chunk.choices[0].delta.get("content", "")
if hasattr(chunk.choices[0].delta, "role"):
role = chunk.choices[0].delta.role
if len(chunk.choices) > 0:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why this happens but some chunks were returning with no choices. I saw that same behavior in Node I think. It might be an implementation detail or it might signal that the stream is starting?

role = chunk.choices[0].delta.role
if len(chunk.choices) > 0:
content += chunk.choices[0].delta.get("content", "") or ""
delta_role = getattr(chunk.choices[0].delta, "role", None)
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 seems like the content or role can both be None even after a previous chunk had a role. Only track the role when there's a value here

@RyanKadri RyanKadri merged commit ffbaf97 into staging Jan 8, 2024
4 checks passed
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