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

Class MockStreamingClient

examples/streaming/mcp_cli_working_demo.py:36–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35 # Mock a simple streaming client
36 class MockStreamingClient:
37 async def create_completion(self, messages, tools=None, stream=True, **kwargs):
38 """Simulate an LLM that streams responses."""
39
40 # Different responses based on the question
41 user_msg = messages[-1]["content"] if messages else ""
42
43 if "code" in user_msg.lower():
44 # Code response
45 chunks = [
46 {"response": "I'll"},
47 {"response": "I'll help"},
48 {"response": "I'll help you"},
49 {"response": "I'll help you with"},
50 {"response": "I'll help you with a"},
51 {"response": "I'll help you with a Python"},
52 {"response": "I'll help you with a Python function"},
53 {"response": "I'll help you with a Python function:\n\n```python"},
54 {
55 "response": "I'll help you with a Python function:\n\n```python\ndef"
56 },
57 {
58 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci"
59 },
60 {
61 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n"
62 },
63 {
64 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):"
65 },
66 {
67 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if"
68 },
69 {
70 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n"
71 },
72 {
73 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n <="
74 },
75 {
76 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n <= 1"
77 },
78 {
79 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n <= 1:"
80 },
81 {
82 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n <= 1:\n return"
83 },
84 {
85 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n <= 1:\n return n"
86 },
87 {
88 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n <= 1:\n return n\n return"
89 },
90 {
91 "response": "I'll help you with a Python function:\n\n```python\ndef fibonacci(n):\n if n <= 1:\n return n\n return fibonacci"
92 },
93 {

Callers 1

demo_streaming_handlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected