Skip to content

Fix Cohere streaming and xAI tools validation#1983

Merged
jxnl merged 2 commits intomainfrom
fix-cohere-xai-streaming
Jan 4, 2026
Merged

Fix Cohere streaming and xAI tools validation#1983
jxnl merged 2 commits intomainfrom
fix-cohere-xai-streaming

Conversation

@jxnl
Copy link
Copy Markdown
Collaborator

@jxnl jxnl commented Jan 4, 2026

Summary

  • use cohere chat_stream for streaming and handle async return types safely
  • add Cohere streaming chunk extraction for Partial/Iterable
  • validate xAI tools responses with prepared models and unwrap adapter results

Testing

  • not run (API keys required)

Important

Enhance Cohere streaming and xAI tools validation by using chat_stream and validating responses with prepared models.

  • Cohere Streaming:
    • Use chat_stream for streaming in from_cohere() in client.py.
    • Add chunk extraction logic for Mode.COHERE_TOOLS and Mode.COHERE_JSON_SCHEMA in extract_json() and extract_json_async() in iterable.py and partial.py.
  • xAI Tools Validation:
    • Validate responses with prepared models in acreate() and create() in client.py.
    • Unwrap adapter results in _validate_model_from_json() in function_calls.py.
  • Misc:
    • Update ty-check args in .pre-commit-config.yaml to ignore unresolved imports.

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

@github-actions github-actions Bot added dependencies Pull requests that update a dependency file enhancement New feature or request python Pull requests that update python code labels Jan 4, 2026
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 83dd71c in 1 minute and 16 seconds. Click for details.
  • Reviewed 464 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 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. instructor/dsl/iterable.py:153
  • Draft comment:
    The COHERE extraction logic (handling event_type and chunk_type) is duplicated in both sync and async methods. Consider refactoring this block into a helper function to adhere to DRY principles.
  • Reason this comment was not posted:
    Confidence changes required: 80% <= threshold 85% None
2. instructor/providers/cohere/client.py:84
  • Draft comment:
    In the async_wrapper, using call_kwargs.pop("stream", False) directly modifies the caller’s dictionary. Consider copying the kwargs before modification to prevent unintended side effects.
  • Reason this comment was not posted:
    Confidence changes required: 80% <= threshold 85% None
3. instructor/providers/xai/client.py:137
  • Draft comment:
    The logic for selecting and preparing the response model (using prepare_response_model for XAI_TOOLS or streaming mode) could benefit from an inline comment clarifying the decision criteria for future maintainers.
  • Reason this comment was not posted:
    Confidence changes required: 80% <= threshold 85% None
4. instructor/providers/xai/client.py:218
  • Draft comment:
    The error message when no tool calls and no text content are found includes the raw response. Ensure that exposing raw responses does not leak sensitive data in production.
  • Reason this comment was not posted:
    Confidence changes required: 80% <= threshold 85% None
5. instructor/providers/xai/client.py:312
  • Draft comment:
    The non-streaming branch in the create function duplicates JSON extraction logic from both text and tool_call paths. Consider refactoring this repeated logic into a dedicated helper to reduce duplication.
  • Reason this comment was not posted:
    Confidence changes required: 80% <= threshold 85% None

Workflow ID: wflow_r5S1IlEJEP8WT8IW

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

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Jan 4, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
instructor 159f121 Commit Preview URL

Branch Preview URL
Jan 04 2026, 04:45 PM

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 159f121 in 57 seconds. Click for details.
  • Reviewed 589 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 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. .pre-commit-config.yaml:37
  • Draft comment:
    The ty-check hook now ignores unresolved imports. Please add a brief comment explaining why '--ignore unresolved-import' is needed.
  • Reason this comment was not posted:
    Confidence changes required: 80% <= threshold 85% None
2. instructor/dsl/iterable.py:157
  • Draft comment:
    There is repeated JSON start extraction logic (search for '{' or '[' and slicing) in multiple event branches. Consider refactoring this pattern into a helper function to adhere to the DRY principle.
  • Reason this comment was not posted:
    Confidence changes required: 80% <= threshold 85% None
3. instructor/dsl/iterable.py:370
  • Draft comment:
    The asynchronous JSON extraction (in extract_json_async) duplicates similar logic to its synchronous counterpart. Centralize the JSON start extraction into a shared helper to improve maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 80% <= threshold 85% None
4. instructor/dsl/partial.py:288
  • Draft comment:
    Multiple branches in the extract_json function show nearly identical logic for locating the JSON start index. Refactor these repeated blocks into a common helper to reduce duplication.
  • Reason this comment was not posted:
    Confidence changes required: 80% <= threshold 85% None
5. instructor/dsl/partial.py:245
  • Draft comment:
    Potential bug: In model_from_chunks, 'chunk_buffer += chunk' is used, which concatenates the characters of the string instead of appending the full chunk. Use 'chunk_buffer.append(chunk)' to correctly accumulate whole chunks.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_KlNJhd3BDhfMG1M8

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

@jxnl jxnl merged commit bc375d8 into main Jan 4, 2026
9 checks passed
@jxnl jxnl deleted the fix-cohere-xai-streaming branch January 4, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant