mirror of
https://github.com/github/awesome-copilot.git
synced 2026-04-11 02:35:55 +00:00
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -97,7 +97,7 @@ go run <filename>.go
|
||||
### Java
|
||||
|
||||
```bash
|
||||
cd java/cookbook/recipe
|
||||
cd java/recipe
|
||||
jbang <FileName>.java
|
||||
```
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ npx --version
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
jbang AccessibilityReport.java
|
||||
jbang recipe/AccessibilityReport.java
|
||||
# Enter a URL when prompted
|
||||
```
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Manage multiple independent conversations simultaneously.
|
||||
> **Runnable example:** [recipe/MultipleSessions.java](recipe/MultipleSessions.java)
|
||||
>
|
||||
> ```bash
|
||||
> jbang MultipleSessions.java
|
||||
> jbang recipe/MultipleSessions.java
|
||||
> ```
|
||||
|
||||
## Example scenario
|
||||
@@ -21,35 +21,39 @@ You need to run multiple conversations in parallel, each with its own context an
|
||||
import com.github.copilot.sdk.*;
|
||||
import com.github.copilot.sdk.json.*;
|
||||
|
||||
var client = new CopilotClient();
|
||||
client.start().get();
|
||||
public class MultipleSessions {
|
||||
public static void main(String[] args) throws Exception {
|
||||
var client = new CopilotClient();
|
||||
client.start().get();
|
||||
|
||||
// Create multiple independent sessions
|
||||
var session1 = client.createSession(new SessionConfig()
|
||||
.setModel("gpt-5")
|
||||
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
||||
var session2 = client.createSession(new SessionConfig()
|
||||
.setModel("gpt-5")
|
||||
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
||||
var session3 = client.createSession(new SessionConfig()
|
||||
.setModel("claude-sonnet-4.5")
|
||||
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
||||
// Create multiple independent sessions
|
||||
var session1 = client.createSession(new SessionConfig()
|
||||
.setModel("gpt-5")
|
||||
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
||||
var session2 = client.createSession(new SessionConfig()
|
||||
.setModel("gpt-5")
|
||||
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
||||
var session3 = client.createSession(new SessionConfig()
|
||||
.setModel("claude-sonnet-4.5")
|
||||
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
||||
|
||||
// Each session maintains its own conversation history
|
||||
session1.sendAndWait(new MessageOptions().setPrompt("You are helping with a Python project")).get();
|
||||
session2.sendAndWait(new MessageOptions().setPrompt("You are helping with a TypeScript project")).get();
|
||||
session3.sendAndWait(new MessageOptions().setPrompt("You are helping with a Go project")).get();
|
||||
// Each session maintains its own conversation history
|
||||
session1.sendAndWait(new MessageOptions().setPrompt("You are helping with a Python project")).get();
|
||||
session2.sendAndWait(new MessageOptions().setPrompt("You are helping with a TypeScript project")).get();
|
||||
session3.sendAndWait(new MessageOptions().setPrompt("You are helping with a Go project")).get();
|
||||
|
||||
// Follow-up messages stay in their respective contexts
|
||||
session1.sendAndWait(new MessageOptions().setPrompt("How do I create a virtual environment?")).get();
|
||||
session2.sendAndWait(new MessageOptions().setPrompt("How do I set up tsconfig?")).get();
|
||||
session3.sendAndWait(new MessageOptions().setPrompt("How do I initialize a module?")).get();
|
||||
// Follow-up messages stay in their respective contexts
|
||||
session1.sendAndWait(new MessageOptions().setPrompt("How do I create a virtual environment?")).get();
|
||||
session2.sendAndWait(new MessageOptions().setPrompt("How do I set up tsconfig?")).get();
|
||||
session3.sendAndWait(new MessageOptions().setPrompt("How do I initialize a module?")).get();
|
||||
|
||||
// Clean up all sessions
|
||||
session1.destroy().get();
|
||||
session2.destroy().get();
|
||||
session3.destroy().get();
|
||||
client.stop().get();
|
||||
// Clean up all sessions
|
||||
session1.destroy().get();
|
||||
session2.destroy().get();
|
||||
session3.destroy().get();
|
||||
client.stop().get();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Custom session IDs
|
||||
|
||||
@@ -22,7 +22,12 @@ public class AccessibilityReport {
|
||||
var reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
System.out.print("Enter URL to analyze: ");
|
||||
String url = reader.readLine().trim();
|
||||
String urlLine = reader.readLine();
|
||||
if (urlLine == null) {
|
||||
System.out.println("No URL provided. Exiting.");
|
||||
return;
|
||||
}
|
||||
String url = urlLine.trim();
|
||||
if (url.isEmpty()) {
|
||||
System.out.println("No URL provided. Exiting.");
|
||||
return;
|
||||
|
||||
@@ -24,8 +24,14 @@ public class ErrorHandling {
|
||||
|
||||
session.close();
|
||||
} catch (ExecutionException ex) {
|
||||
System.err.println("Error: " + ex.getCause().getMessage());
|
||||
ex.getCause().printStackTrace();
|
||||
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();
|
||||
|
||||
@@ -25,9 +25,9 @@ public class MultipleSessions {
|
||||
var s1 = f1.get(); var s2 = f2.get(); var s3 = f3.get();
|
||||
|
||||
// Send a message to each session
|
||||
System.out.println("S1: " + s1.sendAndWait(new MessageOptions().setPrompt("Explain Java records")).get().getMessage());
|
||||
System.out.println("S2: " + s2.sendAndWait(new MessageOptions().setPrompt("Explain sealed classes")).get().getMessage());
|
||||
System.out.println("S3: " + s3.sendAndWait(new MessageOptions().setPrompt("Explain pattern matching")).get().getMessage());
|
||||
System.out.println("S1: " + s1.sendAndWait(new MessageOptions().setPrompt("Explain Java records")).get().getData().content());
|
||||
System.out.println("S2: " + s2.sendAndWait(new MessageOptions().setPrompt("Explain sealed classes")).get().getData().content());
|
||||
System.out.println("S3: " + s3.sendAndWait(new MessageOptions().setPrompt("Explain pattern matching")).get().getData().content());
|
||||
|
||||
// Clean up
|
||||
s1.destroy().get(); s2.destroy().get(); s3.destroy().get();
|
||||
|
||||
@@ -54,10 +54,8 @@ jbang PRVisualization.java github/copilot-sdk
|
||||
jbang ManagingLocalFiles.java /path/to/your/folder
|
||||
```
|
||||
|
||||
**Ralph Loop in planning mode:**
|
||||
**Ralph Loop with a prompt file:**
|
||||
|
||||
```bash
|
||||
jbang RalphLoop.java plan 5
|
||||
```
|
||||
|
||||
## Why JBang?
|
||||
|
||||
Reference in New Issue
Block a user