model

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	// Stream sends a request and returns a channel of Chunks.
	// The implementation MUST close the channel after the stream ends or errors.
	// The implementation MUST respect context cancellation.
	Stream(ctx context.Context, req Request) (<-chan Chunk, error)

	// Name returns a human-readable identifier for this adapter,
	// e.g. "openai", "anthropic", "gemini".
	Name() string
}

Adapter translates between the canonical Request/Chunk types and a specific model provider's wire format.

type Chunk

type Chunk struct {
	Type             ChunkType      `json:"type"`
	Text             string         `json:"text,omitempty"`
	ReasoningContent string         `json:"reasoning_content,omitempty"`
	ToolCall         *ToolCallDelta `json:"tool_call,omitempty"`
	Finish           *FinishReason  `json:"finish,omitempty"`
	Usage            *Usage         `json:"usage,omitempty"`
	Err              error          `json:"-"`
}

Chunk is a single item from the adapter's stream channel.

type ChunkType

type ChunkType string

ChunkType discriminates the kind of content in a stream chunk.

const (
	ChunkTypeText          ChunkType = "text"
	ChunkTypeReasoning     ChunkType = "reasoning"
	ChunkTypeToolCallDelta ChunkType = "tool_call_delta"
	ChunkTypeFinish        ChunkType = "finish"
	ChunkTypeError         ChunkType = "error"
	ChunkTypeUsage         ChunkType = "usage"
)

type FinishReason

type FinishReason struct {
	Reason string `json:"reason"`
}

FinishReason is the terminal state of a generation.

type Message

type Message struct {
	Role       MessageRole `json:"role"`
	Content    string      `json:"content"`
	ToolCallID string      `json:"tool_call_id,omitempty"`
	ToolCalls  []ToolCall  `json:"tool_calls,omitempty"`
}

Message is a single turn in the conversation history.

type MessageRole

type MessageRole string

MessageRole distinguishes system, user, assistant, and tool messages.

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

type Request

type Request struct {
	Model     string    `json:"model"`
	Messages  []Message `json:"messages"`
	Tools     []ToolDef `json:"tools,omitempty"`
	Stream    bool      `json:"stream"`
	MaxTokens int       `json:"max_tokens,omitempty"`
}

Request is the canonical request sent to the model adapter.

type ToolCall

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

ToolCall represents a tool invocation from the model.

type ToolCallDelta

type ToolCallDelta struct {
	ID        string          `json:"id,omitempty"`
	Index     int             `json:"index"`
	Name      string          `json:"name,omitempty"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
}

ToolCallDelta is a partial or complete tool call from the stream.

type ToolDef

type ToolDef struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	InputSchema json.RawMessage `json:"input_schema"`
}

ToolDef is a JSON-schema tool definition sent to the model.

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens,omitempty"`
	OutputTokens int `json:"output_tokens,omitempty"`
}

Usage reports token consumption when available.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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