From 01b0103d866d8a87377d286ffc526021310fa875 Mon Sep 17 00:00:00 2001 From: Vittorio <vittorio.mayellaro.dev@gmail.com> Date: Fri, 4 Oct 2024 13:59:22 +0200 Subject: [PATCH] Formatting --- semantic_router/index/base.py | 10 +++++----- semantic_router/index/pinecone.py | 24 ++++++++++++------------ semantic_router/layer.py | 8 +++++--- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/semantic_router/index/base.py b/semantic_router/index/base.py index be1be557..7add4cb4 100644 --- a/semantic_router/index/base.py +++ b/semantic_router/index/base.py @@ -112,17 +112,17 @@ class BaseIndex(BaseModel): def is_synced( self, - local_route_names: List[str], - local_utterances_list: List[str], - local_function_schemas_list: List[Dict[str, Any]], - local_metadata_list: List[Dict[str, Any]] + local_route_names: List[str], + local_utterances_list: List[str], + local_function_schemas_list: List[Dict[str, Any]], + local_metadata_list: List[Dict[str, Any]], ) -> bool: """ Checks whether local and remote index are synchronized. This method should be implemented by subclasses. """ raise NotImplementedError("This method should be implemented by subclasses.") - + def _sync_index( self, local_route_names: List[str], diff --git a/semantic_router/index/pinecone.py b/semantic_router/index/pinecone.py index 7c304c09..23c5a05a 100644 --- a/semantic_router/index/pinecone.py +++ b/semantic_router/index/pinecone.py @@ -217,11 +217,11 @@ class PineconeIndex(BaseIndex): def _format_routes_dict_for_sync( self, - local_route_names: List[str], - local_utterances_list: List[str], - local_function_schemas_list: List[Dict[str, Any]], + local_route_names: List[str], + local_utterances_list: List[str], + local_function_schemas_list: List[Dict[str, Any]], local_metadata_list: List[Dict[str, Any]], - remote_routes: List[Tuple] + remote_routes: List[Tuple], ) -> Tuple[Dict, Dict]: remote_dict: Dict[str, Dict[str, Any]] = { route: { @@ -252,13 +252,13 @@ class PineconeIndex(BaseIndex): local_dict[route]["metadata"] = metadata return local_dict, remote_dict - + def is_synced( self, - local_route_names: List[str], - local_utterances_list: List[str], - local_function_schemas_list: List[Dict[str, Any]], - local_metadata_list: List[Dict[str, Any]] + local_route_names: List[str], + local_utterances_list: List[str], + local_function_schemas_list: List[Dict[str, Any]], + local_metadata_list: List[Dict[str, Any]], ) -> bool: remote_routes = self.get_routes() @@ -267,7 +267,7 @@ class PineconeIndex(BaseIndex): local_utterances_list, local_function_schemas_list, local_metadata_list, - remote_routes + remote_routes, ) logger.info(f"LOCAL: {local_dict}") logger.info(f"REMOTE: {remote_dict}") @@ -292,7 +292,7 @@ class PineconeIndex(BaseIndex): or local_metadata != remote_metadata ): return False - + return True def _sync_index( @@ -314,7 +314,7 @@ class PineconeIndex(BaseIndex): local_utterances_list, local_function_schemas_list, local_metadata_list, - remote_routes + remote_routes, ) all_routes = set(remote_dict.keys()).union(local_dict.keys()) diff --git a/semantic_router/layer.py b/semantic_router/layer.py index a597e938..410c9d41 100644 --- a/semantic_router/layer.py +++ b/semantic_router/layer.py @@ -529,12 +529,14 @@ class RouteLayer: def is_synced(self) -> bool: if not self.index.sync: raise ValueError("Index is not set to sync with remote index.") - + local_route_names, local_utterances, local_function_schemas, local_metadata = ( self._extract_routes_details(self.routes, include_metadata=True) ) - return self.index.is_synced(local_route_names, local_utterances, local_function_schemas, local_metadata) - + return self.index.is_synced( + local_route_names, local_utterances, local_function_schemas, local_metadata + ) + def _add_and_sync_routes(self, routes: List[Route]): # create embeddings for all routes and sync at startup with remote ones based on sync setting local_route_names, local_utterances, local_function_schemas, local_metadata = ( -- GitLab