summaryrefslogtreecommitdiff
path: root/libpanto-go/README.md
blob: 0b211377de23c579bb80dee531af53026353a935 (plain)
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
53
54
55
56
# libpanto-go

Idiomatic Go bindings for `libpanto-c` via cgo.

## Build

Build the C ABI first:

```sh
cd ..
zig build
```

Then use the Go package from this directory:

```sh
go test ./...
```

At runtime, make sure `../zig-out/lib` (or the installed equivalent) is on your platform's dynamic library path.

## Example

```go
panto.Init()
defer panto.Deinit()

agent, err := panto.NewAgent(panto.Config{
    Provider: panto.ProviderConfig{
        OpenAIChat: &panto.OpenAIChatConfig{
            APIKey: os.Getenv("OPENAI_API_KEY"),
            BaseURL: "https://api.openai.com/v1",
            Model: "gpt-4.1-mini",
        },
    },
})
if err != nil { /* handle */ }
defer agent.Close()

stream, err := agent.Run(panto.UserMessage(panto.TextBlock("hello")))
if err != nil { /* handle */ }
defer stream.Close()

for ev := range stream.Iter() {
    // ev is an Event interface; type-switch on the concrete event, or branch
    // on ev.EventType(). Breaking out of the loop is safe: the session store
    // is current at every step.
    switch ev := ev.(type) {
    case panto.ContentDeltaEvent:
        fmt.Print(ev.Delta)
    case panto.MessageCompleteEvent:
        // full message at agent.Conversation().Message(ev.MessageIndex)
    }
}
if err := stream.Err(); err != nil { /* handle */ }
```