mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-23 20:05:12 +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:
@@ -19,22 +19,24 @@ You want users to be able to continue a conversation even after closing and reop
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/github/copilot-sdk/go"
|
||||
copilot "github.com/github/copilot-sdk/go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := copilot.NewClient()
|
||||
client.Start()
|
||||
ctx := context.Background()
|
||||
client := copilot.NewClient(nil)
|
||||
client.Start(ctx)
|
||||
defer client.Stop()
|
||||
|
||||
// Create session with a memorable ID
|
||||
session, _ := client.CreateSession(copilot.SessionConfig{
|
||||
session, _ := client.CreateSession(ctx, &copilot.SessionConfig{
|
||||
SessionID: "user-123-conversation",
|
||||
Model: "gpt-5",
|
||||
})
|
||||
|
||||
session.Send(copilot.MessageOptions{Prompt: "Let's discuss TypeScript generics"})
|
||||
session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Let's discuss TypeScript generics"})
|
||||
|
||||
// Session ID is preserved
|
||||
fmt.Println(session.SessionID)
|
||||
@@ -47,15 +49,16 @@ func main() {
|
||||
### Resuming a session
|
||||
|
||||
```go
|
||||
client := copilot.NewClient()
|
||||
client.Start()
|
||||
ctx := context.Background()
|
||||
client := copilot.NewClient(nil)
|
||||
client.Start(ctx)
|
||||
defer client.Stop()
|
||||
|
||||
// Resume the previous session
|
||||
session, _ := client.ResumeSession("user-123-conversation")
|
||||
session, _ := client.ResumeSession(ctx, "user-123-conversation")
|
||||
|
||||
// Previous context is restored
|
||||
session.Send(copilot.MessageOptions{Prompt: "What were we discussing?"})
|
||||
session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "What were we discussing?"})
|
||||
|
||||
session.Destroy()
|
||||
```
|
||||
@@ -63,7 +66,7 @@ session.Destroy()
|
||||
### Listing available sessions
|
||||
|
||||
```go
|
||||
sessions, _ := client.ListSessions()
|
||||
sessions, _ := client.ListSessions(ctx)
|
||||
for _, s := range sessions {
|
||||
fmt.Println("Session:", s.SessionID)
|
||||
}
|
||||
@@ -73,15 +76,17 @@ for _, s := range sessions {
|
||||
|
||||
```go
|
||||
// Remove session and all its data from disk
|
||||
client.DeleteSession("user-123-conversation")
|
||||
client.DeleteSession(ctx, "user-123-conversation")
|
||||
```
|
||||
|
||||
### Getting session history
|
||||
|
||||
```go
|
||||
messages, _ := session.GetMessages()
|
||||
messages, _ := session.GetMessages(ctx)
|
||||
for _, msg := range messages {
|
||||
fmt.Printf("[%s] %v\n", msg.Type, msg.Data)
|
||||
if msg.Data.Content != nil {
|
||||
fmt.Printf("[%s] %s\n", msg.Type, *msg.Data.Content)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user