1313if TYPE_CHECKING :
1414 from .._client import Replicate , AsyncReplicate
1515
16+ _STREAM_DOCSTRING = """
17+ Stream output from a model prediction.
18+
19+ This creates a prediction and returns an iterator that yields output chunks
20+ as strings as they become available from the streaming API.
21+
22+ Args:
23+ ref: Reference to the model or version to run. Can be:
24+ - A string containing a version ID
25+ - A string with owner/name format (e.g. "replicate/hello-world")
26+ - A string with owner/name:version format
27+ - A Model instance
28+ - A Version instance
29+ - A ModelVersionIdentifier dictionary
30+ file_encoding_strategy: Strategy for encoding file inputs
31+ **params: Additional parameters including the required "input" dictionary
32+
33+ Yields:
34+ str: Output chunks from the model as they become available
35+
36+ Raises:
37+ ValueError: If the reference format is invalid
38+ ReplicateError: If the prediction fails or streaming is not available
39+ """
40+
1641
1742def _resolve_reference (
1843 ref : Union [Model , Version , ModelVersionIdentifier , str ],
@@ -35,31 +60,7 @@ def stream(
3560 file_encoding_strategy : Optional ["FileEncodingStrategy" ] = None ,
3661 ** params : Unpack [PredictionCreateParamsWithoutVersion ],
3762) -> Iterator [str ]:
38- """
39- Stream output from a model prediction.
40-
41- This creates a prediction and returns an iterator that yields output chunks
42- as strings as they become available from the streaming API.
43-
44- Args:
45- client: The Replicate client instance
46- ref: Reference to the model or version to run. Can be:
47- - A string containing a version ID
48- - A string with owner/name format (e.g. "replicate/hello-world")
49- - A string with owner/name:version format
50- - A Model instance
51- - A Version instance
52- - A ModelVersionIdentifier dictionary
53- file_encoding_strategy: Strategy for encoding file inputs
54- **params: Additional parameters including the required "input" dictionary
55-
56- Yields:
57- str: Output chunks from the model as they become available
58-
59- Raises:
60- ValueError: If the reference format is invalid
61- ReplicateError: If the prediction fails or streaming is not available
62- """
63+ __doc__ = _STREAM_DOCSTRING
6364 version , owner , name , version_id = _resolve_reference (ref )
6465
6566 # Create prediction
@@ -112,25 +113,7 @@ async def async_stream(
112113 file_encoding_strategy : Optional ["FileEncodingStrategy" ] = None ,
113114 ** params : Unpack [PredictionCreateParamsWithoutVersion ],
114115) -> AsyncIterator [str ]:
115- """
116- Async stream output from a model prediction.
117-
118- This creates a prediction and returns an async iterator that yields output chunks
119- as strings as they become available from the streaming API.
120-
121- Args:
122- client: The AsyncReplicate client instance
123- ref: Reference to the model or version to run
124- file_encoding_strategy: Strategy for encoding file inputs
125- **params: Additional parameters including the required "input" dictionary
126-
127- Yields:
128- str: Output chunks from the model as they become available
129-
130- Raises:
131- ValueError: If the reference format is invalid
132- ReplicateError: If the prediction fails or streaming is not available
133- """
116+ __doc__ = _STREAM_DOCSTRING
134117 version , owner , name , version_id = _resolve_reference (ref )
135118
136119 # Create prediction
0 commit comments