用于管理 Elasticsearch Serverless 项目标 AI Agent

打印 上一主题 下一主题

主题 690|帖子 690|积分 2070

作者:来自 Elastic  Fram Souza

由自然语言驱动的 AI 署理,可轻松管理 Elasticsearch Serverless 项目 - 支持项目创建、删除和状态查抄。

这个小型下令行工具让你可以用简朴的英语管理你的无服务器 Elasticsearch 项目。它通过AI(这里是 OpenAI)明白你的意思,并利用 LlamaIndex 调用正确的函数!

它能做什么?



  • 创建项目:创建一个新的无服务器 Elasticsearch 项目。
  • 删除项目:删除一个已有项目(是的,它还会帮你清算干净)。
  • 获取项目状态:检察项目标运行状态。
  • 获取项目详情:获取项目标详细信息。
  • 在 GitHub 上检察代码

工作原理

当你输入类似:
Create a serverless project named my_project"
这样的指令时,系统背后会实行以下步骤:


  • 用户输入 & 上下文
    你的自然语言下令会发送给 AI 智能体(agent)。
  • 函数描述
    这个 AI 智能体预先了解了一些函数,比如:

    • create_ess_project
    • delete_ess_project
    • get_ess_project_status
    • get_ess_project_details
      这些函数都附带详细描述,告诉 AI 每个函数的用途和所需的参数。

  • LLM处理
    你的哀求和这些函数信息会一起发送到大语言模型(LLM),也就是说 AI 会看到:

    • 你的自然语言指令
    • 可用的函数和它们的描述
    • 对话汗青和上下文信息(因为是对话式的,AI 会记着之前的交流内容)

  • 函数调用 & 响应
    AI 判断该调用哪个函数,并把正确的参数(比如项目名)传递过去,然后实行函数,并以友好的格式把效果返回给你。

设置



先决条件

在运行 AI 智能体之前,请确保你已经完成以下准备工作:


  • 已安装Python(3.7 或更高版本)。
  • 已在 Elastic Cloud 上设置好 Elasticsearch 无服务器账号。
  • 已拥有 OpenAI 账号,用于与语言模型交互。

步骤

1)克隆代码仓库
  1. git clone https://github.com/elastic/elasticsearch-labs/supporting-blog-content/serverless-ai-agent
  2. cd serverless-ai-agent
复制代码
2)创建虚拟环境(可选,但推荐)
假如遇到环境干系的题目,可以创建一个虚拟环境来举行隔离:
  1. python -m venv venv
  2. source venv/bin/activate  # On Windows, use venv\Scripts\activate
复制代码
3)安装依赖
运行以下下令,确保全部必须的依赖都已安装:
  1. pip install -r requirements.txt
复制代码
4)设置环境
在项目根目次下创建一个 .env 文件,并添加以下变量。你可以参考示例文件 .env.example 作为模板:
  1. ES_URL=your_elasticsearch_api_url  # The base URL for your Elasticsearch service (e.g., https://your-cluster-id.es.region.aws.elastic-cloud.com)
  2. API_KEY=your_elasticsearch_api_key  # Your API key for Elasticsearch
  3. REGION=your_region  # Example: aws-eu-west-1
  4. OPENAI_API_KEY=your_openai_api_key  # Your OpenAI API key
复制代码
确保你已经正确设置以下变量的值:ES_URL、API_KEY 和 OPENAI_API_KEY。这些密钥可以在对应服务的控制台找到。
5)项目文件
这个工具利用一个名为 projects.json 的文件来保存项目标映射关系(即项目名称和项目详情)。假如该文件不存在,工具会自动创建。

运行 AI 智能体

完成设置后,你可以通过以下方式运行 AI 智能体:
  1. python main.py
复制代码
你将看到类似这样的提示:
  1. Welcome to the Serverless Project AI Agent Tool!
  2. You can ask things like:
  3. - 'Create a serverless project named my_project'
  4. - 'Delete the serverless project named my_project'
  5. - 'Get the status of the serverless project named my_project'
  6. - 'Get the details of the serverless project named my_project'
复制代码
输入你的下令,AI 智能体将自动处理!完成后,输入 exit 或 quit 退出。

更多细节



  • LLM 集成
    LLM 接收到你的查询和每个可用函数的详细描述。这资助它明白上下文,并决定是否调用 create_ess_project 或 delete_ess_project 等函数。
  • 工具描述
    每个函数工具(通过 FunctionTool.from_defaults 创建)都有一个友好的描述。这个描述会包含在发送给 LLM 的提示中,资助它了解可用的操作以及每个操作的预期。
  • 持久化
    你的项目及其详情会保存在 projects.json 文件中,这样你就不需要每次都重新输入信息。
  • 详细日记
    智能体被设置为详细日记模式,这对于调试和检察你的指令怎样转换为函数调用非常有效。

示例利用

假设你已经完成了全部设置并成功启动了 AI 智能体。以下是一些常见的利用示例:
  1. python main.py Welcome to the Serverless Project AI Agent Tool!
  2. You can ask things like:
  3. - 'Create a serverless project named my_project'
  4. - 'Delete the serverless project named my_project'
  5. - 'Get the status of the serverless project named my_project'
  6. - 'Get the details of the serverless project named my_project'User: Create a serverless project named my-february-testAdded user message to memory: Create a serverless project named my-february-test=== Calling Function ===Calling function: create_ess_project with args: {"project_name":"my-february-test"}========================Agent: The serverless Elasticsearch project named "my-february-test" has been created successfully. Here are the details:- **Project ID:** <>>- **Elasticsearch Endpoint:** [https://my-february-test-ccc399.es.eu-west-1.aws.qa.elastic.cloud](https://my-february-test-ccc399.es.eu-west-1.aws.qa.elastic.cloud)- **Kibana Endpoint:** [https://my-february-test-ccc399.kb.eu-west-1.aws.qa.elastic.cloud](https://my-february-test-ccc399.kb.eu-west-1.aws.qa.elastic.cloud)User: get my-february-test statusAdded user message to memory: get my-february-test status=== Calling Function ===Calling function: get_ess_project_status with args: {"project_name":"my-february-test"}========================Agent: The status of the "my-february-test" project is currently **initializing**.User: get my-february-test infoAdded user message to memory: get my-february-test info=== Calling Function ===Calling function: get_ess_project_details with args: {"project_name":"my-february-test"}========================Agent: Here are the details for the "my-february-test" project:- **Project Name:** my-february-test- **Alias:** my-february-test-ccc399- **Cloud ID:** ""- **Project ID:** ""- **Region ID:** aws-eu-west-1- **Created At:** 2025-02-12T15:42:00.530177619Z- **Created By:** 571213384- **Organization ID:** ""- **Type:** Elasticsearch- **Optimized For:** General Purpose- **Search Lake:**  - **Boost Window:** 7  - **Search Power:** 100- **Endpoints:**  - **Elasticsearch:** https://my-february-test-ccc399.es.eu-west-1.aws.qa.elastic.cloud  - **Kibana:** https://my-february-test-ccc399.kb.eu-west-1.aws.qa.elastic.cloud- **Credentials:**  - **Username:** ""  - **Password:** ""Please ensure to keep the credentials secure.User: please delete the my-february-test projectAdded user message to memory: please delete the my-february-test project=== Calling Function ===Calling function: delete_ess_project with args: {"project_name":"my-february-test"}========================Agent: The "my-february-test" project has been deleted successfully.
复制代码
了解有关 Elastic Cloud Serverless 的更多信息,并开始 14 天免费试用来亲自测试。

原文:The AI Agent to manage Elasticsearch Serverless projects - Elasticsearch Labs

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

张裕

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表