From a35b0e1678e095cf7975e5b52d6213a191419f64 Mon Sep 17 00:00:00 2001
From: jamescalam <james.briggs@hotmail.com>
Date: Sat, 30 Nov 2024 20:56:48 +0100
Subject: [PATCH] fix: Route types

---
 semantic_router/encoders/openai.py | 16 ++++++++--------
 semantic_router/route.py           |  7 +------
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/semantic_router/encoders/openai.py b/semantic_router/encoders/openai.py
index 065e32b7..1ac5e56e 100644
--- a/semantic_router/encoders/openai.py
+++ b/semantic_router/encoders/openai.py
@@ -36,8 +36,8 @@ model_configs = {
 
 
 class OpenAIEncoder(DenseEncoder):
-    client: Optional[openai.Client]
-    async_client: Optional[openai.AsyncClient]
+    _client: Optional[openai.Client] = PrivateAttr(default=None)
+    _async_client: Optional[openai.AsyncClient] = PrivateAttr(default=None)
     dimensions: Union[int, NotGiven] = NotGiven()
     token_limit: int = 8192  # default value, should be replaced by config
     _token_encoder: Any = PrivateAttr()
@@ -77,10 +77,10 @@ class OpenAIEncoder(DenseEncoder):
         if max_retries is not None:
             self.max_retries = max_retries
         try:
-            self.client = openai.Client(
+            self._client = openai.Client(
                 base_url=base_url, api_key=api_key, organization=openai_org_id
             )
-            self.async_client = openai.AsyncClient(
+            self._async_client = openai.AsyncClient(
                 base_url=base_url, api_key=api_key, organization=openai_org_id
             )
         except Exception as e:
@@ -103,7 +103,7 @@ class OpenAIEncoder(DenseEncoder):
             False and a document exceeds the token limit, an error will be
             raised.
         :return: List of embeddings for each document."""
-        if self.client is None:
+        if self._client is None:
             raise ValueError("OpenAI client is not initialized.")
         embeds = None
 
@@ -114,7 +114,7 @@ class OpenAIEncoder(DenseEncoder):
         # Exponential backoff
         for j in range(self.max_retries + 1):
             try:
-                embeds = self.client.embeddings.create(
+                embeds = self._client.embeddings.create(
                     input=docs,
                     model=self.name,
                     dimensions=self.dimensions,
@@ -160,7 +160,7 @@ class OpenAIEncoder(DenseEncoder):
         return text
 
     async def acall(self, docs: List[str], truncate: bool = True) -> List[List[float]]:
-        if self.async_client is None:
+        if self._async_client is None:
             raise ValueError("OpenAI async client is not initialized.")
         embeds = None
 
@@ -171,7 +171,7 @@ class OpenAIEncoder(DenseEncoder):
         # Exponential backoff
         for j in range(self.max_retries + 1):
             try:
-                embeds = await self.async_client.embeddings.create(
+                embeds = await self._async_client.embeddings.create(
                     input=docs,
                     model=self.name,
                     dimensions=self.dimensions,
diff --git a/semantic_router/route.py b/semantic_router/route.py
index 7008ff00..b1fc5e8b 100644
--- a/semantic_router/route.py
+++ b/semantic_router/route.py
@@ -9,11 +9,6 @@ from semantic_router.schema import Message, RouteChoice
 from semantic_router.utils import function_call
 from semantic_router.utils.logger import logger
 
-try:
-    from PIL.Image import Image
-except ImportError:
-    pass
-
 
 def is_valid(route_config: str) -> bool:
     try:
@@ -45,7 +40,7 @@ def is_valid(route_config: str) -> bool:
 
 class Route(BaseModel):
     name: str
-    utterances: Union[List[str], List[Union[Any, "Image"]]]
+    utterances: Union[List[str], List[Any]]
     description: Optional[str] = None
     function_schemas: Optional[List[Dict[str, Any]]] = None
     llm: Optional[BaseLLM] = None
-- 
GitLab