-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (43 loc) · 1.57 KB
/
Copy pathmain.py
File metadata and controls
60 lines (43 loc) · 1.57 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import asyncio
import os
from copilot import CopilotClient
input_log: list[str] = []
async def auto_approve_permission(request, invocation):
return {"kind": "approved"}
async def auto_approve_tool(input_data, invocation):
return {"permissionDecision": "allow"}
async def handle_user_input(request, invocation):
input_log.append(f"question: {request['question']}")
return {"answer": "Paris", "wasFreeform": True}
async def main():
opts = {"github_token": os.environ.get("GITHUB_TOKEN")}
if os.environ.get("COPILOT_CLI_PATH"):
opts["cli_path"] = os.environ["COPILOT_CLI_PATH"]
client = CopilotClient(opts)
try:
session = await client.create_session(
{
"model": "claude-haiku-4.5",
"on_permission_request": auto_approve_permission,
"on_user_input_request": handle_user_input,
"hooks": {"on_pre_tool_use": auto_approve_tool},
}
)
response = await session.send_and_wait(
{
"prompt": (
"I want to learn about a city. Use the ask_user tool to ask me "
"which city I'm interested in. Then tell me about that city."
)
}
)
if response:
print(response.data.content)
await session.destroy()
print("\n--- User input log ---")
for entry in input_log:
print(f" {entry}")
print(f"\nTotal user input requests: {len(input_log)}")
finally:
await client.stop()
asyncio.run(main())