Example with code content.
()
| 50 | |
| 51 | |
| 52 | async def streaming_with_code(): |
| 53 | """Example with code content.""" |
| 54 | console = Console() |
| 55 | |
| 56 | code_response = """Here's a Python function: |
| 57 | |
| 58 | ```python |
| 59 | def fibonacci(n): |
| 60 | if n <= 1: |
| 61 | return n |
| 62 | return fibonacci(n-1) + fibonacci(n-2) |
| 63 | ``` |
| 64 | |
| 65 | This implements the Fibonacci sequence recursively.""" |
| 66 | |
| 67 | # Stream it character by character for smooth effect |
| 68 | with StreamingContext( |
| 69 | console=console, title="📝 Code Example", mode="response" |
| 70 | ) as ctx: |
| 71 | for char in code_response: |
| 72 | ctx.update(char) |
| 73 | await asyncio.sleep(0.01) # Very smooth streaming |
| 74 | |
| 75 | |
| 76 | async def main(): |