-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathchat.py
More file actions
40 lines (30 loc) · 1.07 KB
/
chat.py
File metadata and controls
40 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import asyncio
import json
from copilot import CopilotClient
BLUE = "\033[34m"
RESET = "\033[0m"
async def main():
async with CopilotClient() as client:
session = await client.create_session()
def on_event(event):
output = None
if event.type == "assistant.reasoning":
output = f"[reasoning: {event.data.content}]"
elif event.type == "tool.execution_start":
output = f"[tool: {event.data.tool_name} {json.dumps(event.data.arguments)}]"
if output:
print(f"{BLUE}{output}{RESET}")
session.on(on_event)
print("Chat with Copilot (Ctrl+C to exit)\n")
while True:
user_input = input("You: ").strip()
if not user_input:
continue
print()
reply = await session.send_and_wait({"prompt": user_input})
print(f"\nAssistant: {reply.data.content if reply else None}\n")
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nBye!")