refactored the logic for accessing the API key

This commit is contained in:
Minura Punchihewa
2025-01-03 11:49:58 +05:30
parent d1be5a937f
commit ea85f02e03

View File

@@ -34,7 +34,11 @@ class AIMindTool(BaseTool):
mind_name: Optional[Text] = None
def __init__(self, api_key: Optional[Text] = None, **kwargs):
super().__init__(api_key=api_key, **kwargs)
super().__init__(**kwargs)
self.api_key = api_key or os.getenv("MINDS_API_KEY")
if not self.api_key:
raise ValueError("API key must be provided either through constructor or MINDS_API_KEY environment variable")
try:
from minds.client import Client # type: ignore
from minds.datasources import DatabaseConfig # type: ignore
@@ -43,12 +47,6 @@ class AIMindTool(BaseTool):
"`minds_sdk` package not found, please run `pip install minds-sdk`"
)
if os.getenv("MINDS_API_KEY"):
self.api_key = os.getenv("MINDS_API_KEY")
if self.api_key is None:
raise ValueError("A Minds API key is required to use the AIMind Tool.")
minds_client = Client(api_key=self.api_key)
# Convert the datasources to DatabaseConfig objects.