-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (40 loc) · 1.05 KB
/
Copy pathmain.go
File metadata and controls
46 lines (40 loc) · 1.05 KB
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
// Example: multi-provider fallback chain.
//
// Tries Anthropic first, falls back to OpenAI, then Gemini.
//
// Run:
//
// ANTHROPIC_API_KEY=sk-ant-... OPENAI_API_KEY=sk-... go run ./examples/multi-provider/
package main
import (
"context"
"fmt"
"os"
"github.com/GrayCodeAI/eyrie/client"
)
func main() {
primary := client.Client(&client.EyrieConfig{
Provider: "anthropic",
})
secondary := client.Client(&client.EyrieConfig{
Provider: "openai",
})
messages := []client.EyrieMessage{
{Role: "user", Content: "Explain what a fallback chain is in one sentence."},
}
// Try primary first, fall back to secondary on failure.
resp, err := primary.Chat(context.Background(), messages, client.ChatOptions{
Model: "claude-sonnet-4-6",
})
if err != nil {
fmt.Fprintf(os.Stderr, "primary failed, trying secondary: %v\n", err)
resp, err = secondary.Chat(context.Background(), messages, client.ChatOptions{
Model: "gpt-4o",
})
if err != nil {
fmt.Fprintf(os.Stderr, "all providers failed: %v\n", err)
os.Exit(1)
}
}
fmt.Println(resp.Content)
}