semantic_router.layer.LayerConfig#
- class semantic_router.layer.LayerConfig(routes: List[Route] = [], encoder_type: str = 'openai', encoder_name: str | None = None)#
Bases:
object
Generates a LayerConfig object that can be used for initializing a RouteLayer.
Methods
__init__
([routes, encoder_type, encoder_name])add
(route)from_file
(path)from_index
(index[, encoder_type, encoder_name])Initialize a LayerConfig from a BaseIndex object.
from_tuples
(route_tuples[, encoder_type, ...])Initialize a LayerConfig from a list of tuples of routes and utterances.
get
(name)get_hash
()remove
(name)to_dict
()to_file
(path)Save the routes to a file in JSON or YAML format
Convert the routes to a list of Utterance objects.
Attributes
routes
- classmethod from_index(index: BaseIndex, encoder_type: str = 'openai', encoder_name: str | None = None)#
Initialize a LayerConfig from a BaseIndex object.
- Parameters:
index (BaseIndex) – The index to initialize the LayerConfig from.
encoder_type (str, optional) – The type of encoder to use, defaults to “openai”.
encoder_name (Optional[str], optional) – The name of the encoder to use, defaults to None.
- classmethod from_tuples(route_tuples: List[Tuple[str, str, List[Dict[str, Any]] | None, Dict[str, Any]]], encoder_type: str = 'openai', encoder_name: str | None = None)#
Initialize a LayerConfig from a list of tuples of routes and utterances.
- Parameters:
route_tuples (List[Tuple[str, str]]) – A list of tuples, each containing a route name and an associated utterance.
encoder_type (str, optional) – The type of encoder to use, defaults to “openai”.
encoder_name (Optional[str], optional) – The name of the encoder to use, defaults to None.
- to_file(path: str)#
Save the routes to a file in JSON or YAML format