MCPcopy Create free account
hub / github.com/IBM/mcp-cli / simple_streaming_example

Function simple_streaming_example

examples/getting_started/streaming_simple.py:20–49  ·  view source on GitHub ↗

Simple example of using StreamingContext.

()

Source from the content-addressed store, hash-verified

18
19
20async def simple_streaming_example():
21 """Simple example of using StreamingContext."""
22 console = Console()
23
24 # Simulate chunks coming from an LLM
25 text_chunks = [
26 "I'll help you ",
27 "understand how ",
28 "streaming works.\n\n",
29 "When content streams ",
30 "from an LLM, ",
31 "it arrives in chunks ",
32 "like this.\n\n",
33 "The streaming display:\n",
34 "• Shows a progress indicator\n",
35 "• Detects content type\n",
36 "• Provides a preview\n",
37 "• Shows statistics\n\n",
38 "This makes the ",
39 "experience more ",
40 "responsive!",
41 ]
42
43 # Use StreamingContext - it's that simple!
44 with StreamingContext(console=console, title="🤖 Assistant") as ctx:
45 for chunk in text_chunks:
46 ctx.update(chunk)
47 await asyncio.sleep(0.1) # Simulate network delay
48
49 print("\n✅ Streaming complete!")
50
51
52async def streaming_with_code():

Callers 1

mainFunction · 0.85

Calls 1

updateMethod · 0.80

Tested by

no test coverage detected