-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (41 loc) · 1.11 KB
/
main.go
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
49
50
51
52
package main
import (
"context"
"fmt"
"os"
"github.com/rhettg/agent"
"github.com/rhettg/agent/provider/openaichat"
"github.com/sashabaranov/go-openai"
)
func main() {
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
p := openaichat.New(client, "gpt-4-vision-preview",
// By default, gpt-4-vision-preview is configured with a very small
// default max tokens. Make it bigger.
openaichat.WithMaxTokens(1024),
)
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "usage: %s <image file>\n", os.Args[0])
os.Exit(1)
}
a := agent.New(p)
imgName := os.Args[1]
imgData, err := os.ReadFile(imgName)
if err != nil {
fmt.Fprintf(os.Stderr, "error reading image file: %v\n", err)
os.Exit(1)
}
im := agent.NewImageMessage(agent.RoleUser, "please explain", imgName, imgData)
a.AddMessage(im)
m, err := a.Step(context.Background())
if err != nil {
fmt.Fprintf(os.Stderr, "error handling message: %v\n", err)
os.Exit(1)
}
content, err := m.Content(context.Background())
if err != nil {
fmt.Fprintf(os.Stderr, "error getting message content: %v\n", err)
os.Exit(1)
}
fmt.Println(content)
}