Go library for streaming LLM interactions with tool calling support.
Handles streaming, multi-step tool calls, and user approval flows — so you don't have to.
go get github.com/x2d7/interludeSee examples/ for usage examples.
client:= openai.OpenAIClient{
Endpoint: "https://openrouter.ai/api/v1",
APIKey: os.Getenv("API_KEY"),
Model: "gpt-4o",
}
c:= chat.Chat{
Messages: chat.NewMessages(),
}
forevent:=rangec.SendUserStream(ctx, &client, "Hello!") {
switchv:=event.(type) {
case chat.EventToken:
fmt.Print(v.Content)
case chat.EventError:
log.Fatal(v.Error)
}
}toolList:=tools.NewTools()
tool, _:=tools.NewTool("get_weather", "Returns weather for a city", func(inputstruct {
Citystring`json:"city"`
}) (string, error) {
return"Sunny, 22°C", nil
})
toolList.Add(tool)
c:= chat.Chat{
Messages: chat.NewMessages(),
Tools: toolList,
}
forevent:=rangec.SendUserStream(ctx, &client, "What's the weather in Berlin?") {
switchv:=event.(type) {
case chat.EventToken:
fmt.Print(v.Content)
case chat.EventToolCall:
v.Resolve(true) // approve the callcase chat.EventCompletionEnded:
fmt.Println()
}
}Tool input schema is generated automatically from your struct using jsonschema tags.
- OpenAI-compatible APIs (OpenAI, OpenRouter, etc.)
MIT