provider

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrModelNotFound = errors.New("model not found")
	ErrNoMessages    = errors.New("no messages provided")
)

Functions

func DefaultModel

func DefaultModel(pt ProviderType) string

DefaultModel returns the default model for a provider type.

func DefaultURL

func DefaultURL(pt ProviderType) string

DefaultURL returns the default base URL for a provider type.

func Register

func Register(pt ProviderType, r Registration)

Register adds a provider to the global registry.

Types

type CompletionOptions

type CompletionOptions struct {
	Model       string
	Temperature float32
	MaxTokens   int     // 0 = provider default
	TopP        float32 // 0 = provider default
}

CompletionOptions configures a completion request. Zero values for MaxTokens and TopP mean "use provider default".

type Message

type Message struct {
	Role    Role   `json:"role"`
	Content string `json:"content"`
}

Message represents a single message in a conversation.

type ModelInfo

type ModelInfo struct {
	Name        string
	Size        int64
	Modified    string
	Family      string
	Description string
}

ModelInfo describes an available model.

type Provider

type Provider interface {
	CreateCompletion(ctx context.Context, messages []Message, opts *CompletionOptions) (string, error)
	StreamCompletion(ctx context.Context, messages []Message, opts *CompletionOptions, onResponse func(string)) error
	ListModels(ctx context.Context) ([]ModelInfo, error)
	Name() string
	Description() string
}

Provider defines the interface for AI providers.

func New

func New(pt ProviderType, baseURL string) (Provider, error)

New creates a provider instance by type, using the default URL if baseURL is empty.

type ProviderInfo

type ProviderInfo struct {
	Type        ProviderType
	Name        string
	Description string
}

ProviderInfo describes an available provider.

func All

func All() []ProviderInfo

All returns info for all registered providers in registration order.

type ProviderType

type ProviderType string

ProviderType identifies a provider implementation.

const (
	Ollama  ProviderType = "ollama"
	LocalAI ProviderType = "localai"
	OpenAI  ProviderType = "openai"
	Groq    ProviderType = "groq"
	Custom  ProviderType = "custom"
)

type Registration

type Registration struct {
	Factory      func(baseURL string) Provider
	DefaultURL   string
	DefaultModel string
	Name         string
	Description  string
}

Registration holds metadata and a factory for a provider type.

type Role

type Role string

Role represents a message role in a conversation.

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

Directories

Path Synopsis
Package openaicompat implements the OpenAI-compatible chat completions API.
Package openaicompat implements the OpenAI-compatible chat completions API.

Jump to

Keyboard shortcuts

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