Base adapter
Abstract base class for router backends.
This module defines the BaseAdapter interface that all backend implementations must follow. Backends handle provider-specific logic, model initialization, and routing execution.
BaseAdapter()
Bases: ABC
Abstract base class for router backend adapters.
Defines the interface that all backend implementations must follow. Adapters handle provider-specific logic, model initialization, and routing execution.
Initialize the adapter.
from_file(file_path, **kwargs)
classmethod
Load adapter from a configuration file.
Subclasses that support file-based initialization must override this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to configuration file (JSON or YAML). |
required |
**kwargs
|
Any
|
Additional arguments for initialization. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
BaseAdapter |
BaseAdapter
|
Initialized adapter instance. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by the subclass. |
route(source, **kwargs)
abstractmethod
async
Execute routing using backend implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | bytes
|
Input to route (text or bytes). |
required |
**kwargs
|
Any
|
Additional routing parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Selected route name, or None if no route matches. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented by the subclass. |
train(training_data)
Train the backend with provided training data.
Subclasses can override this method if training is supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
training_data
|
Generic[T]
|
Training data configuration. The structure depends on the specific backend implementation. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented by the subclass. |