-
-
Notifications
You must be signed in to change notification settings - Fork 725
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
Anthropic streaming support #682
Conversation
Streaming is now available with anthropic - https://docs.anthropic.com/en/api/messages-streaming
Sweep: PR Reviewinstructor/client.pyThe changes remove assertions that prevent the Sweep Found These Issues
https://github.com/jxnl/instructor/blob/a846c45aec1ea00768591ff44a5f82c006f9dd59/instructor%2Fclient.py#L128 https://github.com/jxnl/instructor/blob/a846c45aec1ea00768591ff44a5f82c006f9dd59/instructor%2Fclient.py#L311 instructor/dsl/iterable.pyThe changes introduce new conditions to handle Sweep Found These Issues
https://github.com/jxnl/instructor/blob/a846c45aec1ea00768591ff44a5f82c006f9dd59/instructor%2Fdsl%2Fiterable.py#L114-L115 instructor/dsl/partial.pyThe changes introduce new conditions to handle Sweep Found These Issues
https://github.com/jxnl/instructor/blob/a846c45aec1ea00768591ff44a5f82c006f9dd59/instructor%2Fdsl%2Fpartial.py#L185 tests/llm/test_anthropic/conftest.pyThe changes introduce pytest fixtures for tests/llm/test_anthropic/test_stream.pyThe changes add four new test functions to validate synchronous and asynchronous creation of models returning either an iterable or a partial Sweep Found These Issues
https://github.com/jxnl/instructor/blob/a846c45aec1ea00768591ff44a5f82c006f9dd59/tests%2Fllm%2Ftest_anthropic%2Ftest_stream.py#L33-L52 https://github.com/jxnl/instructor/blob/a846c45aec1ea00768591ff44a5f82c006f9dd59/tests%2Fllm%2Ftest_anthropic%2Ftest_stream.py#L72-L87 tests/llm/test_anthropic/util.pyIntroduced a new utility file for testing with model and mode configurations. Potential IssuesSweep isn't 100% sure if the following are issues or not but they may be worth taking a look at.
https://github.com/jxnl/instructor/blob/a846c45aec1ea00768591ff44a5f82c006f9dd59/tests%2Fllm%2Ftest_anthropic%2Futil.py#L1-L5 |
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.
❌ Changes requested. Reviewed everything up to a846c45 in 47 seconds
More details
- Looked at
242
lines of code in6
files - Skipped
0
files when reviewing. - Skipped posting
0
drafted comments based on config settings.
Workflow ID: wflow_dnsiYwLSpx2waGgY
Want Ellipsis to fix these issues? Tag @ellipsis-dev
in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
@@ -128,8 +128,6 @@ def create_partial( | |||
strict: bool = True, |
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.
The PR introduces significant functionality changes by supporting streaming for Anthropic. Please ensure that the documentation is updated to reflect these changes, and consider adding relevant entries to the mkdocs.yml if new documentation files are created.
if json_chunk := chunk.delta.text: | ||
yield json_chunk | ||
if mode == Mode.ANTHROPIC_TOOLS: | ||
yield chunk.model_extra.get("delta", "").get("partial_json", "") |
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.
yield chunk.model_extra.get("delta", "").get("partial_json", "") | |
yield chunk.model_extra.get("delta", {}).get("partial_json", "") |
should it be {} since "".get
would error?
can you try and update the documentation on anthropic docs? |
This change was missed in instructor-ai#682 Addresses instructor-ai#821
Streaming is now live on Anthropic. This change introduces json parsing support for streamed chunks.
https://docs.anthropic.com/en/api/messages-streaming
Summary:
This PR introduces streaming support for Anthropic in the instructor library, updating methods and adding tests to ensure functionality.
Key points:
instructor/client.py
for streaming support.instructor/dsl/iterable.py
andinstructor/dsl/partial.py
for new Anthropic modes.tests/llm/test_anthropic/
to validate streaming functionality.Generated with ❤️ by ellipsis.dev