Skip to content

Fix some typing issues #177

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

Merged
merged 1 commit into from
Jan 13, 2023
Merged

Fix some typing issues #177

merged 1 commit into from
Jan 13, 2023

Conversation

ddeville
Copy link
Contributor

There were a bunch of mypy issues when I applied this internally so fixing them here.

Also deal with async stream line parsing a bit more robustly (iterating over an aiohttp.StreamReader by chunks could still return multiple lines so let's keep using the regular one and deal with multiple lines separately).

Finally make sure that we correctly close the underlying session if an exception is raised while we're making the raw request.

@ddeville ddeville requested a review from athyuttamre January 12, 2023 19:21
async for chunk in rbody:
# While the `StreamReader` iterator is meant to iterate over lines by default, it seems like it sometimes
# returns multiple lines at a time, so let's split the chunk by lines again.
for line in chunk.splitlines():
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you prefer to change what the server sends here? iter_chunks returns exactly the chunks as received from the server

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When stress testing this I saw that iter_chunks would return multiple lines in a chunk maybe 1/3 of the time so I believe we still need to handle this edge case. We could go back to using iter_chunks rather than the regular async stream iterator though, you're right.

@ddeville ddeville merged commit 5d1a726 into main Jan 13, 2023
@ddeville ddeville deleted the damien/async-types branch January 13, 2023 01:06
cgayapr pushed a commit to cgayapr/openai-python that referenced this pull request Dec 14, 2024
stainless-app bot pushed a commit that referenced this pull request Mar 27, 2025
Update README.md to mention which website the key lives on
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.

3 participants