-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathErrorHandling.java
More file actions
39 lines (34 loc) · 1.42 KB
/
ErrorHandling.java
File metadata and controls
39 lines (34 loc) · 1.42 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
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.github:copilot-sdk-java:0.2.1-java.1
import com.github.copilot.sdk.*;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
import java.util.concurrent.ExecutionException;
public class ErrorHandling {
public static void main(String[] args) {
try (var client = new CopilotClient()) {
client.start().get();
try (var session = client.createSession(
new SessionConfig()
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
.setModel("gpt-5")).get()) {
session.on(AssistantMessageEvent.class,
msg -> System.out.println(msg.getData().content()));
session.sendAndWait(
new MessageOptions().setPrompt("Hello!")).get();
}
} catch (ExecutionException ex) {
Throwable cause = ex.getCause();
Throwable error = cause != null ? cause : ex;
System.err.println("Error: " + error.getMessage());
error.printStackTrace();
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
System.err.println("Interrupted: " + ex.getMessage());
ex.printStackTrace();
} catch (Exception ex) {
System.err.println("Error: " + ex.getMessage());
ex.printStackTrace();
}
}
}