Documentation
¶
Overview ¶
Package llmfactory provides factories and configuration for LLM model instantiation, supporting multiple providers (OpenAI, Azure, etc.) and model selection strategies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NewLLM = CreateLLM
NewLLM is a wrapper for CreateLLM to allow for overriding the default implementation.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Providers specifies the list of providers to use
Providers []*ProviderConfig `json:"providers" yaml:"providers"`
// DefaultProvider specifies the default provider to use
DefaultProvider string `json:"default_provider" yaml:"default_provider"`
// AssistantModels specifies the mapping of assistants to models.
// key is the assistant name, value is the model name.
// The model name can be in the format of <provider_name>/<model_name>.
// Use `default: <model_name>` as the default model for assistants.
AssistantModels map[string][]string `json:"assistant_models" yaml:"assistant_models"`
// Orgs specifies the organizations configuration to override the global configuration.
Orgs map[string]*OrgConfig `json:"orgs_override" yaml:"orgs_override"`
// Skills specifies the skills configuration.
Skills *skills.Config `json:"skills,omitempty" yaml:"skills,omitempty"`
}
type Factory ¶
type Factory interface {
// GetModel returns an LLM model that matches the given options.
//
// Resolution rules:
// - When ProviderType is set, a provider of that type is selected.
// - Otherwise, when AssistantName is set, the configured assistant model
// mapping (optionally per-org) is expanded into the preferred models.
// - The preferred models are tried in order; the first available and
// allowed model wins.
// - If no preferred model matches, the default model is returned.
//
// RequiredCapabilities, when non-zero, restricts the candidates to
// providers whose type supports ALL of the requested capabilities.
GetModel(opts ModelOptions) (llms.Model, error)
// Skills returns all loaded skills for the given agent sorted alphabetically by name.
// Use tags to filter skills by tags. The Skill must have all the tags provided.
Skills(agent string, tags ...string) skills.Skills
}
Factory is the interface for creating and managing LLM models. In multi-tenant environments, the OrgID is used to determine the LLM model to use for the organization. The factory can also be provided with a ModelFilterFunc to restrict which models an organization may use.
type HTTPClient ¶ added in v0.16.114
HTTPClient is primarily used to describe an *http.Client, but also supports custom implementations.
For bespoke implementations, prefer using an *http.Client with a custom transport. See http.RoundTripper for further information.
type ModelFilterFunc ¶ added in v0.19.141
ModelFilterFunc reports whether the given model may be used for the org. Provide this to enforce per-org / per-model quota: return false when the model must not be used for the org (e.g. quota exceeded), true otherwise. The orgID can be empty, in which case the check applies globally. The modelName can be in the format of <provider_name>/<model_name>.
type ModelOptions ¶ added in v0.19.141
type ModelOptions struct {
// ProviderType specifies the provider type to use.
// If not specified, a matching provider will be used.
ProviderType llms.ProviderType
// OrgID specifies the organization ID to use,
// if configuration provides Org overrides.
OrgID string
// AssistantName specifies the assistant name to use.
AssistantName string
// PreferredModels specifies the preferred models to use.
PreferredModels []string
// RequiredCapabilities specifies the required capabilities the model must support.
// When non-zero, only providers whose type supports ALL of the requested
// capabilities are considered.
RequiredCapabilities llms.Capability
}
type OpenAIConfig ¶
type OpenAIConfig struct {
BaseURL string `json:"base_url,omitempty" yaml:"base_url,omitempty"`
APIVersion string `json:"api_version,omitempty" yaml:"api_version,omitempty"`
// APIType specifies the type of API to use:
// OPENAI|AZURE|AZURE_AD|CLOUDFLARE|ANTHROPIC|GOOGLEAI|BEDROCK|PERPLEXITY
APIType string `json:"api_type,omitempty" yaml:"api_type,omitempty"`
}
OpenAIConfig specifies options config
type Option ¶ added in v0.16.114
type Option func(*Options)
func WithAWSConfigFactory ¶ added in v0.16.114
func WithHTTPClient ¶ added in v0.16.114
func WithHTTPClient(client HTTPClient) Option
WithHTTPClient allows setting a custom HTTP client. If not set, the default value is http.DefaultClient.
func WithModelFilter ¶ added in v0.19.141
func WithModelFilter(filter ModelFilterFunc) Option
WithModelFilter sets a predicate used to restrict which models an org may use, for example to enforce per-org / per-model quota.
type Options ¶ added in v0.16.114
type Options struct {
// HTTPClient is used to create a new HTTP client.
HTTPClient HTTPClient
// AwsConfigFactory is used to create a new AWS config.
AwsConfigFactory func() (*aws.Config, error)
// ModelFilter reports whether a model may be used for an org,
// e.g. to enforce per-org / per-model quota.
ModelFilter ModelFilterFunc
}
func NewOptions ¶ added in v0.16.114
type OrgConfig ¶ added in v0.19.141
type OrgConfig struct {
// AssistantModels specifies the mapping of assistants to models.
// key is the assistant name, value is the model name.
// The model name can be in the format of <provider_name>/<model_name>.
// Use `default: <model_name>` as the default model for assistants.
AssistantModels map[string][]string `json:"assistant_models" yaml:"assistant_models"`
}
type ProviderConfig ¶
type ProviderConfig struct {
Name string `json:"name" yaml:"name"`
Token string `json:"token,omitempty" yaml:"token,omitempty"`
DefaultModel string `json:"default_model,omitempty" yaml:"default_model,omitempty"`
AvailableModels []string `json:"available_models,omitempty" yaml:"available_models,omitempty"`
OpenAI OpenAIConfig `json:"open_ai" yaml:"open_ai"`
}
ProviderConfig for the OpenAI provider