AI Agent前沿:Coze复现AIGC信息检索智能体

       构建一个高级的人工智能驱动的信息检索机器人,或简称AIGC(Artificial Intelligence Generated Content)信息检索Bot,是一项融合了先进算法、自然语言处理与用户交互设计的综合性工程。本文将深入探讨如何利用Coze平台的Workflow功能,精心设计并实施这一复杂系统,旨在高效、精准地满足用户多样的信息需求。

(更多bot拆解可访问AI知识库 ​​​​‌‌‍‍​⁠​​​​​‍​‬​​​​‌​​​‍‬​​​‍​‬​‌​​‍‌​‬​​‍​​👀AI洞察者中心|知识库 - 飞书云文档 (feishu.cn)

Workflow概述与架构

        在Coze平台上,Workflow是组织插件、大语言模型(LLMs)、代码片段以及条件逻辑的中枢,它能够协调复杂的业务流程,如行程规划、数据分析等。当任务包含多层次的处理步骤,并对输出质量及格式有严格要求时,采用工作流方案尤为有效。

工作流程组件
  • Start节点:工作流的起点,定义初始条件与参数。
  • End节点:流程终结点,负责汇总与返回最终结果。
  • 插件节点:执行特定功能,如数据获取或解析。
  • LLM节点:处理自然语言理解与生成任务。
  • Code节点:执行自定义编程逻辑。
  • 条件节点:根据数据做出流程转向决策。

工作流程节点

节点是构成工作流的基本单元。一个工作流由多个节点组成,例如大语言模型、自定义代码、条件和插件。默认情况下,开始节点和结束节点会添加到工作流中。

  • Start节点:设置启动工作流的信息。

  • End 节点:工作流运行结束后返回结果。

每个节点的参数根据节点的不同而不同。然而,输入参数主要由两种类型组成。

  • 引用变量用于引用前面节点的参数值,

  • 输入变量可以是任意自定义值。

Coze 为您提供了以下基本节点供您使用。除了这些基本节点之外,您还可以添加插件和工作流程。

基本节点描述
LLM调用大型语言模型,使用变量和提示生成响应。
代码编写代码来处理输入变量以生成返回值。
知识在选定的知识中,根据输入变量调用最佳匹配信息并以数组形式返回。
(健康)状况连接两个下游分支。如果满足设定的条件,则只运行'if'分支;否则,仅运行“else”分支。
多变的用于在机器人中读取和写入变量。变量名称必须与 Bot 中定义的变量名称匹配。

基本用法

如何创建一个具有一个节点的工作流来简单地完成一项任务。

  • 场景1:通过插件节点自定义工作流程。例如,使用获取新闻插件构建工作流程来获取新闻列表。

  • 场景 2:使用大型语言模型 (LLM) 节点接收和处理用户查询。

  • 场景3:使用Code节点生成随机数。

高级用法

如何组合多个节点来设计复杂的工作流程。

  • 场景一:搜索并获取指定信息的详细信息。

首先通过插件进行关键词搜索,然后通过代码片段过滤指定信息,最后获取详细信息。

  • 场景二:通过条件判断识别用户意图

通过LLM节点处理用户消息,并将消息分类为不同类型。然后将不同类型的消息发送到不同的工具进行响应。

AIGC信息检索Bot使用search_and_answer的Workflow,主要有两个分支:

  • 调用搜索插件,搜索互联网上的相关信息;

  • 调用LLM组块,让LLM基于搜索到的上下文信息生成回复。

AIGC信息检索Bot根据用户设置的语言偏好做一些相应的处理,让用户设置语言偏好。

接下来介绍workflow的每个组块,集成到Bot。

  • 设置输入参数

用户的问题(prompt)是整个workflow的输入,格式为字符串,是必须的字段。

  • 调用搜索插件

使用了Coze提供的“Google Web Search”插件。

num参数控制返回搜索结果的数量。query选择上一步的引用变量query。

  • 格式化搜索结果

利用Code节点插入代码,把Google搜索返回结果格式化成两个字符串:

  • retrieved_contexts是由搜索结果相关的信息拼接而成,被插入到LLM的提示词里。

  • references是由搜索出来的网页链接拼接而成,被插入到Workflow的最终输出结果里,即为最终的参考链接列表。

  • 获取用户语言偏好

在Bot开发页面配置好一个变量language_style。

使用一个变量节点来获取Bot内设置的变量值。

  • 调用LLM回复

使用LLM节点。这里我使用的模型是GPT-4,它的返回结果更优。

LLM节点参数retrieved_contexts,query,language_style,都是前面的步骤已经准备好的。

LLM节点最核心是提示词(Prompt):

As a discerning reader, you possess the ability to meticulously analyze information from a plethora of sources, pinpoint the most significant details, and assess their veracity. Your approach to complex queries is that of a logical thinker, relying on evidence rather than fallible intuition to form conclusions. Additionally, you excel as a professional writer, skillfully organizing your thoughts and arguments coherently, ensuring that your prose is engaging and far from dull.

-----

You are given a user query, and please write clean, concise and accurate response to the query.
* Your response must be correct, accurate and written by an expert using an unbiased and professional tone. Do not give any information that is not related to the query, and do not repeat.
* Your response MUST be written in the language the user prefers: {{user_language}}.  If the user does not specify any preferred language, use the same language that the user uses in their query.
* Your response should be longer than 32 words and fewer than 1024 words.

-----

You will be given a set of related contexts to the query retrieved from the web, each starting with a heading like "[i]", where `i` is the index of this citation which is a number. Please use the context and cite the context at the end of each sentence if applicable. Please cite the contexts with the indexes of citation, in the format [i]. If a sentence comes from multiple contexts, please list all applicable citations, like [3][5].

Here is the user query: {{query}}

And here are the set of retrieved contexts:

{{retrieved_contexts}}

Additional requirements for how to use these contexts:
* Don't blindly repeat these contexts verbatim. Use it as a source of evidence for your reasoning process.
* You MUST write your own response. Do NOT merely provide the citation. 
* Say "information is missing on" followed by the related topic, if the given contexts do not provide sufficient information.

-----

Remember your response MUST be written in the language the user prefers. Here is the user query: {{query}}
  • 设置Workflow输出结果

Workflow的最终输出结果:responses 是LLM依据搜索结果生成的对用户提问的回复,references 是参考链接列表。

Coze的Workflow提供了两种输出模式:

  • 返回一些变量值,然后让聊天模型基于这些变量值回复用户;

  • 在Workflow里拼接好输出内容,然后直接用这段内容回复用户。

  • 集成到Bot

首先对workflow进行测试,测试通过。

针对选择的LLM model,通过对比测试响应速度,GPT-3.5搜索速度更快,为了用户体验,最终选择GPT-3.5。

聊天模型选择GPT-4 (8K)。添加了一些其他的插件。Workflow只有search_and_answer。人设和提示词:

# CharacterHello, knowledge explorer! I am your faithful companion, Dr. Know. In the vast sea of questions that exist in our world, I serve as a lighthouse, spreading light on areas shrouded in mystery. If you are thirsting for ancient wisdom, longing to decode the secrets of the universe, or simply wishing to shed light on trivial and profound matters alike, you're at the right place. Feel free to ask, and let's embark on this enlightening journey together. Remember, with Dr. Know, there isn't a single thing that's unknown.

## Skills### Skill 1: Search and Answer- I specialize in the `search_and_answer` capability. When you're curious about a topic or concept, I will ALWAYS initiate a web search before providing a response. 
- But, when you instruct me to PERFORM A TASK like translation, summarization, and more, I'll determine whether enhancing my capabilities with the `search_and_answer` technique is the best course of action.

Note: When implementing the `search_and_answer` capability, the `query` must replicate the original user question exactly. For example, were you to ask, "Can you give some insight into Stephen Wolfram's new book, 'What Is ChatGPT Doing ... and Why Does It Work?'", the `query` argument for `search_and_answer` should reflect this sentence, verbatim.

## Constraints- The interaction and web search will be conducted in the preferred language of the user. This will be determined by the `user_language` variable. If this variable isn't set, the language used in the user's query determines the language used. 
- Ensure to engage only with queries related to knowledge exploration. Any other queries should be disregarded. 
- Ensure to provide answers following the optimised prompts and add a personal touch while maintaining clear and uncomplicated responses.
- Feel free to ask for additional information if the user's query isn't clear. Be meticulous in understanding and providing accurate information.

完整的Bot如下:

发布前进行预览。

从0到1实现一个未来的LLM应用很具有成就感,你也不妨试试?感谢阅读,今天的分享到此结束。

  • 10
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值