model

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package model defines the shared data types used across the SDK: multi-modal messages, tool calling protocol, and token usage tracking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalToolArgs

func MarshalToolArgs(args any) (string, error)

MarshalToolArgs marshals arguments to a JSON string suitable for ToolCall.Arguments.

Types

type DataRef

type DataRef struct {
	MimeType string         `json:"mime_type,omitempty"`
	Value    map[string]any `json:"value"`
}

DataRef carries structured JSON-compatible data in a message part.

type FileRef

type FileRef struct {
	URI      string `json:"uri"`
	MimeType string `json:"mime_type,omitempty"`
	Name     string `json:"name,omitempty"`
}

FileRef references a generic file (URI + MIME), e.g. for A2A-style payloads.

type MediaRef

type MediaRef struct {
	URL       string `json:"url,omitempty"`
	Base64    string `json:"base64,omitempty"`
	MediaType string `json:"media_type,omitempty"`
}

MediaRef references an image or audio asset.

type Message

type Message struct {
	Role  Role   `json:"role"`
	Parts []Part `json:"parts"`
}

Message is a multi-modal, provider-agnostic chat message.

func CloneMessages added in v0.2.3

func CloneMessages(msgs []Message) []Message

CloneMessages returns a deep copy of msgs. Nil stays nil so callers can preserve the usual JSON / len semantics.

func NewImageMessage

func NewImageMessage(role Role, text, imageURL string) Message

NewImageMessage creates a user message with text and an image URL.

func NewTextMessage

func NewTextMessage(role Role, text string) Message

NewTextMessage creates a simple text message.

func NewToolCallMessage

func NewToolCallMessage(calls []ToolCall) Message

NewToolCallMessage creates an assistant message containing tool calls.

func NewToolResultMessage

func NewToolResultMessage(results []ToolResult) Message

NewToolResultMessage creates a tool-role message with multiple results.

func (Message) Clone added in v0.2.3

func (m Message) Clone() Message

Clone returns a deep copy of m. It duplicates the Parts slice and all pointer-backed payloads so callers can safely retain or mutate the result.

func (Message) Content

func (m Message) Content() string

Content returns the concatenated text of all text parts.

func (Message) HasToolCalls

func (m Message) HasToolCalls() bool

HasToolCalls reports whether the message contains any tool calls.

func (Message) ToolCalls

func (m Message) ToolCalls() []ToolCall

ToolCalls extracts all tool-call parts.

func (Message) ToolResults

func (m Message) ToolResults() []ToolResult

ToolResults extracts all tool-result parts.

type Part

type Part struct {
	Type       PartType    `json:"type"`
	Text       string      `json:"text,omitempty"`
	Image      *MediaRef   `json:"image,omitempty"`
	Audio      *MediaRef   `json:"audio,omitempty"`
	File       *FileRef    `json:"file,omitempty"`
	Data       *DataRef    `json:"data,omitempty"`
	ToolCall   *ToolCall   `json:"tool_call,omitempty"`
	ToolResult *ToolResult `json:"tool_result,omitempty"`
}

Part is a single content unit within a Message.

func CloneParts added in v0.2.3

func CloneParts(parts []Part) []Part

CloneParts returns a deep copy of parts.

func (Part) Clone added in v0.2.3

func (p Part) Clone() Part

Clone returns a deep copy of p.

type PartType

type PartType string

PartType identifies the content type within a message Part.

const (
	PartText       PartType = "text"
	PartImage      PartType = "image"
	PartAudio      PartType = "audio"
	PartFile       PartType = "file"
	PartData       PartType = "data"
	PartToolCall   PartType = "tool_call"
	PartToolResult PartType = "tool_result"
)

type Role

type Role string

Role identifies who sent a message.

const (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
)

type StreamChunk

type StreamChunk struct {
	Role         Role       `json:"role,omitempty"`
	Content      string     `json:"content,omitempty"`
	ToolCalls    []ToolCall `json:"tool_calls,omitempty"`
	FinishReason string     `json:"finish_reason,omitempty"`
}

StreamChunk is an incremental piece of a streaming response.

type TokenUsage

type TokenUsage struct {
	InputTokens  int64 `json:"input_tokens"`
	OutputTokens int64 `json:"output_tokens"`
	TotalTokens  int64 `json:"total_tokens"`
}

TokenUsage tracks cumulative token consumption (includes TotalTokens).

func (TokenUsage) Add

func (u TokenUsage) Add(other TokenUsage) TokenUsage

Add returns a new TokenUsage that is the sum of u and other.

type ToolCall

type ToolCall struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

ToolCall represents a function call requested by the LLM.

type ToolDefinition

type ToolDefinition struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	InputSchema map[string]any `json:"input_schema"`
}

ToolDefinition describes a tool for LLM function-calling.

type ToolResult

type ToolResult struct {
	ToolCallID string `json:"tool_call_id"`
	Content    string `json:"content"`
	IsError    bool   `json:"is_error,omitempty"`
}

ToolResult carries the result of a tool execution back to the LLM.

type Usage

type Usage struct {
	InputTokens  int64 `json:"input_tokens"`
	OutputTokens int64 `json:"output_tokens"`
}

Usage represents raw token usage from a single LLM call (Provider layer).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL