diff options
| author | t <t@tjp.lol> | 2026-07-07 11:26:32 -0600 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-07-07 11:26:45 -0600 |
| commit | f83578fdc9264019a1a1cef8c5484a161167d3dd (patch) | |
| tree | 888f11767f944d61e5ca8eb92fa1b2dba295a4b8 /libpanto-go/README.md | |
initial commit, moved libpanto over from the pantograph repo
Diffstat (limited to 'libpanto-go/README.md')
| -rw-r--r-- | libpanto-go/README.md | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/libpanto-go/README.md b/libpanto-go/README.md new file mode 100644 index 0000000..0b21137 --- /dev/null +++ b/libpanto-go/README.md @@ -0,0 +1,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 */ } +``` |
