rulebased

package
v1.18.6 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package rulebased provides a rule-based model router that selects the appropriate model based on NLP analysis of the input using Bleve.

Routes are defined with example texts, and Bleve's full-text search determines the best matching route based on text similarity.

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

type Client struct {
	base.Config
	// contains filtered or unexported fields
}

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

func (c *Client) BaseConfig() base.Config

BaseConfig returns the base configuration.

func (*Client) Close

func (c *Client) Close() error

Close cleans up resources.

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.

func (*Client) ID

func (c *Client) ID() string

ID returns the provider identifier.

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.

Jump to

Keyboard shortcuts

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