跳转到主要内容

AIMindTool

描述

AIMindToolAI-Minds 的包装器,由 MindsDB 提供。它允许您通过简单地配置连接参数,用自然语言查询数据源。当您需要从各种数据源(包括 PostgreSQL、MySQL、MariaDB、ClickHouse、Snowflake 和 Google BigQuery)中存储的数据获取问题的答案时,此工具非常有用。 Minds 是与大型语言模型 (LLM) 类似的人工智能系统,但它们通过回答任何数据中的任何问题而超越了 LLM。这是通过以下方式实现的:
  • 使用参数搜索选择最相关的答案数据
  • 通过语义搜索理解含义并在正确的上下文中提供响应
  • 通过分析数据和使用机器学习 (ML) 模型提供精确答案

安装

要将此工具整合到您的项目中,您需要安装 Minds SDK
uv add minds-sdk

开始步骤

要有效使用 AIMindTool,请遵循以下步骤
  1. 软件包安装:确认您的 Python 环境中已安装 crewai[tools]minds-sdk 软件包。
  2. API 密钥获取在此处注册 Minds 帐户,并获取 API 密钥。
  3. 环境配置:将您获取的 API 密钥存储在名为 MINDS_API_KEY 的环境变量中,以便工具使用。

示例

以下示例演示了如何初始化工具并执行查询
代码
from crewai_tools import AIMindTool

# Initialize the AIMindTool
aimind_tool = AIMindTool(
    datasources=[
        {
            "description": "house sales data",
            "engine": "postgres",
            "connection_data": {
                "user": "demo_user",
                "password": "demo_password",
                "host": "samples.mindsdb.com",
                "port": 5432,
                "database": "demo",
                "schema": "demo_data"
            },
            "tables": ["house_sales"]
        }
    ]
)

# Run a natural language query
result = aimind_tool.run("How many 3 bedroom houses were sold in 2008?")
print(result)

参数

AIMindTool 接受以下参数
  • api_key:可选。您的 Minds API 密钥。如果未提供,它将从 MINDS_API_KEY 环境变量中读取。
  • datasources:一个字典列表,每个字典包含以下键
    • description:数据源中包含的数据的描述。
    • engine:数据源的引擎(或类型)。
    • connection_data:一个字典,包含数据源的连接参数。
    • tables:数据源将使用的表列表。这是可选的,如果数据源中的所有表都将被使用,则可以省略。
支持的数据源及其连接参数列表可在此处找到。

代理集成示例

以下是如何将 AIMindTool 与 CrewAI 代理集成
代码
from crewai import Agent
from crewai.project import agent
from crewai_tools import AIMindTool

# Initialize the tool
aimind_tool = AIMindTool(
    datasources=[
        {
            "description": "sales data",
            "engine": "postgres",
            "connection_data": {
                "user": "your_user",
                "password": "your_password",
                "host": "your_host",
                "port": 5432,
                "database": "your_db",
                "schema": "your_schema"
            },
            "tables": ["sales"]
        }
    ]
)

# Define an agent with the AIMindTool
@agent
def data_analyst(self) -> Agent:
    return Agent(
        config=self.agents_config["data_analyst"],
        allow_delegation=False,
        tools=[aimind_tool]
    )

结论

AIMindTool 提供了一种强大的方式,让您可以使用自然语言查询数据源,从而更轻松地提取见解,而无需编写复杂的 SQL 查询。通过连接到各种数据源并利用 AI-Minds 技术,此工具使代理能够高效地访问和分析数据。