-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (45 loc) · 1.56 KB
/
Copy pathProgram.cs
File metadata and controls
52 lines (45 loc) · 1.56 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
using GitHub.Copilot.SDK;
var inputLog = new List<string>();
using var client = new CopilotClient(new CopilotClientOptions
{
CliPath = Environment.GetEnvironmentVariable("COPILOT_CLI_PATH"),
GitHubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN"),
});
await client.StartAsync();
try
{
await using var session = await client.CreateSessionAsync(new SessionConfig
{
Model = "claude-haiku-4.5",
OnPermissionRequest = (request, invocation) =>
Task.FromResult(new PermissionRequestResult { Kind = "approved" }),
OnUserInputRequest = (request, invocation) =>
{
inputLog.Add($"question: {request.Question}");
return Task.FromResult(new UserInputResponse { Answer = "Paris", WasFreeform = true });
},
Hooks = new SessionHooks
{
OnPreToolUse = (input, invocation) =>
Task.FromResult<PreToolUseHookOutput?>(new PreToolUseHookOutput { PermissionDecision = "allow" }),
},
});
var response = await session.SendAndWaitAsync(new MessageOptions
{
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 != null)
{
Console.WriteLine(response.Data?.Content);
}
Console.WriteLine("\n--- User input log ---");
foreach (var entry in inputLog)
{
Console.WriteLine($" {entry}");
}
Console.WriteLine($"\nTotal user input requests: {inputLog.Count}");
}
finally
{
await client.StopAsync();
}