Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (40 loc) · 1.5 KB
/
Copy pathmain.py
File metadata and controls
57 lines (40 loc) · 1.5 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
import asyncio
import os
from copilot import CopilotClient
from copilot.client import SubprocessConfig
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():
client = CopilotClient(SubprocessConfig(
github_token=os.environ.get("GITHUB_TOKEN"),
cli_path=os.environ.get("COPILOT_CLI_PATH"),
))
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())