aurelio-labs / semantic-router

Superfast AI decision making and intelligent processing of multi-modal data.
https://www.aurelio.ai/semantic-router
MIT License
1.86k stars 190 forks source link

Optional dependencies are not actually optional #187

Closed saevarb closed 5 months ago

saevarb commented 6 months ago

In pyproject.toml, a good deal of dependencies are marked optional, and for good reason. However, these are not actually optional. They are all imported unconditionally which will cause a runtime crash whenever an "optional" dependency is not present.

jamescalam commented 6 months ago

We should be capturing these like with the pinecone imports in pinecone.py like:

    def _initialize_client(self, api_key: Optional[str] = None):
        try:
            from pinecone import Pinecone, ServerlessSpec

            self.ServerlessSpec = ServerlessSpec
        except ImportError:
            raise ImportError(
                "Please install pinecone-client to use PineconeIndex. "
                "You can install it with: "
                "`pip install 'semantic-router[pinecone]'`"
            )

Where are you seeing this not happen?

jamescalam commented 5 months ago

We fixed the issue (there were several cases of this issue) in #190 — hope this helps!