providers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package providers contains LLM provider implementations for Iris.

Each provider is implemented in its own subpackage (e.g., providers/openai, providers/anthropic). Providers implement the core.Provider interface.

Provider Interface

All providers must implement core.Provider:

type Provider interface {
    ID() string
    Models() []ModelInfo
    Supports(feature Feature) bool
    Chat(ctx context.Context, req *ChatRequest) (*ChatResponse, error)
    StreamChat(ctx context.Context, req *ChatRequest) (*ChatStream, error)
}

Concurrency

Providers SHOULD be safe for concurrent calls. If a provider cannot be concurrent-safe, it MUST document this limitation.

Streaming

StreamChat returns a *ChatStream (not a raw channel) to carry errors and final tool calls consistently. Providers MUST:

  • Close all channels (Ch, Err, Final) when finished
  • Terminate promptly on context cancellation
  • Send at most one error on Err
  • Send exactly one response on Final (or zero on setup failure)

Feature Detection

Use Supports() to check provider capabilities before making requests:

if p.Supports(core.FeatureToolCalling) {
    // Safe to use tools
}

Core Re-exports

The historical core type, feature, role, and error aliases in this package are deprecated and frozen. Import github.com/petal-labs/iris/core directly for those APIs. Registry functions in this package remain supported.

Index

Constants

View Source
const (
	FeatureChat          = core.FeatureChat
	FeatureChatStreaming = core.FeatureChatStreaming
	FeatureToolCalling   = core.FeatureToolCalling
)

Deprecated: Import feature constants from github.com/petal-labs/iris/core.

View Source
const (
	RoleSystem    = core.RoleSystem
	RoleUser      = core.RoleUser
	RoleAssistant = core.RoleAssistant
)

Deprecated: Import role constants from github.com/petal-labs/iris/core.

Variables

View Source
var (
	ErrUnauthorized  = core.ErrUnauthorized
	ErrRateLimited   = core.ErrRateLimited
	ErrBadRequest    = core.ErrBadRequest
	ErrNotFound      = core.ErrNotFound
	ErrServer        = core.ErrServer
	ErrNetwork       = core.ErrNetwork
	ErrDecode        = core.ErrDecode
	ErrModelRequired = core.ErrModelRequired
	ErrNoMessages    = core.ErrNoMessages
)

Deprecated: Import sentinel errors from github.com/petal-labs/iris/core.

Functions

func Create

func Create(name, apiKey string) (core.Provider, error)

Create creates a new provider instance by name with the given API key. Returns an error if the provider is not registered.

func CreateWithConfig added in v1.0.0

func CreateWithConfig(name string, config ProviderConfig) (core.Provider, error)

CreateWithConfig creates a registered provider with common construction values such as an API key and resource endpoint.

func IsRegistered

func IsRegistered(name string) bool

IsRegistered returns true if a provider with the given name is registered.

func List

func List() []string

List returns the names of all registered providers in sorted order.

func Register

func Register(name string, factory ProviderFactory)

Register adds a provider factory to the registry. It is typically called from a provider's init() function. If a provider with the same name is already registered, it will be overwritten.

Example usage in a provider package:

func init() {
    providers.Register("openai", func(apiKey string) core.Provider {
        return New(apiKey)
    })
}

func RegisterConfigured added in v1.0.0

func RegisterConfigured(name string, factory ConfiguredProviderFactory)

RegisterConfigured adds a provider factory that can consume common values beyond an API key. Get and Create remain available through an API-key-only adapter for backward compatibility.

Types

type ChatChunk

type ChatChunk = core.ChatChunk

ChatChunk represents an incremental streaming response.

type ChatRequest

type ChatRequest = core.ChatRequest

ChatRequest represents a request to a chat model.

type ChatResponse

type ChatResponse = core.ChatResponse

ChatResponse represents a response from a chat model.

type ChatStream

type ChatStream = core.ChatStream

ChatStream represents a streaming response from a provider.

type ConfiguredProviderFactory added in v1.0.0

type ConfiguredProviderFactory func(config ProviderConfig) core.Provider

ConfiguredProviderFactory creates a provider from common registry values.

type Feature

type Feature = core.Feature

Feature represents a capability that a provider may support.

type Message

type Message = core.Message

Message represents a single message in a conversation.

type ModelID

type ModelID = core.ModelID

ModelID is a string identifier for a model.

type ModelInfo

type ModelInfo = core.ModelInfo

ModelInfo describes a model available from a provider.

type Provider

type Provider = core.Provider

Provider is the interface that LLM providers must implement.

type ProviderConfig added in v1.0.0

type ProviderConfig struct {
	APIKey   string
	Endpoint string
}

ProviderConfig supplies common construction values to a configured registry factory. Endpoint is primarily used by providers such as Azure AI Foundry whose resource endpoint cannot be inferred from an API key.

type ProviderError

type ProviderError = core.ProviderError

ProviderError represents an error returned by a provider.

type ProviderFactory

type ProviderFactory func(apiKey string) core.Provider

ProviderFactory creates a provider instance with the given API key.

func Get

func Get(name string) ProviderFactory

Get retrieves a provider factory by name. Returns nil if the provider is not registered.

type Role

type Role = core.Role

Role represents a message participant role.

type TokenUsage

type TokenUsage = core.TokenUsage

TokenUsage tracks token consumption for a request.

type ToolCall

type ToolCall = core.ToolCall

ToolCall represents a tool invocation requested by the model.

Directories

Path Synopsis
Package anthropic provides an Anthropic API provider implementation for Iris.
Package anthropic provides an Anthropic API provider implementation for Iris.
Package azurefoundry provides an Iris provider implementation for Azure AI Foundry.
Package azurefoundry provides an Iris provider implementation for Azure AI Foundry.
Package gemini provides a Google Gemini API provider implementation for Iris.
Package gemini provides a Google Gemini API provider implementation for Iris.
Package huggingface provides an LLM provider implementation for Hugging Face Inference Providers.
Package huggingface provides an LLM provider implementation for Hugging Face Inference Providers.
internal
normalize
Package normalize provides shared provider error normalization helpers.
Package normalize provides shared provider error normalization helpers.
timeoutx
Package timeoutx applies per-provider timeouts to direct (non-chat) calls.
Package timeoutx applies per-provider timeouts to direct (non-chat) calls.
toolcalls
Package toolcalls provides shared streaming tool-call assembly utilities.
Package toolcalls provides shared streaming tool-call assembly utilities.
Package ollama provides an Ollama provider implementation for the Iris SDK.
Package ollama provides an Ollama provider implementation for the Iris SDK.
Package openai provides an OpenAI API provider implementation for Iris.
Package openai provides an OpenAI API provider implementation for Iris.
Package perplexity provides a Perplexity Search API provider implementation for Iris.
Package perplexity provides a Perplexity Search API provider implementation for Iris.
Package voyageai provides a Voyage AI API provider implementation for Iris.
Package voyageai provides a Voyage AI API provider implementation for Iris.
Package xai provides an xAI Grok API provider implementation for Iris.
Package xai provides an xAI Grok API provider implementation for Iris.
Package zai provides a Z.ai GLM API provider implementation for Iris.
Package zai provides a Z.ai GLM API provider implementation for Iris.

Jump to

Keyboard shortcuts

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