Documentation
¶
Index ¶
- func ExtractText(parts []ContentPart) string
- func ExtractThinking(parts []ContentPart) string
- type Agent
- type ChatCompletionProvider
- type Chunk
- type ContentPart
- type ContentPartType
- type Event
- type EventType
- type Items
- type Message
- type MessageBuilder
- type MessageMeta
- type MessageRole
- type Model
- type Provider
- type ReasoningEffort
- type RequestParameters
- type ToolCall
- type ToolConfirmation
- type ToolParameter
- type ToolPermission
- type ToolResult
- type ToolSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractText ¶
func ExtractText(parts []ContentPart) string
ExtractText returns the concatenated text of all text-type parts.
func ExtractThinking ¶
func ExtractThinking(parts []ContentPart) string
ExtractThinking returns the concatenated text of all thinking-type parts.
Types ¶
type ChatCompletionProvider ¶
type ChatCompletionProvider interface {
// CreateChatCompletion generates a chat completion response to the
// provided messages.
CreateChatCompletion(
ctx context.Context,
params RequestParameters,
messages []Message,
) (*Message, error)
// CreateChatCompletionStream streams the response via the output callback.
CreateChatCompletionStream(
ctx context.Context,
params RequestParameters,
messages []Message,
output func(Chunk),
) (*Message, error)
}
ChatCompletionProvider is the interface for LLM chat completion backends.
type ContentPart ¶
type ContentPart struct {
Type ContentPartType `json:"type"`
Text string `json:"text,omitempty"` // text and thinking parts
MIMEType string `json:"mimeType,omitempty"` // image parts (e.g. "image/png")
Data []byte `json:"data,omitempty"` // raw bytes - base64 encoded when serialized
}
ContentPart represents a single part of a message's content. Messages are composed of one or more content parts — text, thinking (reasoning), or image data. This mirrors the multi-part content model used by Anthropic and OpenAI APIs.
func BuildContentParts ¶
func BuildContentParts(content, reasoning string) []ContentPart
BuildContentParts builds a Parts slice from legacy Content and ReasoningContent strings.
func NewImagePart ¶
func NewImagePart(mimeType string, data []byte) ContentPart
NewImagePart returns an image content part with the given MIME type and raw image bytes.
func NewTextPart ¶
func NewTextPart(text string) ContentPart
NewTextPart returns a text content part.
func NewThinkingPart ¶
func NewThinkingPart(text string) ContentPart
NewThinkingPart returns a thinking/reasoning content part.
type ContentPartType ¶
type ContentPartType string
ContentPartType identifies the kind of a single content part within a message.
const ( ContentPartText ContentPartType = "text" ContentPartThinking ContentPartType = "thinking" ContentPartImage ContentPartType = "image" )
type Event ¶
type Event struct {
Type EventType
Chunk Chunk // EventChunk
Message *Message // EventResponseComplete
Error error // EventError
}
Event represents a single event emitted during a completion step. Only the fields relevant to the EventType are populated; the rest are zero-valued. Message is a pointer so that chunk events (the most frequent) carry no weight from it.
type EventType ¶
type EventType int
EventType identifies the kind of event emitted during a completion step.
type Items ¶
type Items struct {
Type string `json:"type"` // e.g. "string"
}
Items describes the element type for array tool parameters.
type Message ¶
type Message struct {
Parts []ContentPart
Role MessageRole
ToolCalls []ToolCall
ToolResults []ToolResult
Metadata MessageMeta
}
func NewMessageWithAssistant ¶
func NewMessageWithToolCalls ¶
func (*Message) TextContent ¶
TextContent returns the concatenated text of all text-type parts.
func (*Message) ThinkingContent ¶
ThinkingContent returns the concatenated text of all thinking-type parts.
type MessageBuilder ¶
type MessageBuilder struct {
// contains filtered or unexported fields
}
MessageBuilder accumulates streaming content for a message The accumulated content is presented as []ContentPart via Parts().
func NewMessageBuilder ¶
func NewMessageBuilder(role MessageRole) *MessageBuilder
NewMessageBuilder creates a builder for a message with the given role.
func (*MessageBuilder) AppendContent ¶
func (b *MessageBuilder) AppendContent(chunk string)
AppendContent appends a streaming text chunk.
func (*MessageBuilder) AppendReasoning ¶
func (b *MessageBuilder) AppendReasoning(chunk string)
AppendReasoning appends a streaming reasoning/thinking chunk.
func (*MessageBuilder) Build ¶
func (b *MessageBuilder) Build() *Message
Build finalizes the builder into a Message.
func (*MessageBuilder) InitFromParts ¶
func (b *MessageBuilder) InitFromParts(parts []ContentPart)
InitFromParts seeds the builder with existing content parts. Used when continuing to stream into an existing assistant message (prefill).
func (*MessageBuilder) Parts ¶
func (b *MessageBuilder) Parts() []ContentPart
Parts returns the accumulated content as a parts slice. The slice is constructed fresh on each call (from the internal string builders), so callers can use it directly without copying.
type MessageMeta ¶
type MessageMeta struct {
GenerationProvider *string `json:"generation_provider,omitempty"`
GenerationModel *string `json:"generation_model,omitempty"`
TimeToFirstToken *time.Duration `json:"time_to_first_token,omitempty"`
TotalDuration *time.Duration `json:"total_duration,omitempty"`
ThinkingSignature *string `json:"thinking_signature,omitempty"`
ReasoningDetails json.RawMessage `json:"reasoning_details,omitempty"` // preserved reasoning_detail blocks (OpenRouter)
}
MessageMeta contains metadata about a message's generation.
func (*MessageMeta) Scan ¶
func (m *MessageMeta) Scan(value any) error
Scan implements sql.Scanner for MessageMeta.
type MessageRole ¶
type MessageRole string
const ( MessageRoleSystem MessageRole = "system" MessageRoleUser MessageRole = "user" MessageRoleAssistant MessageRole = "assistant" MessageRoleToolCall MessageRole = "tool_call" MessageRoleToolResult MessageRole = "tool_result" )
func (MessageRole) FriendlyRole ¶
func (m MessageRole) FriendlyRole() string
FriendlyRole returns a human friendly signifier for the message's role.
func (MessageRole) IsAssistant ¶
func (m MessageRole) IsAssistant() bool
func (MessageRole) IsSystem ¶
func (m MessageRole) IsSystem() bool
func (MessageRole) IsUser ¶
func (m MessageRole) IsUser() bool
type Model ¶
Model represents a resolved model ready for making completion requests. It references its Provider for the client connection.
type Provider ¶
type Provider struct {
Name string
Display string
Client ChatCompletionProvider
Models []Model
}
Provider holds a fully initialized provider backend with its resolved models.
type ReasoningEffort ¶
type ReasoningEffort string
ReasoningEffort controls how much reasoning the model should perform.
const ( XHigh ReasoningEffort = "xhigh" High ReasoningEffort = "high" Medium ReasoningEffort = "medium" Low ReasoningEffort = "low" Minimal ReasoningEffort = "minimal" None ReasoningEffort = "none" )
type RequestParameters ¶
type RequestParameters struct {
Model *Model
Agent *Agent
Effort ReasoningEffort
Temperature float32
MaxTokens int
}
RequestParameters contains everything needed for a single completion request.
func NewRequestParameters ¶
func NewRequestParameters(model *Model, agent *Agent, effort ReasoningEffort, temperature float32, maxTokens int) RequestParameters
NewRequestParameters builds RequestParameters for a completion request.
type ToolConfirmation ¶
ToolConfirmation represents the user's decision for a single tool call. Approved must be set for every tool call (the slice length must match). When Approved is false, Reason is optionally included in the rejection message sent back to the model, giving the user a way to steer the agent.
type ToolParameter ¶
type ToolPermission ¶
type ToolPermission string
ToolPermission classifies the kind of access a tool performs.
const ( ToolPermRead ToolPermission = "read" // read-only (Read, Grep, Glob) ToolPermWrite ToolPermission = "write" // write (Write, Edit) ToolPermExec ToolPermission = "exec" // execute (Bash) )