Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

fix streamify docstring (#1999)

Chen Qian8825040bd3a5
diff --git a/dspy/utils/streaming.py b/dspy/utils/streaming.py
index bf1f4f5bd..b897ba08a 100644
--- a/dspy/utils/streaming.py
+++ b/dspy/utils/streaming.py
@@ -18,23 +18,27 @@ def streamify(program: Module) -> Callable[[Any, Any], Awaitable[Any]]:
Args:
program: The DSPy program to wrap with streaming functionality.
+
Returns:
A function that takes the same arguments as the original program, but returns an async
- generator that yields the program's outputs incrementally.
+ generator that yields the program's outputs incrementally.
Example:
- >>> class TestSignature(dspy.Signature):
- >>> input_text: str = dspy.InputField()
- >>> output_text: str = dspy.OutputField()
- >>>
- >>> # Create the program and wrap it with streaming functionality
- >>> program = dspy.streamify(dspy.Predict(TestSignature))
- >>>
- >>> # Use the program with streaming output
- >>> async def use_streaming():
- >>> output_stream = program(input_text="Test")
- >>> async for value in output_stream:
- >>> print(value) # Print each streamed value incrementally
+
+ ```python
+ class TestSignature(dspy.Signature):
+ input_text: str = dspy.InputField()
+ output_text: str = dspy.OutputField()
+
+ # Create the program and wrap it with streaming functionality
+ program = dspy.streamify(dspy.Predict(TestSignature))
+
+ # Use the program with streaming output
+ async def use_streaming():
+ output_stream = program(input_text="Test")
+ async for value in output_stream:
+ print(value) # Print each streamed value incrementally
+ ```
"""
import dspy