-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add deprecated replicate.stream() for v1 compatibility
#79
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
Merged
zeke
merged 7 commits into
main
from
dp-671-add-deprecated-support-for-replicatestream-in-the-v2-python
Oct 10, 2025
+431
−31
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
621162a
feat: add deprecated replicate.stream() for v1 compatibility
zeke fee09ac
fix: add pyright ignores for deprecated function usage in tests and i…
zeke 8fadecb
fix: correct test assertions and add missing pyright ignore
zeke 019c4d6
fix: add pyright ignores for deprecated imports and unknown types
zeke 9b9d6b9
fix: add mypy type ignore for var-annotated
zeke 1fefbf4
Merge branch 'main' into dp-671-add-deprecated-support-for-replicates…
zeke 1f036c8
docs: remove incorrect Raises section from stream() docstring
zeke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| """ | ||
| Deprecated streaming functionality for backwards compatibility with v1 SDK. | ||
|
|
||
| This module provides the stream() function which wraps replicate.use() with streaming=True. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import warnings | ||
| from typing import Any, Dict, Type, Union, Iterator, AsyncIterator, overload | ||
| from typing_extensions import deprecated | ||
|
|
||
| from .._client import Client, AsyncClient | ||
| from ._predictions_use import use | ||
|
|
||
| __all__ = ["stream"] | ||
|
|
||
|
|
||
| def _format_deprecation_message(ref: str, input: Dict[str, Any]) -> str: | ||
| """Format the deprecation message with a working example.""" | ||
| # Format the input dict for display | ||
| input_str = "{\n" | ||
| for key, value in input.items(): | ||
| if isinstance(value, str): | ||
| input_str += f' "{key}": "{value}",\n' | ||
| else: | ||
| input_str += f' "{key}": {value},\n' | ||
| input_str += " }" | ||
|
|
||
| return ( | ||
| f"replicate.stream() is deprecated and will be removed in a future version. " | ||
| f"Use replicate.use() with streaming=True instead:\n\n" | ||
| f' model = replicate.use("{ref}", streaming=True)\n' | ||
| f" for event in model(input={input_str}):\n" | ||
| f' print(str(event), end="")\n' | ||
| ) | ||
|
|
||
|
|
||
| @overload | ||
| def stream( | ||
| client: Type[Client], | ||
| ref: str, | ||
| *, | ||
| input: Dict[str, Any], | ||
| ) -> Iterator[str]: ... | ||
|
|
||
|
|
||
| @overload | ||
| def stream( | ||
| client: Type[AsyncClient], | ||
| ref: str, | ||
| *, | ||
| input: Dict[str, Any], | ||
| ) -> AsyncIterator[str]: ... | ||
|
|
||
|
|
||
| @deprecated("replicate.stream() is deprecated. Use replicate.use() with streaming=True instead") | ||
| def stream( | ||
| client: Union[Type[Client], Type[AsyncClient]], | ||
| ref: str, | ||
| *, | ||
| input: Dict[str, Any], | ||
| ) -> Union[Iterator[str], AsyncIterator[str]]: | ||
| """ | ||
| Run a model and stream its output (deprecated). | ||
|
|
||
| This function is deprecated. Use replicate.use() with streaming=True instead: | ||
|
|
||
| model = replicate.use("anthropic/claude-4.5-sonnet", streaming=True) | ||
| for event in model(input={"prompt": "Hello"}): | ||
| print(str(event), end="") | ||
|
|
||
| Args: | ||
| client: The Replicate client class (Client or AsyncClient) | ||
| ref: Reference to the model to run. Can be a string with owner/name format | ||
| (e.g., "anthropic/claude-4.5-sonnet") or owner/name:version format. | ||
| input: Dictionary of input parameters for the model. The required keys depend | ||
| on the specific model being run. | ||
|
|
||
| Returns: | ||
| An iterator (or async iterator) that yields output strings as they are | ||
| generated by the model | ||
|
|
||
| Raises: | ||
| DeprecationWarning: Always raised when this function is called | ||
| """ | ||
| # Log deprecation warning with helpful migration example | ||
| warnings.warn( | ||
| _format_deprecation_message(ref, input), | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
|
|
||
| # Use the existing use() function with streaming=True | ||
| model = use(client, ref, streaming=True) # type: ignore[var-annotated] # pyright: ignore[reportUnknownVariableType] | ||
|
|
||
| # Call the model with the input | ||
| return model(**input) # type: ignore[return-value] | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's wrong, no? We don't seem to raise an exception here, only log a warning message from what I can see 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Fixed in 1f036c8 - removed the incorrect Raises section since we only issue a warning, not raise an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝🏼 Hey, real Zeke here. Claude wrote that comment. I think this is the first time I've seen Claude Code successfully comment inline on a PR review!
I think it was this prompting: https://github.com/zeke/dotfiles/blob/e0277d51382eb08713b7181da6a4ef7ee4969424/.claude/CLAUDE.md#L19-L23