Skip to content

feat(xai): add streaming support for xAI provider#1758

Merged
jxnl merged 7 commits into567-labs:mainfrom
jeongyoonm:feature/xai-streaming
Sep 5, 2025
Merged

feat(xai): add streaming support for xAI provider#1758
jxnl merged 7 commits into567-labs:mainfrom
jeongyoonm:feature/xai-streaming

Conversation

@jeongyoonm
Copy link
Copy Markdown
Contributor

@jeongyoonm jeongyoonm commented Jul 31, 2025

Summary

This PR resolves issue #1663. It adds streaming support for the xAI provider.

Description

  • Implemented iterable and partial streaming features for sync and async xAI clients.
  • Works for both XAI_JSON and XAI_TOOLS mode.
  • Added test cases that do simple and union extraction for every case.

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_xai function, and introduces new tests.

  • Behavior:
    • Adds streaming support for xAI provider in instructor/providers/xai/client.py.
    • Implements iterable and partial streaming for sync and async clients.
    • Supports XAI_JSON mode; XAI_TOOLS mode does not effectively stream.
  • Functions:
    • Modifies acreate() and create() to process streaming responses in instructor/providers/xai/client.py.
  • Tests:
    • Adds test_stream.py with tests for iterable and partial models, both sync and async.
    • Tests include simple and union extraction cases.
  • Misc:
    • Changes default mode to XAI_JSON in from_provider() in auto_client.py.

This description was created by Ellipsis for 5652050. You can customize this summary. It will automatically update as commits are pushed.

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 5652050 in 1 minute and 16 seconds. Click for details.
  • Reviewed 366 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 7 draft 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% <= threshold 85% 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% <= threshold 85% 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% <= threshold 85% 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% <= threshold 85% 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% <= threshold 85% 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% <= threshold 85% None

Workflow ID: wflow_fDjUNsMVzweKS8N9

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@jxnl
Copy link
Copy Markdown
Collaborator

jxnl commented Aug 1, 2025

This is great. I'll take a look this weekend after I see the tests pass.

@jeongyoonm
Copy link
Copy Markdown
Contributor Author

jeongyoonm commented Aug 2, 2025

@jxnl Checks are failing because API keys are not provided.
Screenshot 2025-08-02 at 8 25 54 AM
Please let me know if there's anything I can do regarding this. Thanks.

@jeongyoonm
Copy link
Copy Markdown
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.

@jxnl
Copy link
Copy Markdown
Collaborator

jxnl commented Sep 5, 2025

Sorry, just life got ahead of me. Taking a look now.

@jxnl jxnl merged commit bc97a48 into 567-labs:main Sep 5, 2025
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