forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (34 loc) · 1.34 KB
/
Copy pathmain.py
File metadata and controls
51 lines (34 loc) · 1.34 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
import asyncio
from copilot import CopilotClient
from copilot.generated.rpc import PermissionDecisionApproveOnce
input_log: list[str] = []
async def auto_approve_permission(request, invocation):
return PermissionDecisionApproveOnce()
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():
client = CopilotClient()
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(
"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.disconnect()
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())