FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
copilot-sdk/java/sdk/jbang-example.java at main · github/copilot-sdk · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
copilot-sdk
Public
Notifications
You must be signed in to change notification settings
Fork
1.4k
Star
10.4k
Code
Issues
229
Pull requests
39
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
copilot-sdk
/
java
/
sdk
/
jbang-example.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (36 loc) · 1.67 KB
Breadcrumbs
copilot-sdk
/
java
/
sdk
/
jbang-example.java
Copy path
File metadata and controls
42 lines (36 loc) · 1.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.github:copilot-sdk-java:1.0.13-preview.1
import
com
.
github
.
copilot
.
CopilotClient
;
import
com
.
github
.
copilot
.
generated
.
AssistantMessageEvent
;
import
com
.
github
.
copilot
.
generated
.
SessionUsageInfoEvent
;
import
com
.
github
.
copilot
.
rpc
.
MessageOptions
;
import
com
.
github
.
copilot
.
rpc
.
PermissionHandler
;
import
com
.
github
.
copilot
.
rpc
.
SessionConfig
;
import
static
java
.
lang
.
System
.
out
;
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
().
setOnPermissionRequest
(
PermissionHandler
.
APPROVE_ALL
).
setModel
(
"claude-sonnet-4.5"
)).
get
();
// Handle assistant message events
session
.
on
(
AssistantMessageEvent
.
class
,
msg
-> {
out
.
println
(
msg
.
getData
().
content
());
});
// Handle session usage info events
session
.
on
(
SessionUsageInfoEvent
.
class
,
usage
-> {
var
data
=
usage
.
getData
();
out
.
println
(
"
\n
--- Usage Metrics ---"
);
out
.
println
(
"Current tokens: "
+
data
.
currentTokens
().
intValue
());
out
.
println
(
"Token limit: "
+
data
.
tokenLimit
().
intValue
());
out
.
println
(
"Messages count: "
+
data
.
messagesLength
().
intValue
());
});
// Send a message
var
completable
=
session
.
sendAndWait
(
new
MessageOptions
().
setPrompt
(
"What is 2+2?"
));
// and wait for completion
completable
.
get
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL