mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 17:18:29 +00:00
completed the initialization logic for the tool
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
from typing import Dict, Optional, Type, TYPE_CHECKING
|
||||
import secrets
|
||||
from typing import Dict, Optional, Text, Type
|
||||
|
||||
from crewai.tools import BaseTool
|
||||
from openai import OpenAI
|
||||
from pydantic import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from minds_sdk import Client
|
||||
|
||||
|
||||
class AIMindInputSchema(BaseModel):
|
||||
"""Input for AIMind Tool."""
|
||||
@@ -26,15 +24,38 @@ class AIMindTool(BaseTool):
|
||||
args_schema: Type[BaseModel] = AIMindInputSchema
|
||||
api_key: Optional[str] = None
|
||||
datasources: Optional[Dict] = None
|
||||
minds_client: Optional["Client"] = None
|
||||
mind_name: Optional[Text] = None
|
||||
|
||||
def __init__(self, api_key: Optional[str] = None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
try:
|
||||
from minds_sdk import Client # type: ignore
|
||||
from minds.datasources import DatabaseConfig # type: ignore
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"`minds_sdk` package not found, please run `pip install minds-sdk`"
|
||||
)
|
||||
|
||||
self.minds_client = Client(api_key=api_key)
|
||||
minds_client = Client(api_key=api_key)
|
||||
|
||||
# Convert the datasources to DatabaseConfig objects.
|
||||
datasources = []
|
||||
for datasource in self.datasources:
|
||||
if datasource["type"] == "database":
|
||||
config = DatabaseConfig(
|
||||
name=datasource["name"],
|
||||
engine=datasource["engine"],
|
||||
description=datasource["description"],
|
||||
connection_data=datasource["connection_data"],
|
||||
tables=datasource["tables"],
|
||||
)
|
||||
datasources.append(config)
|
||||
|
||||
# Generate a random name for the Mind.
|
||||
name = f"cai_mind_{secrets.token_hex(5)}"
|
||||
|
||||
mind = minds_client.minds.create(
|
||||
name=name, datasources=datasources, replace=True
|
||||
)
|
||||
|
||||
self.mind_name = mind.name
|
||||
Reference in New Issue
Block a user