-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjbang-example.java
More file actions
38 lines (32 loc) · 1.44 KB
/
jbang-example.java
File metadata and controls
38 lines (32 loc) · 1.44 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
//DEPS io.github.copilot-community-sdk:copilot-sdk:1.0.8
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();
// Handle assistant message events
session.on(AssistantMessageEvent.class, msg -> {
System.out.println(msg.getData().getContent());
});
// Handle session usage info events
session.on(SessionUsageInfoEvent.class, usage -> {
var data = usage.getData();
System.out.println("\n--- Usage Metrics ---");
System.out.println("Current tokens: " + (int) data.getCurrentTokens());
System.out.println("Token limit: " + (int) data.getTokenLimit());
System.out.println("Messages count: " + (int) data.getMessagesLength());
});
// Send a message
var completable = session.sendAndWait(new MessageOptions().setPrompt("What is 2+2?"));
// and wait for completion
completable.get();
}
}
}