From aafcf992ab4f8df96a994b73a126a085f695524f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Fri, 3 Jan 2025 10:03:53 -0300 Subject: [PATCH] fix weviate tool --- src/crewai_tools/tools/weaviate_tool/vector_search.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/crewai_tools/tools/weaviate_tool/vector_search.py b/src/crewai_tools/tools/weaviate_tool/vector_search.py index bfe80f966..14e10d7c5 100644 --- a/src/crewai_tools/tools/weaviate_tool/vector_search.py +++ b/src/crewai_tools/tools/weaviate_tool/vector_search.py @@ -40,9 +40,7 @@ class WeaviateVectorSearchTool(BaseTool): generative_model: Optional[str] = None collection_name: Optional[str] = None limit: Optional[int] = Field(default=3) - headers: Optional[dict] = Field( - default={"X-OpenAI-Api-Key": os.environ["OPENAI_API_KEY"]} - ) + headers: Optional[dict] = None weaviate_cluster_url: str = Field( ..., description="The URL of the Weaviate cluster", @@ -55,6 +53,12 @@ class WeaviateVectorSearchTool(BaseTool): def __init__(self, **kwargs): super().__init__(**kwargs) if WEAVIATE_AVAILABLE: + openai_api_key = os.environ.get("OPENAI_API_KEY") + if not openai_api_key: + raise ValueError( + "OPENAI_API_KEY environment variable is required for WeaviateVectorSearchTool and it is mandatory to use the tool." + ) + self.headers = {"X-OpenAI-Api-Key": openai_api_key} self.vectorizer = self.vectorizer or Configure.Vectorizer.text2vec_openai( model="nomic-embed-text", )