-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjbang-example.java
More file actions
34 lines (28 loc) · 1.14 KB
/
jbang-example.java
File metadata and controls
34 lines (28 loc) · 1.14 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
//DEPS io.github.copilot-community-sdk:copilot-sdk:1.0.0
import com.github.copilot.sdk.*;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
import java.util.concurrent.CompletableFuture;
class CopilotSDK {
public static void main(String[] args) throws Exception {
// Create and start client
try (var client = new CopilotClient()) {
client.start().get();
// Create a session
var session = client.createSession(
new SessionConfig().setModel("claude-sonnet-4.5")).get();
// Wait for response using session.idle event
var done = new CompletableFuture<Void>();
session.on(evt -> {
if (evt instanceof AssistantMessageEvent msg) {
System.out.println(msg.getData().getContent());
} else if (evt instanceof SessionIdleEvent) {
done.complete(null);
}
});
// Send a message and wait for completion
session.send(new MessageOptions().setPrompt("What is 2+2?")).get();
done.get();
}
}
}