Skip to main content
Version: DEV

创建一个通用聊天机器人

聊天机器人是最常见的人工智能场景之一。然而,有效理解用户查询并做出适当回应仍然是一个挑战。RAGFlow的通用聊天机器人代理是我们尝试解决这一长期存在的问题。

这个聊天机器人非常类似于开始AI聊天中介绍的聊天机器人,但有一个关键区别——它引入了一种反思机制,通过重写用户的查询来改进从目标知识库中的检索。

本文档提供了使用我们的聊天机器人模板创建此类聊天机器人的指南。

先决条件

  1. 确保您已正确设置要使用的LLM。有关更多信息,请参阅配置您的API密钥部署本地LLM的指南。
  2. 确保您已配置知识库并正确解析了相应的文件。有关更多信息,请参阅配置知识库指南。
  3. 确保你已经阅读了Agentic RAG 简介

从模板创建聊天机器人代理

使用我们的模板创建一个通用聊天机器人代理:

  1. 点击页面顶部中间的Agent标签以显示Agent页面。

  2. 点击页面右上角的+ 创建代理以显示代理模板页面。

  3. 代理模板页面上,将鼠标悬停在通用聊天机器人的卡片上,然后点击使用此模板
    您现在被引导到无代码工作流编辑器页面。

    workflow_editor

NOTE

RAGFlow的无代码编辑器免去了编码的麻烦,使代理开发变得轻松。

理解模板中的每个组件

以下是聊天机器人模板中每个组件及其角色和要求的详细说明:

  • 开始

    • Function: Sets an opening greeting for users.
    • Purpose: Establishes a welcoming atmosphere and prepares the user for interaction.
  • 互动

    • Function: Serves as the interface between human and the bot.
    • Role: Acts as the downstream component of Begin.
  • 检索

    • Function: Retrieves information from specified knowledge base(s).
    • Requirement: Must have knowledgebases set up to function.
  • 相关

    • Function: Assesses the relevance of the retrieved information from the Retrieval component to the user query.
    • Process:
      • If relevant, it directs the data to the Generate component for final response generation.
      • Otherwise, it triggers the Rewrite component to refine the user query and redo the retrival process.
  • 生成

    • Function: Prompts the LLM to generate responses based on the retrieved information.
    • Note: The prompt settings allow you to control the way in which the LLM generates responses. Be sure to review the prompts and make necessary changes.
  • 重写:

    • Function: Refines a user query when no relevant information from the knowledge base is retrieved.
    • Usage: Often used in conjunction with Relevant and Retrieval to create a reflective/feedback loop.

配置您的聊天机器人代理

  1. 点击开始设置开场问候语:
    opener

  2. 点击检索以选择正确的知识库并进行任何必要的调整:
    setting_knowledge_bases

  3. 点击生成以配置LLM的摘要行为:
    3.1. 确认模型。
    3.2. 检查提示设置。如果有变量,请确保它们与正确的组件ID匹配:
    prompt_settings

  4. 点击相关以查看或更改其设置:
    您可以保留当前设置,但可以随意尝试更改以了解代理的操作方式。 relevant_settings

  5. 点击重写以选择不同的查询重写模型或更新查询重写的最大循环次数:
    loop_time loop_time

NOTE

增加最大循环次数可能会显著延长接收最终响应所需的时间。

  1. 在您认为必要的地方更新您的工作流程。

  2. 点击保存以应用您的更改。
    您的代理将显示为代理页面上的一个代理卡片。

测试你的聊天机器人代理

  1. Agent页面上找到您的聊天机器人代理:
    find_chatbot

  2. 尝试用你的问题来验证这个聊天机器人是否按预期工作:
    test_chatbot