mirror of
https://github.com/github/awesome-copilot.git
synced 2026-04-13 03: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
|
### Java
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd java/cookbook/recipe
|
cd java/recipe
|
||||||
jbang <FileName>.java
|
jbang <FileName>.java
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ npx --version
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
jbang AccessibilityReport.java
|
jbang recipe/AccessibilityReport.java
|
||||||
# Enter a URL when prompted
|
# Enter a URL when prompted
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Manage multiple independent conversations simultaneously.
|
|||||||
> **Runnable example:** [recipe/MultipleSessions.java](recipe/MultipleSessions.java)
|
> **Runnable example:** [recipe/MultipleSessions.java](recipe/MultipleSessions.java)
|
||||||
>
|
>
|
||||||
> ```bash
|
> ```bash
|
||||||
> jbang MultipleSessions.java
|
> jbang recipe/MultipleSessions.java
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
## Example scenario
|
## 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.*;
|
||||||
import com.github.copilot.sdk.json.*;
|
import com.github.copilot.sdk.json.*;
|
||||||
|
|
||||||
var client = new CopilotClient();
|
public class MultipleSessions {
|
||||||
client.start().get();
|
public static void main(String[] args) throws Exception {
|
||||||
|
var client = new CopilotClient();
|
||||||
|
client.start().get();
|
||||||
|
|
||||||
// Create multiple independent sessions
|
// Create multiple independent sessions
|
||||||
var session1 = client.createSession(new SessionConfig()
|
var session1 = client.createSession(new SessionConfig()
|
||||||
.setModel("gpt-5")
|
.setModel("gpt-5")
|
||||||
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
||||||
var session2 = client.createSession(new SessionConfig()
|
var session2 = client.createSession(new SessionConfig()
|
||||||
.setModel("gpt-5")
|
.setModel("gpt-5")
|
||||||
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
||||||
var session3 = client.createSession(new SessionConfig()
|
var session3 = client.createSession(new SessionConfig()
|
||||||
.setModel("claude-sonnet-4.5")
|
.setModel("claude-sonnet-4.5")
|
||||||
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
.setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get();
|
||||||
|
|
||||||
// Each session maintains its own conversation history
|
// Each session maintains its own conversation history
|
||||||
session1.sendAndWait(new MessageOptions().setPrompt("You are helping with a Python project")).get();
|
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();
|
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();
|
session3.sendAndWait(new MessageOptions().setPrompt("You are helping with a Go project")).get();
|
||||||
|
|
||||||
// Follow-up messages stay in their respective contexts
|
// Follow-up messages stay in their respective contexts
|
||||||
session1.sendAndWait(new MessageOptions().setPrompt("How do I create a virtual environment?")).get();
|
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();
|
session2.sendAndWait(new MessageOptions().setPrompt("How do I set up tsconfig?")).get();
|
||||||
session3.sendAndWait(new MessageOptions().setPrompt("How do I initialize a module?")).get();
|
session3.sendAndWait(new MessageOptions().setPrompt("How do I initialize a module?")).get();
|
||||||
|
|
||||||
// Clean up all sessions
|
// Clean up all sessions
|
||||||
session1.destroy().get();
|
session1.destroy().get();
|
||||||
session2.destroy().get();
|
session2.destroy().get();
|
||||||
session3.destroy().get();
|
session3.destroy().get();
|
||||||
client.stop().get();
|
client.stop().get();
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Custom session IDs
|
## Custom session IDs
|
||||||
|
|||||||
@@ -22,7 +22,12 @@ public class AccessibilityReport {
|
|||||||
var reader = new BufferedReader(new InputStreamReader(System.in));
|
var reader = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
|
||||||
System.out.print("Enter URL to analyze: ");
|
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()) {
|
if (url.isEmpty()) {
|
||||||
System.out.println("No URL provided. Exiting.");
|
System.out.println("No URL provided. Exiting.");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -24,8 +24,14 @@ public class ErrorHandling {
|
|||||||
|
|
||||||
session.close();
|
session.close();
|
||||||
} catch (ExecutionException ex) {
|
} catch (ExecutionException ex) {
|
||||||
System.err.println("Error: " + ex.getCause().getMessage());
|
Throwable cause = ex.getCause();
|
||||||
ex.getCause().printStackTrace();
|
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) {
|
} catch (Exception ex) {
|
||||||
System.err.println("Error: " + ex.getMessage());
|
System.err.println("Error: " + ex.getMessage());
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ public class MultipleSessions {
|
|||||||
var s1 = f1.get(); var s2 = f2.get(); var s3 = f3.get();
|
var s1 = f1.get(); var s2 = f2.get(); var s3 = f3.get();
|
||||||
|
|
||||||
// Send a message to each session
|
// Send a message to each session
|
||||||
System.out.println("S1: " + s1.sendAndWait(new MessageOptions().setPrompt("Explain Java records")).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().getMessage());
|
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().getMessage());
|
System.out.println("S3: " + s3.sendAndWait(new MessageOptions().setPrompt("Explain pattern matching")).get().getData().content());
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
s1.destroy().get(); s2.destroy().get(); s3.destroy().get();
|
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
|
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?
|
## Why JBang?
|
||||||
|
|||||||
Reference in New Issue
Block a user