Streaming with Funcchain¶
Example
See stream.py
This serves as an example of how to implement streaming output for text generation tasks using funcchain.
Full Code Example¶
Demo
Instructions¶
Step-by-step
Necessary Imports
Configure Settings
The settings are configured to set the temperature, which controls the creativity of the language model's output. Experiment with different values.
Define the Story Generation Function
The generate_story_of function is designed to take a topic and use the chain function to generate a story.
def generate_story_of(topic: str) -> str:
"""
Write a short story based on the topic.
"""
return chain()
Execute the Streaming Generation
This block uses the stream_to context manager to print the output of the story generation function as it is being streamed. This is how you stream the story while it is being generated.