Documentation
¶
Overview ¶
Package core provides the Iris SDK client and types.
Package core provides the Iris SDK client and types for interacting with AI providers.
Package core provides the Iris SDK client and types.
Index ¶
- Variables
- type APIEndpoint
- type BuiltInTool
- type ChatBuilder
- func (b *ChatBuilder) Assistant(s string) *ChatBuilder
- func (b *ChatBuilder) BuiltInTool(toolType string) *ChatBuilder
- func (b *ChatBuilder) CodeInterpreter() *ChatBuilder
- func (b *ChatBuilder) ContinueFrom(responseID string) *ChatBuilder
- func (b *ChatBuilder) FileSearch(vectorStoreIDs ...string) *ChatBuilder
- func (b *ChatBuilder) GetResponse(ctx context.Context) (*ChatResponse, error)
- func (b *ChatBuilder) Instructions(s string) *ChatBuilder
- func (b *ChatBuilder) MaxTokens(n int) *ChatBuilder
- func (b *ChatBuilder) ReasoningEffort(level ReasoningEffort) *ChatBuilder
- func (b *ChatBuilder) Stream(ctx context.Context) (*ChatStream, error)
- func (b *ChatBuilder) System(s string) *ChatBuilder
- func (b *ChatBuilder) Temperature(v float32) *ChatBuilder
- func (b *ChatBuilder) Tools(ts ...Tool) *ChatBuilder
- func (b *ChatBuilder) Truncation(mode string) *ChatBuilder
- func (b *ChatBuilder) User(s string) *ChatBuilder
- func (b *ChatBuilder) UserMultimodal() *MessageBuilder
- func (b *ChatBuilder) UserWithFileID(text, fileID string) *ChatBuilder
- func (b *ChatBuilder) UserWithFileURL(text, fileURL string) *ChatBuilder
- func (b *ChatBuilder) UserWithImageFileID(text, fileID string) *ChatBuilder
- func (b *ChatBuilder) UserWithImageURL(text, imageURL string) *ChatBuilder
- func (b *ChatBuilder) WebSearch() *ChatBuilder
- type ChatChunk
- type ChatRequest
- type ChatResponse
- type ChatStream
- type Client
- type ClientOption
- type ContentPart
- type ContextualizedEmbeddingProvider
- type ContextualizedEmbeddingRequest
- type ContextualizedEmbeddingResponse
- type EmbeddingInput
- type EmbeddingProvider
- type EmbeddingRequest
- type EmbeddingResponse
- type EmbeddingUsage
- type EmbeddingVector
- type EncodingFormat
- type Feature
- type FileSearchResources
- type ImageAction
- type ImageBackground
- type ImageChunk
- type ImageData
- type ImageDetail
- type ImageEditRequest
- type ImageFormat
- type ImageGenerateRequest
- type ImageGenerator
- type ImageInput
- type ImageInputFidelity
- type ImageQuality
- type ImageResponse
- type ImageSize
- type ImageStream
- type ImageUsage
- type InputFile
- type InputImage
- type InputText
- type InputType
- type Message
- type MessageBuilder
- func (m *MessageBuilder) Done() *ChatBuilder
- func (m *MessageBuilder) FileBase64(filename, base64Data string) *MessageBuilder
- func (m *MessageBuilder) FileID(fileID string) *MessageBuilder
- func (m *MessageBuilder) FileURL(url string) *MessageBuilder
- func (m *MessageBuilder) ImageFileID(fileID string) *MessageBuilder
- func (m *MessageBuilder) ImageFileIDWithDetail(fileID string, detail ImageDetail) *MessageBuilder
- func (m *MessageBuilder) ImageURL(url string) *MessageBuilder
- func (m *MessageBuilder) ImageURLWithDetail(url string, detail ImageDetail) *MessageBuilder
- func (m *MessageBuilder) Text(s string) *MessageBuilder
- type ModelID
- type ModelInfo
- type NoopTelemetryHook
- type OutputDType
- type Provider
- type ProviderError
- type ReasoningEffort
- type ReasoningOutput
- type RequestEndEvent
- type RequestStartEvent
- type RerankRequest
- type RerankResponse
- type RerankResult
- type RerankUsage
- type RerankerProvider
- type RetryConfig
- type RetryPolicy
- type Role
- type TelemetryHook
- type TokenUsage
- type Tool
- type ToolCall
- type ToolResources
Constants ¶
This section is empty.
Variables ¶
var ( ErrRateLimited = errors.New("rate limited") ErrBadRequest = errors.New("bad request") ErrNotFound = errors.New("not found") ErrServer = errors.New("server error") ErrNetwork = errors.New("network error") ErrDecode = errors.New("decode error") ErrNotSupported = errors.New("operation not supported") )
Sentinel errors for classification.
var ( ErrModelRequired = errors.New("model required") ErrNoMessages = errors.New("no messages") )
Validation errors.
Functions ¶
This section is empty.
Types ¶
type APIEndpoint ¶
type APIEndpoint string
APIEndpoint represents which API endpoint a model uses.
const ( // APIEndpointCompletions is the Chat Completions API (default for older models). APIEndpointCompletions APIEndpoint = "completions" // APIEndpointResponses is the Responses API (for newer models like GPT-5.x). APIEndpointResponses APIEndpoint = "responses" )
type BuiltInTool ¶
type BuiltInTool struct {
Type string `json:"type"` // "web_search", "file_search", "code_interpreter"
}
BuiltInTool represents a built-in tool available in the Responses API.
type ChatBuilder ¶
type ChatBuilder struct {
// contains filtered or unexported fields
}
ChatBuilder provides a fluent API for building chat requests. ChatBuilder is NOT thread-safe and should not be shared across goroutines.
func (*ChatBuilder) Assistant ¶
func (b *ChatBuilder) Assistant(s string) *ChatBuilder
Assistant appends an assistant message.
func (*ChatBuilder) BuiltInTool ¶
func (b *ChatBuilder) BuiltInTool(toolType string) *ChatBuilder
BuiltInTool adds a built-in tool to the request.
func (*ChatBuilder) CodeInterpreter ¶
func (b *ChatBuilder) CodeInterpreter() *ChatBuilder
CodeInterpreter adds the code_interpreter built-in tool.
func (*ChatBuilder) ContinueFrom ¶
func (b *ChatBuilder) ContinueFrom(responseID string) *ChatBuilder
ContinueFrom chains this request to a previous response.
func (*ChatBuilder) FileSearch ¶
func (b *ChatBuilder) FileSearch(vectorStoreIDs ...string) *ChatBuilder
FileSearch adds the file_search built-in tool with optional vector store IDs.
func (*ChatBuilder) GetResponse ¶
func (b *ChatBuilder) GetResponse(ctx context.Context) (*ChatResponse, error)
GetResponse executes the chat request and returns the response. It applies validation, telemetry, and retry logic.
func (*ChatBuilder) Instructions ¶
func (b *ChatBuilder) Instructions(s string) *ChatBuilder
Instructions sets the system instructions (Responses API style). For Chat Completions API, this is equivalent to adding a system message.
func (*ChatBuilder) MaxTokens ¶
func (b *ChatBuilder) MaxTokens(n int) *ChatBuilder
MaxTokens sets the maximum tokens parameter.
func (*ChatBuilder) ReasoningEffort ¶
func (b *ChatBuilder) ReasoningEffort(level ReasoningEffort) *ChatBuilder
ReasoningEffort sets the reasoning effort level for models that support it.
func (*ChatBuilder) Stream ¶
func (b *ChatBuilder) Stream(ctx context.Context) (*ChatStream, error)
Stream executes the chat request and returns a streaming response. It applies validation and telemetry.
func (*ChatBuilder) System ¶
func (b *ChatBuilder) System(s string) *ChatBuilder
System appends a system message.
func (*ChatBuilder) Temperature ¶
func (b *ChatBuilder) Temperature(v float32) *ChatBuilder
Temperature sets the temperature parameter.
func (*ChatBuilder) Tools ¶
func (b *ChatBuilder) Tools(ts ...Tool) *ChatBuilder
Tools sets the tools available for the request.
func (*ChatBuilder) Truncation ¶
func (b *ChatBuilder) Truncation(mode string) *ChatBuilder
Truncation sets the truncation mode for the request.
func (*ChatBuilder) User ¶
func (b *ChatBuilder) User(s string) *ChatBuilder
User appends a user message.
func (*ChatBuilder) UserMultimodal ¶
func (b *ChatBuilder) UserMultimodal() *MessageBuilder
UserMultimodal starts building a multimodal user message.
func (*ChatBuilder) UserWithFileID ¶
func (b *ChatBuilder) UserWithFileID(text, fileID string) *ChatBuilder
UserWithFileID adds a user message with text and a file ID. This is a convenience method for document analysis with uploaded files.
func (*ChatBuilder) UserWithFileURL ¶
func (b *ChatBuilder) UserWithFileURL(text, fileURL string) *ChatBuilder
UserWithFileURL adds a user message with text and a file URL. This is a convenience method for document analysis use cases.
func (*ChatBuilder) UserWithImageFileID ¶
func (b *ChatBuilder) UserWithImageFileID(text, fileID string) *ChatBuilder
UserWithImageFileID adds a user message with text and an image file ID. This is a convenience method for vision use cases with uploaded files.
func (*ChatBuilder) UserWithImageURL ¶
func (b *ChatBuilder) UserWithImageURL(text, imageURL string) *ChatBuilder
UserWithImageURL adds a user message with text and an image URL. This is a convenience method for common vision use cases.
func (*ChatBuilder) WebSearch ¶
func (b *ChatBuilder) WebSearch() *ChatBuilder
WebSearch adds the web_search built-in tool.
type ChatChunk ¶
type ChatChunk struct {
Delta string `json:"delta"`
}
ChatChunk represents an incremental streaming response. Delta contains incremental assistant text.
type ChatRequest ¶
type ChatRequest struct {
Model ModelID `json:"model"`
Messages []Message `json:"messages"`
Temperature *float32 `json:"temperature,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
Tools []Tool `json:"-"` // Tools are handled separately by providers
// Responses API fields (ignored for Chat Completions API)
Instructions string `json:"instructions,omitempty"`
ReasoningEffort ReasoningEffort `json:"reasoning_effort,omitempty"`
BuiltInTools []BuiltInTool `json:"builtin_tools,omitempty"`
PreviousResponseID string `json:"previous_response_id,omitempty"`
Truncation string `json:"truncation,omitempty"`
ToolResources *ToolResources `json:"tool_resources,omitempty"`
}
ChatRequest represents a request to a chat model.
type ChatResponse ¶
type ChatResponse struct {
ID string `json:"id"`
Model ModelID `json:"model"`
Output string `json:"output"`
Usage TokenUsage `json:"usage"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
// Responses API fields
Reasoning *ReasoningOutput `json:"reasoning,omitempty"`
Status string `json:"status,omitempty"`
}
ChatResponse represents a response from a chat model. For providers returning multiple choices, v0.1 uses only the first choice.
func DrainStream ¶
func DrainStream(ctx context.Context, s *ChatStream) (*ChatResponse, error)
DrainStream accumulates all deltas and returns the final ChatResponse. Blocks until stream completes or context cancels.
Behavior:
- Read all chunks from Ch, accumulating Delta into output string
- Check Err channel for any errors
- Wait for Final to get complete response with usage/tool calls
- If Final includes Output, use it; otherwise use accumulated deltas
- Handle context cancellation gracefully
type ChatStream ¶
type ChatStream struct {
// Ch emits text deltas in order. Closed when stream ends.
Ch <-chan ChatChunk
// Err emits at most one error. MUST be closed when stream ends.
// If error occurs after setup, send on Err then close all channels.
Err <-chan error
// Final sent exactly once (or zero if setup fails) after stream completion.
// Includes usage and tool calls if available.
// Providers may send partial ChatResponse with Output empty.
Final <-chan *ChatResponse
}
ChatStream represents a streaming response from a provider.
Channel Rules:
- Providers MUST close Ch, Err, and Final when finished
- On context cancellation, providers MUST terminate promptly and close channels
- Err channel emits at most one error
- Final channel emits exactly once on success (or zero times on setup failure)
- If providers cannot compute Usage for streaming, they MAY leave it zeroed
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main entry point for interacting with LLM providers. Client is safe for concurrent use.
func NewClient ¶
func NewClient(p Provider, opts ...ClientOption) *Client
NewClient creates a new Client with the given provider and options.
func (*Client) Chat ¶
func (c *Client) Chat(model ModelID) *ChatBuilder
Chat returns a ChatBuilder for constructing and executing a chat request.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client.
func WithRetryPolicy ¶
func WithRetryPolicy(r RetryPolicy) ClientOption
WithRetryPolicy sets the retry policy for the client.
func WithTelemetry ¶
func WithTelemetry(h TelemetryHook) ClientOption
WithTelemetry sets the telemetry hook for the client.
type ContentPart ¶
type ContentPart interface {
// ContentType returns the type identifier for this content part.
ContentType() string
}
ContentPart represents a part of multimodal content in a message. Types implementing this interface can be used in multimodal messages with the OpenAI Responses API.
type ContextualizedEmbeddingProvider ¶
type ContextualizedEmbeddingProvider interface {
// CreateContextualizedEmbeddings generates context-aware embeddings for document chunks.
// Each inner slice in Inputs represents chunks from a single document.
CreateContextualizedEmbeddings(ctx context.Context, req *ContextualizedEmbeddingRequest) (*ContextualizedEmbeddingResponse, error)
}
ContextualizedEmbeddingProvider is an optional interface for providers that support context-aware chunk embeddings. These embeddings encode not just the local content of each chunk, but also context from surrounding chunks in the same document.
type ContextualizedEmbeddingRequest ¶
type ContextualizedEmbeddingRequest struct {
// Model specifies the embedding model to use.
Model ModelID `json:"model"`
// Inputs is a list of documents, where each document is a list of chunks.
// Chunks within the same document are encoded with awareness of each other.
Inputs [][]string `json:"inputs"`
// InputType specifies whether inputs are queries or documents.
InputType InputType `json:"input_type,omitempty"`
// OutputDimension specifies the number of dimensions for output embeddings.
OutputDimension *int `json:"output_dimension,omitempty"`
// OutputDType specifies the data type for embeddings (float, int8, etc.).
OutputDType OutputDType `json:"output_dtype,omitempty"`
// EncodingFormat specifies the encoding format (float array or base64).
EncodingFormat EncodingFormat `json:"encoding_format,omitempty"`
}
ContextualizedEmbeddingRequest represents a request to generate contextualized embeddings.
type ContextualizedEmbeddingResponse ¶
type ContextualizedEmbeddingResponse struct {
// Embeddings contains the vectors grouped by document, then by chunk.
// embeddings[i][j] is the embedding for chunk j of document i.
Embeddings [][]EmbeddingVector `json:"embeddings"`
// Model is the model that generated the embeddings.
Model ModelID `json:"model"`
// Usage contains token consumption information.
Usage EmbeddingUsage `json:"usage"`
}
ContextualizedEmbeddingResponse contains the generated contextualized embeddings.
type EmbeddingInput ¶
type EmbeddingInput struct {
Text string `json:"text"`
ID string `json:"id,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
EmbeddingInput represents a single text to embed with optional metadata.
type EmbeddingProvider ¶
type EmbeddingProvider interface {
// CreateEmbeddings generates embeddings for the given input texts.
CreateEmbeddings(ctx context.Context, req *EmbeddingRequest) (*EmbeddingResponse, error)
}
EmbeddingProvider is an optional interface for providers that support embeddings.
type EmbeddingRequest ¶
type EmbeddingRequest struct {
Model ModelID `json:"model"`
Input []EmbeddingInput `json:"input"`
EncodingFormat EncodingFormat `json:"encoding_format,omitempty"`
Dimensions *int `json:"dimensions,omitempty"`
User string `json:"user,omitempty"`
InputType InputType `json:"input_type,omitempty"`
OutputDType OutputDType `json:"output_dtype,omitempty"`
Truncation *bool `json:"truncation,omitempty"`
}
EmbeddingRequest represents a request to generate embeddings.
type EmbeddingResponse ¶
type EmbeddingResponse struct {
Vectors []EmbeddingVector `json:"vectors"`
Model ModelID `json:"model"`
Usage EmbeddingUsage `json:"usage"`
}
EmbeddingResponse contains the generated embeddings.
type EmbeddingUsage ¶
type EmbeddingUsage struct {
PromptTokens int `json:"prompt_tokens"`
TotalTokens int `json:"total_tokens"`
}
EmbeddingUsage tracks token consumption for embeddings.
type EmbeddingVector ¶
type EmbeddingVector struct {
Index int `json:"index"`
ID string `json:"id,omitempty"`
Vector []float32 `json:"vector,omitempty"`
VectorB64 string `json:"vector_b64,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
EmbeddingVector represents a single embedding result.
type EncodingFormat ¶
type EncodingFormat string
EncodingFormat specifies the embedding output format.
const ( // EncodingFormatFloat returns embeddings as float arrays. EncodingFormatFloat EncodingFormat = "float" // EncodingFormatBase64 returns embeddings as base64-encoded strings. EncodingFormatBase64 EncodingFormat = "base64" )
type Feature ¶
type Feature string
Feature represents a capability that a provider may support.
const ( FeatureChat Feature = "chat" FeatureChatStreaming Feature = "chat_streaming" FeatureToolCalling Feature = "tool_calling" FeatureReasoning Feature = "reasoning" FeatureBuiltInTools Feature = "builtin_tools" FeatureResponseChain Feature = "response_chain" FeatureEmbeddings Feature = "embeddings" FeatureContextualizedEmbeddings Feature = "contextualized_embeddings" FeatureReranking Feature = "reranking" )
const FeatureImageGeneration Feature = "image_generation"
FeatureImageGeneration indicates support for image generation.
type FileSearchResources ¶
type FileSearchResources struct {
VectorStoreIDs []string `json:"vector_store_ids"`
}
FileSearchResources contains vector store IDs for file search.
type ImageAction ¶
type ImageAction string
ImageAction represents the action to take (for Responses API).
const ( ImageActionAuto ImageAction = "auto" ImageActionGenerate ImageAction = "generate" ImageActionEdit ImageAction = "edit" )
type ImageBackground ¶
type ImageBackground string
ImageBackground represents the background style.
const ( ImageBackgroundOpaque ImageBackground = "opaque" ImageBackgroundTransparent ImageBackground = "transparent" ImageBackgroundAuto ImageBackground = "auto" )
type ImageChunk ¶
type ImageChunk struct {
PartialImageIndex int `json:"partial_image_index"`
B64JSON string `json:"b64_json"`
}
ImageChunk represents an incremental streaming response for images.
type ImageData ¶
type ImageData struct {
B64JSON string `json:"b64_json,omitempty"`
URL string `json:"url,omitempty"`
RevisedPrompt string `json:"revised_prompt,omitempty"`
}
ImageData represents a single generated image.
type ImageDetail ¶
type ImageDetail string
ImageDetail specifies the level of detail for image processing.
const ( // ImageDetailAuto lets the model decide the appropriate detail level. ImageDetailAuto ImageDetail = "auto" // ImageDetailLow uses fewer tokens for faster processing. ImageDetailLow ImageDetail = "low" // ImageDetailHigh uses more tokens for detailed analysis. ImageDetailHigh ImageDetail = "high" )
type ImageEditRequest ¶
type ImageEditRequest struct {
Model ModelID `json:"model"`
Prompt string `json:"prompt"`
// Image inputs - at least one required
Images []ImageInput `json:"-"` // Handled separately for multipart
// Optional mask for inpainting
Mask *ImageInput `json:"-"`
// Optional parameters
N int `json:"n,omitempty"`
Size ImageSize `json:"size,omitempty"`
Quality ImageQuality `json:"quality,omitempty"`
Format ImageFormat `json:"output_format,omitempty"`
Compression *int `json:"output_compression,omitempty"`
Background ImageBackground `json:"background,omitempty"`
InputFidelity ImageInputFidelity `json:"input_fidelity,omitempty"`
User string `json:"user,omitempty"`
}
ImageEditRequest represents a request to edit images.
type ImageFormat ¶
type ImageFormat string
ImageFormat represents the output file format.
const ( ImageFormatPNG ImageFormat = "png" ImageFormatJPEG ImageFormat = "jpeg" ImageFormatWebP ImageFormat = "webp" )
func (ImageFormat) IsValid ¶
func (f ImageFormat) IsValid() bool
IsValid reports whether the image format is a recognized value.
type ImageGenerateRequest ¶
type ImageGenerateRequest struct {
Model ModelID `json:"model"`
Prompt string `json:"prompt"`
// Optional parameters
N int `json:"n,omitempty"` // Number of images to generate (default 1)
Size ImageSize `json:"size,omitempty"` // Image dimensions
Quality ImageQuality `json:"quality,omitempty"` // Rendering quality
Format ImageFormat `json:"output_format,omitempty"` // Output format
Compression *int `json:"output_compression,omitempty"` // 0-100 for jpeg/webp
Background ImageBackground `json:"background,omitempty"` // Transparency setting
Moderation string `json:"moderation,omitempty"` // "auto" or "low"
User string `json:"user,omitempty"` // User identifier
ResponseFormat string `json:"response_format,omitempty"` // "b64_json" or "url"
PartialImages int `json:"partial_images,omitempty"` // For streaming (0-3)
}
ImageGenerateRequest represents a request to generate images.
type ImageGenerator ¶
type ImageGenerator interface {
// GenerateImage generates images from a text prompt.
GenerateImage(ctx context.Context, req *ImageGenerateRequest) (*ImageResponse, error)
// EditImage edits existing images using a prompt and optional mask.
EditImage(ctx context.Context, req *ImageEditRequest) (*ImageResponse, error)
// StreamImage generates images with streaming partial results.
// Not all providers support streaming.
StreamImage(ctx context.Context, req *ImageGenerateRequest) (*ImageStream, error)
}
ImageGenerator is an optional interface for providers that support image generation.
type ImageInput ¶
type ImageInput struct {
// One of these must be set
Data []byte // Raw image bytes
Base64 string // Base64-encoded image
URL string // URL to fetch image from (Responses API only)
FileID string // File ID from Files API (Responses API only)
Filename string // Optional filename hint
}
ImageInput represents an input image for editing.
func (ImageInput) GetBytes ¶
func (i ImageInput) GetBytes() ([]byte, error)
GetBytes returns the image data as bytes.
type ImageInputFidelity ¶
type ImageInputFidelity string
ImageInputFidelity represents the input image preservation level.
const ( ImageInputFidelityLow ImageInputFidelity = "low" ImageInputFidelityHigh ImageInputFidelity = "high" )
type ImageQuality ¶
type ImageQuality string
ImageQuality represents the rendering quality level.
const ( ImageQualityLow ImageQuality = "low" ImageQualityMedium ImageQuality = "medium" ImageQualityHigh ImageQuality = "high" ImageQualityAuto ImageQuality = "auto" )
func (ImageQuality) IsValid ¶
func (q ImageQuality) IsValid() bool
IsValid reports whether the image quality is a recognized value.
type ImageResponse ¶
type ImageResponse struct {
Created int64 `json:"created"`
Data []ImageData `json:"data"`
Usage *ImageUsage `json:"usage,omitempty"`
}
ImageResponse represents a response containing generated images.
type ImageStream ¶
type ImageStream struct {
Ch <-chan ImageChunk // Partial images
Err <-chan error // At most one error
Final <-chan *ImageResponse // Complete response
}
ImageStream represents a streaming image generation response.
type ImageUsage ¶
type ImageUsage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
TotalTokens int `json:"total_tokens"`
}
ImageUsage tracks token usage for image generation.
type InputFile ¶
type InputFile struct {
// FileID is a file ID from the Files API.
FileID string
// FileURL is an HTTPS URL to the file.
FileURL string
// FileData contains base64-encoded file bytes.
FileData string
// Filename is the recommended filename when using FileData.
Filename string
}
InputFile represents file content in a multimodal message.
func (InputFile) ContentType ¶
ContentType returns the type identifier for InputFile.
type InputImage ¶
type InputImage struct {
// ImageURL is an HTTPS URL or data URL (data:image/jpeg;base64,...).
ImageURL string
// FileID is a file ID from the Files API.
FileID string
// Detail specifies the level of detail for image processing.
Detail ImageDetail
}
InputImage represents image content in a multimodal message.
func (InputImage) ContentType ¶
func (i InputImage) ContentType() string
ContentType returns the type identifier for InputImage.
type InputText ¶
type InputText struct {
// Text is the text content.
Text string
}
InputText represents text content in a multimodal message.
func (InputText) ContentType ¶
ContentType returns the type identifier for InputText.
type InputType ¶
type InputType string
InputType specifies the type of input for retrieval optimization.
const ( // InputTypeNone uses default embedding without retrieval optimization. InputTypeNone InputType = "" // InputTypeQuery optimizes embeddings for search queries. InputTypeQuery InputType = "query" // InputTypeDocument optimizes embeddings for documents being searched. InputTypeDocument InputType = "document" )
type Message ¶
type Message struct {
Role Role `json:"role"`
Content string `json:"content,omitempty"`
Parts []ContentPart `json:"-"` // Multimodal content parts (Responses API only)
}
Message represents a single message in a conversation. For simple text messages, use Content. For multimodal messages, use Parts. If Parts is non-empty, Content is ignored.
type MessageBuilder ¶
type MessageBuilder struct {
// contains filtered or unexported fields
}
MessageBuilder provides a fluent API for building multimodal messages.
func (*MessageBuilder) Done ¶
func (m *MessageBuilder) Done() *ChatBuilder
Done completes the message and returns to the ChatBuilder.
func (*MessageBuilder) FileBase64 ¶
func (m *MessageBuilder) FileBase64(filename, base64Data string) *MessageBuilder
FileBase64 adds a file with base64-encoded content.
func (*MessageBuilder) FileID ¶
func (m *MessageBuilder) FileID(fileID string) *MessageBuilder
FileID adds a file by file ID from the Files API.
func (*MessageBuilder) FileURL ¶
func (m *MessageBuilder) FileURL(url string) *MessageBuilder
FileURL adds a file by URL.
func (*MessageBuilder) ImageFileID ¶
func (m *MessageBuilder) ImageFileID(fileID string) *MessageBuilder
ImageFileID adds an image by file ID from the Files API.
func (*MessageBuilder) ImageFileIDWithDetail ¶
func (m *MessageBuilder) ImageFileIDWithDetail(fileID string, detail ImageDetail) *MessageBuilder
ImageFileIDWithDetail adds an image by file ID with a specific detail level.
func (*MessageBuilder) ImageURL ¶
func (m *MessageBuilder) ImageURL(url string) *MessageBuilder
ImageURL adds an image by URL (HTTPS or data URL).
func (*MessageBuilder) ImageURLWithDetail ¶
func (m *MessageBuilder) ImageURLWithDetail(url string, detail ImageDetail) *MessageBuilder
ImageURLWithDetail adds an image by URL with a specific detail level.
func (*MessageBuilder) Text ¶
func (m *MessageBuilder) Text(s string) *MessageBuilder
Text adds a text content part to the message.
type ModelID ¶
type ModelID string
ModelID is a string identifier for a model. Using string avoids coupling to provider-specific enums.
type ModelInfo ¶
type ModelInfo struct {
ID ModelID `json:"id"`
DisplayName string `json:"display_name"`
Capabilities []Feature `json:"capabilities"`
APIEndpoint APIEndpoint `json:"api_endpoint,omitempty"` // defaults to completions
}
ModelInfo describes a model available from a provider.
func (ModelInfo) GetAPIEndpoint ¶
func (m ModelInfo) GetAPIEndpoint() APIEndpoint
GetAPIEndpoint returns the API endpoint for the model, defaulting to completions.
func (ModelInfo) HasCapability ¶
HasCapability reports whether the model supports the given feature.
type NoopTelemetryHook ¶
type NoopTelemetryHook struct{}
NoopTelemetryHook is a no-op implementation of TelemetryHook. Use this as a default when no telemetry is configured.
func (NoopTelemetryHook) OnRequestEnd ¶
func (NoopTelemetryHook) OnRequestEnd(RequestEndEvent)
OnRequestEnd does nothing.
func (NoopTelemetryHook) OnRequestStart ¶
func (NoopTelemetryHook) OnRequestStart(RequestStartEvent)
OnRequestStart does nothing.
type OutputDType ¶
type OutputDType string
OutputDType specifies the data type for embedding vectors.
const ( // OutputDTypeFloat returns 32-bit floating point numbers (default). OutputDTypeFloat OutputDType = "float" // OutputDTypeInt8 returns 8-bit signed integers (-128 to 127). OutputDTypeInt8 OutputDType = "int8" // OutputDTypeUint8 returns 8-bit unsigned integers (0 to 255). OutputDTypeUint8 OutputDType = "uint8" // OutputDTypeBinary returns bit-packed signed integers. OutputDTypeBinary OutputDType = "binary" // OutputDTypeUbinary returns bit-packed unsigned integers. OutputDTypeUbinary OutputDType = "ubinary" )
type Provider ¶
type Provider interface {
// ID returns the provider identifier (e.g., "openai", "anthropic").
ID() string
// Models returns the list of models available from this provider.
Models() []ModelInfo
// Supports reports whether the provider supports the given feature.
Supports(feature Feature) bool
// Chat sends a non-streaming chat request.
Chat(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
// StreamChat sends a streaming chat request.
StreamChat(ctx context.Context, req *ChatRequest) (*ChatStream, error)
}
Provider is the interface that LLM providers must implement. Providers SHOULD be safe for concurrent calls. If a provider cannot be concurrent-safe, it MUST document this.
type ProviderError ¶
type ProviderError struct {
Provider string
Status int
RequestID string
Code string
Message string
Err error
}
ProviderError represents an error returned by a provider with full context.
func (*ProviderError) Error ¶
func (e *ProviderError) Error() string
Error implements the error interface.
func (*ProviderError) Unwrap ¶
func (e *ProviderError) Unwrap() error
Unwrap returns the underlying error for error chaining.
type ReasoningEffort ¶
type ReasoningEffort string
ReasoningEffort represents the level of reasoning effort for models that support it.
const ( ReasoningEffortNone ReasoningEffort = "none" ReasoningEffortLow ReasoningEffort = "low" ReasoningEffortMedium ReasoningEffort = "medium" ReasoningEffortHigh ReasoningEffort = "high" ReasoningEffortXHigh ReasoningEffort = "xhigh" )
type ReasoningOutput ¶
ReasoningOutput contains reasoning information from the model.
type RequestEndEvent ¶
type RequestEndEvent struct {
Provider string // Provider identifier
Model ModelID // Model that was called
Start time.Time // When the request started
End time.Time // When the request completed
Usage TokenUsage // Token consumption
Err error // Error if request failed, nil on success
}
RequestEndEvent contains metadata about a completed request. Security: This struct intentionally excludes response content and API keys.
func (RequestEndEvent) Duration ¶
func (e RequestEndEvent) Duration() time.Duration
Duration returns the elapsed time for the request.
type RequestStartEvent ¶
type RequestStartEvent struct {
Provider string // Provider identifier (e.g., "openai", "anthropic")
Model ModelID // Model being called
Start time.Time // When the request started
}
RequestStartEvent contains metadata about a starting request. Security: This struct intentionally excludes prompt content and API keys.
type RerankRequest ¶
type RerankRequest struct {
// Model specifies the reranker model to use.
Model ModelID `json:"model"`
// Query is the search query to rank documents against.
Query string `json:"query"`
// Documents is the list of documents to rerank.
Documents []string `json:"documents"`
// TopK limits the number of results to return. If nil, returns all.
TopK *int `json:"top_k,omitempty"`
// ReturnDocuments includes document text in the response if true.
ReturnDocuments bool `json:"return_documents,omitempty"`
// Truncation controls whether to truncate inputs exceeding context length.
// Defaults to true.
Truncation *bool `json:"truncation,omitempty"`
}
RerankRequest represents a request to rerank documents.
type RerankResponse ¶
type RerankResponse struct {
// Results contains the reranked documents sorted by descending relevance.
Results []RerankResult `json:"results"`
// Model is the model that performed the reranking.
Model ModelID `json:"model"`
// Usage contains token consumption information.
Usage RerankUsage `json:"usage"`
}
RerankResponse contains the reranking results.
type RerankResult ¶
type RerankResult struct {
// Index is the original position in the input documents slice.
Index int `json:"index"`
// RelevanceScore is the relevance score (higher is more relevant).
RelevanceScore float64 `json:"relevance_score"`
// Document contains the document text if ReturnDocuments was true.
Document string `json:"document,omitempty"`
}
RerankResult represents a single document's reranking result.
type RerankUsage ¶
type RerankUsage struct {
// TotalTokens is the total number of tokens used.
TotalTokens int `json:"total_tokens"`
}
RerankUsage tracks token consumption for a rerank request.
type RerankerProvider ¶
type RerankerProvider interface {
// Rerank scores and sorts documents by relevance to the query.
// Results are returned in descending order of relevance.
Rerank(ctx context.Context, req *RerankRequest) (*RerankResponse, error)
}
RerankerProvider is an optional interface for providers that support semantic reranking of documents based on query relevance.
type RetryConfig ¶
type RetryConfig struct {
MaxRetries int // Maximum number of retry attempts (default: 3)
BaseDelay time.Duration // Initial delay before first retry (default: 1s)
MaxDelay time.Duration // Maximum delay cap (default: 30s)
Jitter float64 // Jitter factor 0.0-1.0 (default: 0.2)
}
RetryConfig configures retry behavior.
type RetryPolicy ¶
type RetryPolicy interface {
// NextDelay returns the delay before the next retry attempt and whether to retry.
// If ok is false, no more retries should be attempted.
// attempt starts at 0 for the first retry after the initial failure.
NextDelay(attempt int, err error) (delay time.Duration, ok bool)
}
RetryPolicy determines retry behavior for failed requests.
func DefaultRetryPolicy ¶
func DefaultRetryPolicy() RetryPolicy
DefaultRetryPolicy returns a retry policy with sensible defaults. Uses exponential backoff with jitter, max 3 retries, 30s max delay.
func NewRetryPolicy ¶
func NewRetryPolicy(cfg RetryConfig) RetryPolicy
NewRetryPolicy creates a retry policy with the given configuration.
type TelemetryHook ¶
type TelemetryHook interface {
// OnRequestStart is called when a request to a provider begins.
OnRequestStart(e RequestStartEvent)
// OnRequestEnd is called when a request to a provider completes.
OnRequestEnd(e RequestEndEvent)
}
TelemetryHook receives notifications about request lifecycle events. Implementations can use this for logging, metrics, tracing, etc.
Security: Event types intentionally exclude sensitive data. They NEVER include API keys, prompt content, or response content.
type TokenUsage ¶
type TokenUsage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
}
TokenUsage tracks token consumption for a request.
type Tool ¶
Tool is a placeholder interface for tool definitions. Full implementation is in the tools package (Task 07).
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments"`
}
ToolCall represents a tool invocation requested by the model. Arguments MUST be valid JSON bytes and MUST preserve raw JSON (no reformatting).
type ToolResources ¶
type ToolResources struct {
FileSearch *FileSearchResources `json:"file_search,omitempty"`
}
ToolResources contains configuration for built-in tools.