Skip to content

Added streaming support#252

Open
Sirsho1997 wants to merge 6 commits intomainfrom
feature-streaming
Open

Added streaming support#252
Sirsho1997 wants to merge 6 commits intomainfrom
feature-streaming

Conversation

@Sirsho1997
Copy link
Collaborator

@Sirsho1997 Sirsho1997 commented Mar 8, 2026

Added

  • Streaming text inference: When ITextInference.deliveryMethod is EDeliveryMethod.STREAM, textInference() returns an async iterator that yields:
    • Content chunks (str) from choices[0].delta.content
    • A final IText with usage (ITextInferenceUsage), cost, finishReason, taskUUID
  • _requestTextStream() in base: HTTP POST with Accept: text/event-stream, SSE line parsing (data: prefix), json.loads(line), and support for both line.get("data") and top-level keys.
  • TEXT_STREAM_READ_TIMEOUT in utils (milliseconds): configurable via RUNWARE_TEXT_STREAM_TIMEOUT (default 600000, 10 min) for long-lived SSE reads.
  • get_http_url_from_ws_url() in utils: maps WebSocket base URL to HTTP URL via _WS_TO_HTTP (from BASE_RUNWARE_URLS / BASE_RUNWARE_HTTP_URLS).
  • _WS_TO_HTTP dict in utils: BASE_RUNWARE_URLS[env]BASE_RUNWARE_HTTP_URLS[env] for production and test.
  • Stream under semaphore: Streaming path uses _request_semaphore so streamed requests count toward RUNWARE_MAX_CONCURRENT_REQUESTS.
  • README: Documented RUNWARE_TEXT_STREAM_TIMEOUT under “Text Operations” in Configuring Timeouts.

Changed

  • textInference(): Uses EDeliveryMethod (and requestText.deliveryMethod) to branch; stream path returns stream_with_semaphore() wrapper around _requestTextStream().
  • Stream errors: _requestTextStream() wraps execution in try/except and re-raises as RunwareAPIError({"message": str(e)}) for consistent error handling.
  • Removed ITextStreamChunk: Final stream payload is now IText (same as sync response) with taskType, taskUUID, finishReason, usage, cost.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds SDK-level support for streaming text inference by introducing an HTTP base URL alongside the existing WebSocket base URL and wiring deliveryMethod="stream" into textInference().

Changes:

  • Added HTTP base URLs and a WS→HTTP mapping helper (get_http_url_from_ws_url) for streaming requests.
  • Extended EDeliveryMethod with STREAM and routed textInference() to an SSE-based HTTP streaming implementation.
  • Added httpx as a dependency in requirements.txt.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

File Description
runware/utils.py Introduces HTTP base URL constants and WS→HTTP translation helper used by streaming.
runware/types.py Adds EDeliveryMethod.STREAM.
runware/base.py Implements SSE streaming path for textInference() using httpx.
requirements.txt Adds httpx dependency for the new streaming implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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