diff --git a/semantic_router/route.py b/semantic_router/route.py index 4b322dd099b27ab0b5cd61ce202fdadde5ce9d5f..46c7c3e46c448599b6e9490e38e85b501e48e760 100644 --- a/semantic_router/route.py +++ b/semantic_router/route.py @@ -2,14 +2,20 @@ import json import re from typing import Any, Callable, Dict, List, Optional, Union -from PIL.Image import Image from pydantic.v1 import BaseModel +from typing_extensions import TypeAlias from semantic_router.llms import BaseLLM from semantic_router.schema import Message, RouteChoice from semantic_router.utils import function_call from semantic_router.utils.logger import logger +PILImage: TypeAlias = Union[Any, "Image"] +try: + from PIL.Image import Image +except ImportError: + pass + def is_valid(route_config: str) -> bool: try: @@ -41,7 +47,7 @@ def is_valid(route_config: str) -> bool: class Route(BaseModel): name: str - utterances: Union[List[str], List[Image]] + utterances: Union[List[str], List[PILImage]] description: Optional[str] = None function_schema: Optional[Dict[str, Any]] = None llm: Optional[BaseLLM] = None