provider

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIAnthropic         = "anthropic-messages"
	APIOpenAICompletions = "openai-completions"

	ProviderAnthropic = "anthropic"
	ProviderDeepSeek  = "deepseek"
	ProviderSilicon   = "siliconflow"
)
View Source
const (
	ReasoningOff   = "off"
	ReasoningMin   = "minimal"
	ReasoningLow   = "low"
	ReasoningMed   = "medium"
	ReasoningHigh  = "high"
	ReasoningXhigh = "xhigh"
	ReasoningMax   = "max"
)
View Source
const (
	ThinkingFormatAnthropic = "anthropic"
	ThinkingFormatDeepSeek  = "deepseek"
	ThinkingFormatOpenAI    = "openai"
)

Variables

This section is empty.

Functions

func DefaultEmbeddingModel

func DefaultEmbeddingModel() types.Model

DefaultEmbeddingModel returns a minimal Model for embedding requests. The embedding API endpoint defaults to SiliconFlow (free BAAI/bge-m3). API key is resolved from PI_API_KEY or PI_EMBEDDING_API_KEY.

func EmbeddingBaseURL

func EmbeddingBaseURL() string

EmbeddingBaseURL returns the base URL for embedding requests (includes /v1). Defaults to SiliconFlow's API which offers BAAI/bge-m3 for free.

func EmbeddingModel

func EmbeddingModel() string

EmbeddingModel returns the configured embedding model name.

func EnvOr

func EnvOr(key, def string) string

func GetModel

func GetModel(provider, id string) *types.Model

func ListCatalog

func ListCatalog()

Types

type Provider

type Provider struct {
	Model types.Model

	// Instance-level credentials. When empty, env fallbacks are used.
	APIKey           string
	EmbeddingModel   string
	EmbeddingBaseURL string
	EmbeddingAPIKey  string
}

Provider wraps a model and provides a Stream method to interact with it. Each Provider instance is owned by a single Agent to ensure isolation.

API keys are resolved with the following priority:

  1. Instance-level fields (APIKey / EmbeddingAPIKey) — set via NewConfiguredProvider / WithEmbedding / WithAPIKey
  2. Global env fallbacks (PI_API_KEY, provider-specific vars) — used only when no instance-level key is configured.

func NewConfiguredProvider

func NewConfiguredProvider(m types.Model, apiKey string) *Provider

NewConfiguredProvider creates a Provider with an explicit API key, bypassing env resolution for chat completions.

func NewProvider

func NewProvider(m types.Model) *Provider

func (*Provider) Embed

func (p *Provider) Embed(text string) ([]float32, error)

Embed computes an embedding vector for the given text using the configured embedding provider. The embedding endpoint is resolved with instance-level precedence: WithEmbedding fields, else the chat model's BaseURL.

URL: {baseURL}/embeddings (baseURL already includes /v1), POST model + input.

func (*Provider) Stream

func (p *Provider) Stream(ctx types.Context, signal <-chan struct{}, emit types.EventSink) (types.Message, error)

func (*Provider) WithAPIKey

func (p *Provider) WithAPIKey(key string) *Provider

WithAPIKey sets the chat-completion API key on the provider.

func (*Provider) WithEmbedding

func (p *Provider) WithEmbedding(model, baseURL, apiKey string) *Provider

WithEmbedding configures a dedicated embedding endpoint, independent of the chat model. Empty baseURL falls back to the chat model's BaseURL.

Jump to

Keyboard shortcuts

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