Documentation
¶
Overview ¶
Package rulebased provides a rule-based model router that selects the appropriate model based on text similarity using Bleve full-text search.
A model becomes a rule-based router when it has routing rules configured. The model's provider/model fields define the fallback model, and each routing rule maps example phrases to different target models.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client implements the Provider interface for rule-based model routing.
func NewClient ¶
func NewClient(ctx context.Context, cfg *latest.ModelConfig, models map[string]latest.ModelConfig, env environment.Provider, providerFactory ProviderFactory, opts ...options.Opt) (*Client, error)
NewClient creates a new rule-based routing client. The cfg parameter should have Routing rules configured. The provider/model fields of cfg define the fallback model that is used when no routing rule matches.
func (*Client) BaseConfig ¶
BaseConfig returns the base configuration.
func (*Client) CreateChatCompletionStream ¶
func (c *Client) CreateChatCompletionStream( ctx context.Context, messages []chat.Message, availableTools []tools.Tool, ) (chat.MessageStream, error)
CreateChatCompletionStream selects a provider based on input and delegates the call. The selected provider's ID is recorded in LastSelectedModelID.
func (*Client) LastSelectedModelID ¶ added in v1.32.5
LastSelectedModelID returns the ID of the provider selected by the most recent CreateChatCompletionStream call. This allows callers to display the YAML-configured sub-model name for rule-based routing.
type Provider ¶
type Provider interface {
ID() string
CreateChatCompletionStream(
ctx context.Context,
messages []chat.Message,
availableTools []tools.Tool,
) (chat.MessageStream, error)
BaseConfig() base.Config
}
Provider defines the minimal interface needed for model providers.
type ProviderFactory ¶
type ProviderFactory func(ctx context.Context, modelSpec string, models map[string]latest.ModelConfig, env environment.Provider, opts ...options.Opt) (Provider, error)
ProviderFactory creates a provider from a model config. The models parameter provides access to all configured models for resolving references.