Skip to content

Commit

Permalink
Update layer.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Siraj-Aizlewood committed Sep 29, 2024
1 parent 6cb48dd commit 8b86773
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions semantic_router/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class RouteLayer:
index: BaseIndex

def __init__(
self
self,
encoder: Optional[BaseEncoder] = None,
llm: Optional[BaseLLM] = None,
routes: Optional[List[Route]] = None,
Expand Down Expand Up @@ -435,8 +435,29 @@ def add(self, route: Route):
def list_route_names(self) -> List[str]:
return [route.name for route in self.routes]

def update(self, route_name: str, utterances: List[str]):
raise NotImplementedError("This method has not yet been implemented.")
def update(self, name: str, threshold: Optional[float] = None, utterances: Optional[List[str]] = None):
"""Updates the route specified in name. Allows the update of
threshold and/or utterances. If no values are provided via the
threshold or utterances parameters, those fields are not updated.
If neither field is provided raises a ValueError.
The name must exist within the local RouteLayer, if not a
KeyError will be raised.
"""

if threshold is None and utterances is None:
raise ValueError("At least one of 'threshold' or 'utterances' must be provided.")
if utterances:
raise NotImplementedError("The update method cannot be used for updating utterances yet.")

Check warning on line 451 in semantic_router/layer.py

View check run for this annotation

Codecov / codecov/patch

semantic_router/layer.py#L448-L451

Added lines #L448 - L451 were not covered by tests

route = self.get(name)
if route:
if threshold:
old_threshold = route.score_threshold
route.score_threshold = threshold
logger.info(f"Updated threshold for route '{route.name}' from {old_threshold} to {threshold}")

Check warning on line 458 in semantic_router/layer.py

View check run for this annotation

Codecov / codecov/patch

semantic_router/layer.py#L453-L458

Added lines #L453 - L458 were not covered by tests
else:
raise ValueError(f"Route '{name}' not found. Nothing updated.")

Check warning on line 460 in semantic_router/layer.py

View check run for this annotation

Codecov / codecov/patch

semantic_router/layer.py#L460

Added line #L460 was not covered by tests

def delete(self, route_name: str):
"""Deletes a route given a specific route name.
Expand Down

0 comments on commit 8b86773

Please sign in to comment.