dspy.streamify
dspy.streamify(program: Module) -> Callable[[Any, Any], Awaitable[Any]]
Wrap a DSPy program so that it streams its outputs incrementally, rather than returning them all at once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
program
|
Module
|
The DSPy program to wrap with streaming functionality. |
required |
Returns:
Type | Description |
---|---|
Callable[[Any, Any], Awaitable[Any]]
|
A function that takes the same arguments as the original program, but returns an async 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