-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add support for replicate.stream() #75
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
Conversation
This PR adds support for streaming predictions via the `replicate.stream()` method. Changes: - Add `stream()` method to both Replicate and AsyncReplicate clients - Add module-level `stream()` function for convenience - Create new `lib/_predictions_stream.py` module with streaming logic - Add comprehensive tests for sync and async streaming - Update README with documentation and examples using anthropic/claude-4-sonnet The stream method creates a prediction and returns an iterator that yields output chunks as they become available via Server-Sent Events (SSE). This is useful for language models where you want to display output as it's generated.
DP-671 Add support for `replicate.stream()`
The legacy 1.x client supports a method called When creating a prediction via APi, the returned prediction object will always have a Docs about streaming are here: https://replicate.com/docs/topics/predictions/streaming Tasks:
|
The API uses Server-Sent Events internally, but the Python client yields plain string chunks to the user, not SSE event objects.
|
Some thoughts:
|
What effect does that have? The function still works, but a user also sees that error message if they try to run it? Is there a proper way to not implement it at all, but display a helpful message when users call |
|
Replaced by #79 |
This PR adds support for streaming predictions via the
replicate.stream()method, as specified in DP-671This change is intended to support feature parity with the legacy pre-Stainless 1.x client.
Changes
stream()method to bothReplicateandAsyncReplicateclientsstream()function for conveniencelib/_predictions_stream.pymodule with streaming logicanthropic/claude-4-sonnetThe
stream()method creates a prediction and returns an iterator that yields output chunks as strings as they become available from the streaming API. This is useful for language models where you want to display output as it's generated rather than waiting for the entire response.Example Usage
Testing locally
Clone the repo and checkout the branch:
gh repo clone replicate/replicate-python-stainless cd replicate-python-stainless gh pr checkout 75Set up the development environment:
Run the tests:
Try the example:
Prompts
Related: DP-671