-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (42 loc) · 953 Bytes
/
Copy pathmain.go
File metadata and controls
48 lines (42 loc) · 953 Bytes
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
43
44
45
46
47
48
// Example: streaming chat with auto-continuation.
//
// Run:
//
// ANTHROPIC_API_KEY=sk-... go run ./examples/streaming/
package main
import (
"context"
"fmt"
"os"
"github.com/GrayCodeAI/eyrie/client"
)
func main() {
c := client.Client(&client.EyrieConfig{
Provider: client.DetectProvider(),
})
messages := []client.EyrieMessage{
{Role: "user", Content: "Write a short poem about programming."},
}
sr, err := c.StreamChat(context.Background(), messages, client.ChatOptions{
Model: "claude-sonnet-4-6",
})
if err != nil {
fmt.Fprintf(os.Stderr, "stream error: %v\n", err)
os.Exit(1)
}
defer sr.Close()
for evt := range sr.Events {
switch evt.Type {
case "content":
fmt.Print(evt.Content)
case "tool_call":
if evt.ToolCall != nil {
fmt.Printf("\n[Tool call: %s]\n", evt.ToolCall.Name)
}
case "done":
fmt.Println()
case "error":
fmt.Fprintf(os.Stderr, "\nstream error: %s\n", evt.Error)
}
}
}