model

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StreamEventTypeContent  = "content"
	StreamEventTypeToolCall = "tool_call"
	StreamEventTypeHandoff  = "handoff"
	StreamEventTypeDone     = "done"
	StreamEventTypeError    = "error"
)

StreamEvent types

View Source
const (
	// HandoffTypeDelegate indicates a delegation handoff to another agent
	HandoffTypeDelegate = "delegate"

	// HandoffTypeReturn indicates a return handoff to a delegator
	HandoffTypeReturn = "return"
)

Handoff types

Variables

This section is empty.

Functions

func KnownMetadataProviders

func KnownMetadataProviders() []string

func KnownPricingProviders

func KnownPricingProviders() []string

func KnownProviders

func KnownProviders() []string

func OfficialProviderModelDocsURL

func OfficialProviderModelDocsURL(provider string) (string, bool)

func OfficialProviderPricingURL

func OfficialProviderPricingURL(provider string) (string, bool)

func ProviderSupports

func ProviderSupports(provider, modelID string, cap Capability) bool

func ValidateInputPartsVision

func ValidateInputPartsVision(provider, modelID string, parts []ContentPart) error

ValidateInputPartsVision returns an error if parts contains image or document content and the given provider/model does not declare vision support. Call this before building any provider-specific request payload.

Types

type Capability

type Capability string
const (
	CapabilityAudioGeneration  Capability = "audioGeneration"
	CapabilityBatchAPI         Capability = "batchAPI"
	CapabilityCaching          Capability = "caching"
	CapabilityCodeExecution    Capability = "codeExecution"
	CapabilityDocuments        Capability = "documents"
	CapabilityFileSearch       Capability = "fileSearch"
	CapabilityFunctionCalling  Capability = "functionCalling"
	CapabilityImageGeneration  Capability = "imageGeneration"
	CapabilityLiveAPI          Capability = "liveAPI"
	CapabilityStructuredOutput Capability = "structuredOutput"
	CapabilityThinking         Capability = "thinking"
	CapabilityVision           Capability = "vision"
)

type ContentPart

type ContentPart struct {
	Type     ContentPartType
	Text     string // only for ContentPartTypeText
	MimeType string // only for ContentPartTypeDocument / ContentPartTypeImage
	Data     []byte // raw bytes — providers encode to base64 when building API request
	Name     string // original file name (informational, not sent to API)
}

ContentPart represents one part of a multimodal message input. For text parts only Text is set. For document/image parts MimeType and Data are set.

type ContentPartType

type ContentPartType string

ContentPartType identifies the kind of content in a multimodal message part.

const (
	ContentPartTypeText     ContentPartType = "text"
	ContentPartTypeDocument ContentPartType = "document" // PDF, text files
	ContentPartTypeImage    ContentPartType = "image"    // PNG, JPEG, GIF, WEBP
)

type HandoffCall

type HandoffCall struct {
	AgentName      string         `json:"agent_name"`
	Parameters     map[string]any `json:"parameters,omitempty"`
	Type           string         `json:"type,omitempty"`             // Type of handoff (delegate or return)
	ReturnToAgent  string         `json:"return_to_agent,omitempty"`  // Agent to return to after task completion
	TaskID         string         `json:"task_id,omitempty"`          // Unique identifier for the task
	IsTaskComplete bool           `json:"is_task_complete,omitempty"` // Whether the task is complete
}

HandoffCall represents a handoff call from a model

type Model

type Model interface {
	// GetResponse gets a single response from the model
	GetResponse(ctx context.Context, request *Request) (*Response, error)

	// StreamResponse streams a response from the model
	StreamResponse(ctx context.Context, request *Request) (<-chan StreamEvent, error)
}

Model defines the interface for interacting with LLMs

type ModelCapabilitySet

type ModelCapabilitySet struct {
	AudioGeneration  bool
	BatchAPI         bool
	Caching          bool
	CodeExecution    bool
	Documents        bool
	FileSearch       bool
	FunctionCalling  bool
	ImageGeneration  bool
	LiveAPI          bool
	StructuredOutput bool
	Thinking         bool
	Vision           bool
}

func CapabilitiesFor

func CapabilitiesFor(provider, modelID string) ModelCapabilitySet

type ModelMetadata

type ModelMetadata struct {
	DisplayName     string
	Description     string
	ReleaseDate     string
	ContextWindow   int
	MaxOutputTokens int
}

func GetModelMetadata

func GetModelMetadata(provider, modelID string) (ModelMetadata, bool)

type ModelPricingSpec

type ModelPricingSpec struct {
	InputCostPerMillion                  float64
	CachedInputCostPerMillion            float64
	OutputCostPerMillion                 float64
	BatchInputCostPerMillion             float64
	BatchCachedInputCostPerMillion       float64
	BatchOutputCostPerMillion            float64
	PriorityInputCostPerMillion          float64
	PriorityCachedInputCostPerMillion    float64
	PriorityOutputCostPerMillion         float64
	LongContextTriggerAtTokens           int
	LongContextInputCostPerMillion       float64
	LongContextCachedInputCostPerMillion float64
	LongContextOutputCostPerMillion      float64
	TrainingCostPerHour                  float64
	EstimatedCostPerMinute               float64
	EstimatedCostPerSecond               float64
}

func GetModelPricing

func GetModelPricing(provider, modelID string) (ModelPricingSpec, bool)

type ModelSpec

type ModelSpec struct {
	// Provider is the canonical provider ID (e.g. "anthropic", "openai").
	Provider string

	// ModelID is the exact model identifier as used in API calls (e.g. "claude-sonnet-4-6").
	ModelID string

	// Metadata holds descriptive, non-pricing information about the model.
	Metadata ModelMetadata

	// Pricing holds the cost rates for this model.
	Pricing ModelPricingSpec

	// Capabilities holds the resolved feature flags for this model.
	Capabilities ModelCapabilitySet
}

ModelSpec is the complete, unified specification for a model registered in the SDK. It aggregates metadata, pricing, and capabilities from their respective sources.

func AllModelSpecs

func AllModelSpecs() []ModelSpec

AllModelSpecs returns a deterministic flat list of all registered model specs, sorted by provider then model ID.

func GetModelSpec

func GetModelSpec(provider, modelID string) (ModelSpec, bool)

GetModelSpec returns the complete spec for an exact provider/modelID combination. Metadata and Pricing require an exact ID match; Capabilities use prefix matching. Returns false only when no metadata is registered for the given provider/modelID.

func ModelSpecsForProvider

func ModelSpecsForProvider(provider string) []ModelSpec

ModelSpecsForProvider returns all registered model specs for a given provider, sorted by model ID.

type Provider

type Provider interface {
	// GetModel returns a model by name
	GetModel(modelName string) (Model, error)
}

Provider is responsible for looking up Models by name

type ProviderSpec

type ProviderSpec struct {
	ID          string
	DisplayName string
	BaseURL     string
	DocsURL     string
	PricingURL  string
}

func AllProviders

func AllProviders() []ProviderSpec

func GetProvider

func GetProvider(id string) (ProviderSpec, bool)

type Request

type Request struct {
	SystemInstructions string
	Input              interface{}
	InputParts         []ContentPart // when set, used instead of Input for multimodal messages
	Tools              []interface{}
	OutputSchema       interface{}
	Handoffs           []interface{}
	Settings           *Settings
}

Request represents a request to a model

type Response

type Response struct {
	Content     string
	ToolCalls   []ToolCall
	HandoffCall *HandoffCall
	Usage       *Usage
}

Response represents a response from a model

type Settings

type Settings struct {
	Temperature       *float64
	TopP              *float64
	FrequencyPenalty  *float64
	PresencePenalty   *float64
	ToolChoice        *string
	ParallelToolCalls *bool
	MaxTokens         *int
}

Settings configures model-specific parameters

type StreamEvent

type StreamEvent struct {
	Type        string
	Content     string
	ToolCall    *ToolCall
	HandoffCall *HandoffCall
	Done        bool
	Error       error
	Response    *Response
}

StreamEvent represents an event in a streaming response

type ToolCall

type ToolCall struct {
	ID           string
	Name         string
	Parameters   map[string]interface{}
	RawParameter strings.Builder
}

ToolCall represents a tool call from a model

type Usage

type Usage struct {
	PromptTokens     int
	CompletionTokens int
	TotalTokens      int
}

Usage represents token usage information

Directories

Path Synopsis
providers

Jump to

Keyboard shortcuts

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