feat(xai): add streaming support for xAI provider#1758
Merged
jxnl merged 7 commits into567-labs:mainfrom Sep 5, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 5652050 in 1 minute and 16 seconds. Click for details.
- Reviewed
366lines of code in4files - Skipped
0files when reviewing. - Skipped posting
7draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. .ruff.toml:53
- Draft comment:
Removed 'ignore-init-module-imports'. Confirm this removal is intentional and does not break existing projects. - Reason this comment was not posted:
Comment looked like it was already resolved.
2. instructor/auto_client.py:920
- Draft comment:
Default mode updated to Mode.XAI_JSON instead of Mode.JSON. Verify this change for backward compatibility. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%<= threshold85%The comment is asking the author to verify backward compatibility, which is against the rules. It doesn't provide a specific suggestion or point out a clear issue with the code change. Therefore, it should be removed.
3. instructor/providers/xai/client.py:83
- Draft comment:
Extraction of the 'stream' flag via call_kwargs.pop('stream', False) is clear. Consider refactoring similar kwarg cleanup into a helper for DRY. - Reason this comment was not posted:
Confidence changes required:50%<= threshold85%None
4. instructor/providers/xai/client.py:95
- Draft comment:
Streaming logic for JSON mode is duplicated in async and sync paths. Consider extracting the common logic to a helper function to reduce code repetition. - Reason this comment was not posted:
Confidence changes required:80%<= threshold85%None
5. instructor/providers/xai/client.py:125
- Draft comment:
In the async tool mode branch, the async generator comprehension for 'args' may be empty if no tool_calls are returned. Consider handling an empty stream explicitly. - Reason this comment was not posted:
Confidence changes required:80%<= threshold85%None
6. instructor/providers/xai/client.py:202
- Draft comment:
In the synchronous tool mode streaming branch, if no tool_calls are found during iteration the function may return None. Consider adding explicit handling (e.g. raise an error) for such cases. - Reason this comment was not posted:
Confidence changes required:80%<= threshold85%None
7. tests/llm/test_xai/test_stream.py:15
- Draft comment:
Test cases cover sync and async streaming for iterable and partial models. Consider adding tests for failure cases or empty streaming responses. - Reason this comment was not posted:
Confidence changes required:50%<= threshold85%None
Workflow ID: wflow_fDjUNsMVzweKS8N9
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Collaborator
|
This is great. I'll take a look this weekend after I see the tests pass. |
Contributor
Author
|
@jxnl Checks are failing because API keys are not provided. |
Contributor
Author
|
@jxnl Just to follow up on this. Checks are failing because API keys are not provided. Please let me know if there's a way to fix this on my end. |
Collaborator
|
Sorry, just life got ahead of me. Taking a look now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR resolves issue #1663. It adds streaming support for the xAI provider.
Description
Note: XAI_TOOLS does not support streaming. The current implementation works, but effectively it is not streaming.
See https://docs.x.ai/docs/guides/function-calling .
PTAL @jxnl @ivanleomk
Important
Adds streaming support for xAI provider with iterable and partial streaming features, updates
from_xaifunction, and introduces new tests.instructor/providers/xai/client.py.acreate()andcreate()to process streaming responses ininstructor/providers/xai/client.py.test_stream.pywith tests for iterable and partial models, both sync and async.XAI_JSONinfrom_provider()inauto_client.py.This description was created by
for 5652050. You can customize this summary. It will automatically update as commits are pushed.