[Llama3] ReAct Prompt 测试实验

news2024/10/5 13:54:58

ReAct 是一种 LLM 提示和结果处理方法,结合了推理、行动计划和知识源整合,使 LLM 超越其语言模型,并在预测中使用来自现实世界的信息。 ReAct 是推理和行动的结合。

介绍 ReAct 的论文表明它比思维链提示更好。与后者不同的是,ReAct 不会过多地幻化事实。然而,为了获得最佳结果,论文建议将 ReAct 和思维链提示与自我一致性检查结合起来。

前期准备

ReAct Prompt  llama3模板

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can.

If the user demands a final answer but you are unsure, execute the thought/action/action input/observation sequence.  

you have access to the following tools:
[{tool_name_and_description}]


use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action

..(this Thought/Action/Action Input/Observation can repeat N times)

Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!

Question: {question}
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

其它大语言模型的模版

You are an assistant to give people the answer of questions.
Human may provide new question to you with a description and you should use tools to get the answer, rather than directly reply from the description.

You have access to the following tools:

> Search: Search for a term in Wikipedia and return the first sentence. The input to this tool should be a string to search.
> Lookup: Lookup a term in the Wikipedia article and return sentence which describes about a term. The input to this tool should be a string to lookup.

To use a tool, please use the following format:

```
Question: the input question you must answer
Thought: your thought about what to do
Action: the action to take, should be one of [Search, Lookup]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
```

Begin!

Now human has provided the following question.

Question: Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?

把Observation添加到stop token里。

问题:

Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?

可用的工具

[Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]

实践步骤

实验一:

问题: Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?

执行第一次

prompt

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can

you have access to the following tools:
[Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]


use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [Search, Caculator]
Action Input: the input to the action
Observation: the result of the action

..(this Thought/Action/Action Input/Observation can repeat N times)

Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!

Question: Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

运行结果

Thought: I need to find out who Olivia Wilde's boyfriend is and then calculate his current age raised to the 0.23 power.
Action: Search
Action Input: "Who is Olivia Wilde's boyfriend?"

然后我在网上查找一下Olivia Wilde's boyfriend.

搜到如下结果:

Olivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sudeikis — see their relationship timeline.

执行第二次

prompt

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can. 
 
you have access to the following tools:
[Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
 
 
use the following format:
 
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [Search, Caculator]
Action Input: the input to the action
Observation: the result of the action
 
..(this Thought/Action/Action Input/Observation can repeact N times)
 
Thought: I now know the final answer
Final Answer: the final answer to the original input question
 
Begin!
 
Question: Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?
Thought: I need to find out who Olivia Wilde's boyfriend is and then calculate his current age raised to the 0.23 power.
Action: Search
Action Input: "Who is Olivia Wilde's boyfriend?"
Observation: Olivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sudeikis — see their relationship timeline.
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果

结果是:

Thought: I need to find out Harry Styles' current age and then calculate his age raised to the 0.23 power.
Action: Search
Action Input: "What is Harry Styles' current age?"

在网上搜索"Harry Styles age"。 结果是:”29 years“

执行第三次

prompt

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can. 
 
you have access to the following tools:
[Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
 
 
use the following format:
 
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [Search, Caculator]
Action Input: the input to the action
Observation: the result of the action
 
..(this Thought/Action/Action Input/Observation can repeact N times)
 
Thought: I now know the final answer
Final Answer: the final answer to the original input question
 
Begin!
 
Question: Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?
Thought: I need to find out who Olivia Wilde's boyfriend is and then calculate his current age raised to the 0.23 power.
Action: Search
Action Input: "Who is Olivia Wilde's boyfriend?"
Observation: Olivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sudeikis — see their relationship timeline.
Thought: I need to find out Harry Styles' current age and then calculate his age raised to the 0.23 power.
Action: Search
Action Input: "What is Harry Styles' current age?"
Observation: 29 years
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果:

Thought: I need to calculate Harry Styles' age raised to the 0.23 power.
Action: Caculator
Action Input: "29^0.23"

利用计算器计算29 ^ 0.23。 得到:2.169459462491557

执行第四次

prompt

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can. 
 
you have access to the following tools:
[Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
 
 
use the following format:
 
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [Search, Caculator]
Action Input: the input to the action
Observation: the result of the action
 
..(this Thought/Action/Action Input/Observation can repeact N times)
 
Thought: I now know the final answer
Final Answer: the final answer to the original input question
 
Begin!
 
Question: Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?
Thought: I need to find out who Olivia Wilde's boyfriend is and then calculate his current age raised to the 0.23 power.
Action: Search
Action Input: "Who is Olivia Wilde's boyfriend?"
Observation: Olivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sudeikis — see their relationship timeline.
Thought: I need to find out Harry Styles' current age and then calculate his age raised to the 0.23 power.
Action: Search
Action Input: "What is Harry Styles' current age?"
Observation: 29 years
Thought: I need to calculate Harry Styles' age raised to the 0.23 power.
Action: Caculator
Action Input: "29^0.23"
Observation: 2.169459462491557
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果

Final Answer: The answer to the question "Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?" is Harry Styles, and his current age raised to the 0.23 power is approximately 2.17.

实验二:

问题:I want to know what privileges does Harry user have ?

工具:[
{tool_name: getUser, description:search user information including pk_user_id based on username, tool parameter: username},
{tool_name: GetRole, description:get role information including role_id based on pk_user_Id, tool parameter: pk_user_Id } ,
{tool_name: GetPrivilege, description:get all privilege based on role_id , tool parameter: role_id } 
]

执行第一次

prompt

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can. 

If the user demands a final answer but you are unsure, execute the thought/action/action input/observation sequence.
 
you have access to the following tools:
[
{tool_name: getUser, description:search user information including pk_user_id based on username, tool parameter: username},
{tool_name: GetRole, description:get role information including role_id based on pk_user_Id, tool parameter: pk_user_Id } ,
{tool_name: GetPrivilege, description:get all privilege based on role_id , tool parameter: role_id } 
]
 
 
use the following format:
 
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [GetUser, GetRole, GetPrivilege]
Action Input: the input to the action
Observation: the result of the action
 
..(this Thought/Action/Action Input/Observation can repeat N times)
 
Thought: I now know the final answer
Final Answer: the final answer to the original input question
 
Begin!
 
Question: I want to know what privileges does Harry user have ?
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果:

Thought: I need to get the user information first
Action: GetUser
Action Input: Harry

执行第二次

prompt

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can. 

If the user demands a final answer but you are unsure, execute the thought/action/action input/observation sequence.
 
you have access to the following tools:
[
{tool_name: getUser, description:search user information including pk_user_id based on username, tool parameter: username},
{tool_name: GetRole, description:get role information including role_id based on pk_user_Id, tool parameter: pk_user_Id } ,
{tool_name: GetPrivilege, description:get all privilege based on role_id , tool parameter: role_id } 
]
 
 
use the following format:
 
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [GetUser, GetRole, GetPrivilege]
Action Input: the input to the action
Observation: the result of the action
 
..(this Thought/Action/Action Input/Observation can repeat N times)
 
Thought: I now know the final answer
Final Answer: the final answer to the original input question
 
Begin!
 
Question: I want to know what privileges does Harry user have ?
Thought: I need to get the user information first
Action: GetUser
Action Input: Harry
Observation: pk_user_id =1, user_name = Harry, age: 35
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

结果:

Thought: Now that I have the user information, I need to get the role of this user
Action: GetRole
Action Input: 1

执行第三次

prompt

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can. 

If the user demands a final answer but you are unsure, execute the thought/action/action input/observation sequence.
 
you have access to the following tools:
[
{tool_name: getUser, description:search user information including pk_user_id based on username, tool parameter: username},
{tool_name: GetRole, description:get role information including role_id based on pk_user_Id, tool parameter: pk_user_Id } ,
{tool_name: GetPrivilege, description:get all privilege based on role_id , tool parameter: role_id } 
]
 
use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [ GetUser, GetRole, GetPrivilege ]
Action Input: the input to the action
Observation: the result of the action
..(this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

 
Begin!
 
Question: I want to know what privileges does Harry user have?
Thought: I need to get the user information first
Action: GetUser
Action Input: Harry
Observation: user id is 1, user_name is Harry, age is35 .
Thought: Now that I have the user information, I need to get the role of this user
Action: GetRole
Action Input: 1
Observation: role id is 3.
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果有问题,很明显还要根据role id查询privileges.

在prompt里后面追加一个引导词Thought:

结果:

Action: GetPrivilege
Action Input: 3

执行第四次

prompt

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can. 

If the user demands a final answer but you are unsure, execute the thought/action/action input/observation sequence.
 
you have access to the following tools:

getUser: search user information including pk user id based on user name
GetRole: get role information including role id based on pk user Id
GetPrivilege: get all privilege based on role id

 
To use a tool, please use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [ GetUser, GetRole, GetPrivilege ]
Action Input: the input to the action
Observation: the result of the action

..(this Thought/Action/Action Input/Observation can repeat N times)

Thought: I now know the final answer
Final Answer: the final answer to the original input question

 
Begin!

Now human has provided the following question.
 
Question: I want to know what privileges does Harry user have?
Thought: I need to get the user information first
Action: GetUser
Action Input: Harry
Observation: user id is 1, user_name is Harry, age is35 .
Thought: Now that I have the user information, I need to get the role of this user
Action: GetRole
Action Input: 1
Observation: role id is 3.
Thought:
Action: GetPrivilege 
Action Input: 3
Observation: previleges for role whose role id is 3 are edit account and delete account
Thought: <|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果:

I now know the final answer
Final Answer: Harry has privileges to edit account and delete account.

实验三:

问题:I need to search Apple Remote and find the program it was original designed to interact with.

执行第一次

propmt

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can. 
 
you have access to the following tools:
[Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
 
 
use the following format:
 
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [Search, Caculator]
Action Input: the input to the action
Observation: the result of the action
 
..(this Thought/Action/Action Input/Observation can repeact N times)
 
Thought: I now know the final answer
Final Answer: the final answer to the original input question
 
Begin!
 
Question: I need to search Apple Remote and find the program it was original designed to interact with.
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果:

Thought: I need to find the original purpose of Apple Remote
Action: Search
Action Input: "Apple Remote original purpose"

搜索结果:

The Apple Remote is a remote control introduced in October 2005 by Apple. originally designed to control the Front Row media center program.

执行第二次

prompt

<|begin_of_text|><|start_header_id|>user<|end_header_id|>
Answer the following questions as best you can. 
 
you have access to the following tools:
[Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
 
 
use the following format:
 
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [Search, Caculator]
Action Input: the input to the action
Observation: the result of the action
 
..(this Thought/Action/Action Input/Observation can repeact N times)
 
Thought: I now know the final answer
Final Answer: the final answer to the original input question
 
Begin!
 
Question: I need to search Apple Remote and find the program it was original designed to interact with.
Thought: I need to find the original purpose of Apple Remote
Action: Search
Action Input: "Apple Remote"
Observation: The Apple Remote is a remote control introduced in October 2005 by Apple. originally designed to control the Front Row media center program.
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果:

The original program that Apple Remote was designed to interact with is Front Row.

复现失败,找寻答案中。。。

参考资料

ReAct 论文地址

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1807444.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【数据结构(邓俊辉)学习笔记】图06——最小支撑树

文章目录 0. 概述1. 支撑树2. 最小支撑树3. 歧义性4. 蛮力算法5. Prim算法5.1 割与极短跨越边5.2 贪心迭代5.3 实例5.4 实现5.5 复杂度 0. 概述 学习下最小支撑树和prim算法。 1. 支撑树 最小的连通图是树。 连通图G的某一无环连通子图T若覆盖G中所有的顶点&#xff0c;则称…

Layui弹框中设置输入框自动获取焦点无效/Layui设置Input框自动获取焦点无效,怎么办?

1、问题概述? 有时候为了用户体验,期望当弹框打开的时候,指定的输入框能自动的获取焦点,用户就可以直接输入了。提升了用户体验。但有时候设置的时候没有效果。 2、正常的设置自动获取焦点方式 【input框设置方式】 使用关键字autofocus <input type="text&quo…

Linux - 逻辑卷的创建和管理

1.逻辑卷LVM的创建 1.1 创建步骤 ①添加硬盘或者创建分区 ②创建物理卷 pvcreate ③创建卷组 vgcreate ④创建逻辑卷 lvcreate ⑤创建文件系统 mkfs.xfs/ect4/... ⑥创建挂…

安装搭建java版的悟空crm遇到 网络错误请稍候再试 终极解决办法(hrm人力资源模块)

java版 项目目录 ├── build – webpack 配置文件 ├── config – 项目配置文件 ├── src – 源码目录 │ ├── api – axios请求接口 │ ├── assets – 静态图片资源文件 │ ├── components – 通用组件 │ ├── directives – 通用指令 │ ├── filters –…

状态方程ABCD矩阵如何确定例子

状态方程ABCD矩阵如何确定 确定状态空间表示中的状态矩阵A、输入矩阵 B、输出矩阵C 和直通矩阵D,需要从系统的动力学方程出发,并将其转换为状态方程的形式。我们可以通过一个具体的物理系统(如倒立摆系统)来说明这一过程 例子:倒立摆系统 系统描述 考虑一个倒立摆系统…

串口RS232 RS485

RS232 RS232是在1970年由美国电子工业协会(EIA)联合贝尔系统、调制解调器厂家及计算机终端生产厂家共同制定的用于串行通讯的标准。它的全名是“数据终端设备(DTE)和数据通讯设备(DCE)之间串行二进制数据交换接口技术标准”。 该标准规定采用一个25个脚的DB-25连接器&#xff…

Cocos2dx 编译游戏安装包制作教程

在本教程中&#xff0c;我们将学习如何为 Visual Studio 编译项目配置图标&#xff0c;并使用 Inno Setup 创建安装包。我们将包括以下部分&#xff1a; 设置项目图标&#xff1a;在 Visual Studio 中配置 .exe 文件的图标&#xff0c;或者使用第三方工具替换编译后的图标。创…

王学岗鸿蒙开发(北向)——————(七、八)ArkUi的各种装饰器

arts包含如下&#xff1a;1&#xff0c;装饰器 &#xff1b;2&#xff0c;组件的描述(build函数)&#xff1b;3&#xff0c;自定义组件(Component修饰的),是可复用的单元&#xff1b;4&#xff0c;系统的组件(鸿蒙官方提供)&#xff1b;等 装饰器的作用:装饰类、变量、方法、结…

汇编语言LDS指令

在8086架构的实模式下&#xff0c;LDS指令&#xff08;Load Pointer Using DS&#xff09;用于从内存中加载一个32位的指针到指定寄存器和DS寄存器。我们来详细解释一下这条指令为什么会修改DS段寄存器。 LDS指令的功能 LDS指令格式如下&#xff1a; LDS destination, sourc…

SNAT与DNAT

一、SNAT策略概述 1、SNAT 策略的典型应用环境 局域网主机共享单个公网IP地址接入Internet&#xff08;私有IP不能在Internet中正常路由&#xff09; 局域共享上网 2、 SNAT 策略的原理 修改数据包的源地址 把从内网 --> 外网的数据的源内网地址转换成公网源地址 3、SN…

多目标检测模型加权框集成

优秀项目推荐&#xff1a;https://gitcode.com/ZFTurbo/Weighted-Boxes-Fusion/overview 参考链接&#xff1a; 目标检测加权框融合 WBF原理讲解 https://blog.csdn.net/YXD0514/article/details/132574588 目标检测加权框融合 WBF原理讲解&#xff08;Weighted Boxes Fusion&…

java中集合List,Set,Queue,Map

Java SE中的集合框架是一组用于存储和操作对象的类和接口。它提供了丰富的数据结构&#xff0c;可以用于解决各种问题。Java SE中的集合框架包含以下主要类和接口&#xff1a; 一. Collection接口&#xff1a; 是集合框架的根接口&#xff0c;它定义了一些通用的集合操作方法…

微服务之远程调用

常见的远程调用方式 RPC&#xff1a;Remote Produce Call远程过程调用&#xff0c;类似的还有 。自定义数据格式&#xff0c;基于原生TCP通信&#xff0c;速度快&#xff0c;效率高。早期的webservice&#xff0c;现在热门的dubbo &#xff08;12不再维护、17年维护权交给apac…

【设计模式】行为型设计模式之 迭代器模式

介绍 迭代器模式&#xff08;Iterator Pattern&#xff09; 是行为设计模式之一&#xff0c;它提供了一种访问集合对象&#xff08;如列表、数组或其他集合结构&#xff09;中元素的方式&#xff0c;而不需要暴露集合的内部结构。迭代器模式定义了一个迭代器接口&#xff0c;该…

专业学习|南开大学《随机过程》学习笔记(一)

&#xff08;1&#xff09;有哪些经典的关于基本随机过程的书籍推荐&#xff1f; 对于想要系统学习基本随机过程的学生来说&#xff0c;可以参考Sheldon M.Rose编著的经典著作《随机过程》。该书涉及的内容也比较宽泛。但并不局限于单个细节论证。 此外&#xff0c;萨缪尔科林(…

Vulnhub靶机之reven 1

一、信息收集 nmap扫描网段&#xff0c;靶机地址为192.168.145.129。 nmap -sP 192.168.145.* 扫一下端口&#xff0c;开放了22、80、111、50967。 nmap -sT -T4 -p1-65535 192.168.145.129 再看一下目录情况&#xff0c;发现一个疑似后台登录的地址。 dirsearch -u http://…

DeepSeek-7B-chat 4bits量化 Qlora 微调

在本文中我们将学习DeepSeek量化微调的方法&#xff0c;并且从微调结果体会大模型微调的重要性。 引言 在当前快速发展的自然语言处理领域&#xff0c;模型的精度和效率是关键。量化和微调技术可以有效提高模型性能。本文将探讨如何对DeepSeek-7B-chat模型进行4bits量化&…

Linux | buildrootfs 添加mkfs.ext3/mkfs.ext4 支持

因个人需要&#xff0c;mkfs.ext3 但是项目中还没有这个命令 所以琢磨了半天 这里将其小记一下 在buildrootfsz中&#xff0c;需要将e2fsprogs 勾选上然后重新编译就好了 make menuconfig Target packages-> Filesystem and flash utilities-> e2fsprogs

stm32编写Modbus步骤

1. modbus协议简介&#xff1a; modbus协议基于rs485总线&#xff0c;采取一主多从的形式&#xff0c;主设备轮询各从设备信息&#xff0c;从设备不主动上报。 日常使用都是RTU模式&#xff0c;协议帧格式如下所示&#xff1a; 地址 功能码 寄存器地址 读取寄存器…

springCloudAlibaba之分布式事务组件---seata

Seata Sea学习分布式事务Seata二阶段提交协议AT模式 Sea学习 事务&#xff1a;事务是访问数据库并更新数据库中各项数据的一个程序执行单元。在关系数据库中&#xff0c;一个事务由一组或多组SQL语句组成。事务应该具有4个属性&#xff1a;原子性、一致性、隔离性、持久性。例如…