-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathchat.py
More file actions
42 lines (31 loc) · 1.06 KB
/
chat.py
File metadata and controls
42 lines (31 loc) · 1.06 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
41
42
import asyncio
from copilot import CopilotClient
from copilot.session import PermissionHandler
BLUE = "\033[34m"
RESET = "\033[0m"
async def main():
client = CopilotClient()
await client.start()
session = await client.create_session(on_permission_request=PermissionHandler.approve_all)
def on_event(event):
output = None
if event.type.value == "assistant.reasoning":
output = f"[reasoning: {event.data.content}]"
elif event.type.value == "tool.execution_start":
output = f"[tool: {event.data.tool_name}]"
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(user_input)
print(f"\nAssistant: {reply.data.content if reply else None}\n")
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nBye!")