mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-22 11:25:13 +00:00
Fix Go cookbook recipes to use correct SDK API
All 5 Go recipes and their markdown docs used incorrect API patterns that don't match the real github.com/github/copilot-sdk/go v0.1.23: - copilot.NewClient() -> copilot.NewClient(nil) (*ClientOptions param) - client.Start() -> client.Start(ctx) (context.Context required) - copilot.SessionConfig -> &copilot.SessionConfig (pointer required) - session.On(func(event copilot.Event)) -> session.On(func(event copilot.SessionEvent)) - Type assertions -> event.Type string check + *event.Data.Content deref - session.WaitForIdle() -> session.SendAndWait(ctx, ...) (WaitForIdle doesn't exist) - copilot.SystemMessage -> copilot.SystemMessageConfig All 5 recipes verified to compile against SDK v0.1.23.
This commit is contained in:
@@ -39,6 +39,7 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -46,7 +47,7 @@ import (
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"github.com/github/copilot-sdk/go"
|
||||
copilot "github.com/github/copilot-sdk/go"
|
||||
)
|
||||
|
||||
// ============================================================================
|
||||
@@ -94,6 +95,7 @@ func promptForRepo() string {
|
||||
// ============================================================================
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
repoFlag := flag.String("repo", "", "GitHub repository (owner/repo)")
|
||||
flag.Parse()
|
||||
|
||||
@@ -126,18 +128,18 @@ func main() {
|
||||
parts := strings.SplitN(repo, "/", 2)
|
||||
owner, repoName := parts[0], parts[1]
|
||||
|
||||
// Create Copilot client - no custom tools needed!
|
||||
client := copilot.NewClient(copilot.ClientConfig{LogLevel: "error"})
|
||||
// Create Copilot client
|
||||
client := copilot.NewClient(nil)
|
||||
|
||||
if err := client.Start(); err != nil {
|
||||
if err := client.Start(ctx); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer client.Stop()
|
||||
|
||||
cwd, _ := os.Getwd()
|
||||
session, err := client.CreateSession(copilot.SessionConfig{
|
||||
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
|
||||
Model: "gpt-5",
|
||||
SystemMessage: copilot.SystemMessage{
|
||||
SystemMessage: &copilot.SystemMessageConfig{
|
||||
Content: fmt.Sprintf(`
|
||||
<context>
|
||||
You are analyzing pull requests for the GitHub repository: %s/%s
|
||||
@@ -159,12 +161,16 @@ The current working directory is: %s
|
||||
defer session.Destroy()
|
||||
|
||||
// Set up event handling
|
||||
session.On(func(event copilot.Event) {
|
||||
switch e := event.(type) {
|
||||
case copilot.AssistantMessageEvent:
|
||||
fmt.Printf("\n🤖 %s\n\n", e.Data.Content)
|
||||
case copilot.ToolExecutionStartEvent:
|
||||
fmt.Printf(" ⚙️ %s\n", e.Data.ToolName)
|
||||
session.On(func(event copilot.SessionEvent) {
|
||||
switch event.Type {
|
||||
case "assistant.message":
|
||||
if event.Data.Content != nil {
|
||||
fmt.Printf("\n🤖 %s\n\n", *event.Data.Content)
|
||||
}
|
||||
case "tool.execution_start":
|
||||
if event.Data.ToolName != nil {
|
||||
fmt.Printf(" ⚙️ %s\n", *event.Data.ToolName)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -180,12 +186,10 @@ The current working directory is: %s
|
||||
Finally, summarize the PR health - average age, oldest PR, and how many might be considered stale.
|
||||
`, owner, repoName)
|
||||
|
||||
if err := session.Send(copilot.MessageOptions{Prompt: prompt}); err != nil {
|
||||
if _, err := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: prompt}); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
session.WaitForIdle()
|
||||
|
||||
// Interactive loop
|
||||
fmt.Println("\n💡 Ask follow-up questions or type \"exit\" to quit.\n")
|
||||
fmt.Println("Examples:")
|
||||
@@ -209,11 +213,9 @@ The current working directory is: %s
|
||||
break
|
||||
}
|
||||
|
||||
if err := session.Send(copilot.MessageOptions{Prompt: input}); err != nil {
|
||||
if _, err := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: input}); err != nil {
|
||||
log.Printf("Error: %v", err)
|
||||
}
|
||||
|
||||
session.WaitForIdle()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user