[Llama3] ReAct Prompt 测试实验

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 questionBegin!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 canyou 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 questionBegin!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 questionBegin!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 questionBegin!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 questionBegin!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 questionBegin!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 questionBegin!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 questionBegin!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 idTo 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 questionBegin!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 questionBegin!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 questionBegin!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.mzph.cn/bicheng/25479.shtml

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

相关文章

quick4 - hackmyvm

简介 靶机名称&#xff1a;quick4 难度&#xff1a;简单 靶场地址&#xff1a;https://hackmyvm.eu/machines/machine.php?vmQuick4 本地环境 虚拟机&#xff1a;vitual box 靶场IP&#xff08;quick4&#xff09;&#xff1a;192.168.56.104 跳板机IP(windows 11)&…

推荐三款你不知道的良心软件

Tico——抠图、拼图软件 抠图软件大家见过很多了把&#xff0c;但是从多张图片中抠出来的图片拼接成一张图片你们很少见过吧。 Tico就是一款将抠出来的图片拼接成一张新图片的软件&#xff0c;目前仅支持IOS平台。 Tico拼贴图提供了强大的图像编辑和处理功能&#xff0c;用户…

论文降痕指南:如何有效降低AIGC率

随着 AI 技术迅猛发展&#xff0c;各种AI辅助论文写作的工具层出不穷&#xff01; 为了防止有人利用AI工具进行论文代写&#xff0c;在最新的学位法中已经明确规定“已经获得学位者&#xff0c;在获得该学位过程中如有人工智能代写等学术不端行为&#xff0c;经学位评定委员会…

连续状态方程的离散化例子

连续状态方程的离散化 在控制系统中,连续状态方程的离散化是一个重要的步骤,用于将连续时间系统转换为离散时间系统,以便在数字控制器中实现。这通常涉及将连续时间的微分方程转换为离散时间的差分方程。常用的离散化方法 前向欧拉法(Forward Euler)简单易实现,但精度较…

ssm615基于ssm的房源管理系统+vue【已测试】

前言&#xff1a;&#x1f469;‍&#x1f4bb; 计算机行业的同仁们&#xff0c;大家好&#xff01;作为专注于Java领域多年的开发者&#xff0c;我非常理解实践案例的重要性。以下是一些我认为有助于提升你们技能的资源&#xff1a; &#x1f469;‍&#x1f4bb; SpringBoot…

312. 戳气球 Hard

有 n 个气球&#xff0c;编号为0 到 n - 1&#xff0c;每个气球上都标有一个数字&#xff0c;这些数字存在数组 nums 中。 现在要求你戳破所有的气球。戳破第 i 个气球&#xff0c;你可以获得 nums[i - 1] * nums[i] * nums[i 1] 枚硬币。 这里的 i - 1 和 i 1 代表和 i 相邻…

程序猿大战Python——pycharm软件的使用

基础配置 目标&#xff1a;了解PyCharm软件的基础配置处理。 修改背景颜色&#xff1a; Appearance -> Theme 修改字体大小&#xff1a; 搜索font -> Font 例如&#xff0c;一起完成背景、字体大小的修改。 总结&#xff1a; &#xff08;1&#xff09;如果要对PyChar…

专业场景化ChatGPT论文润色提示词指令,更精准、更有效辅助学术论文撰写

大家好&#xff0c;感谢关注。我是七哥&#xff0c;一个在高校里不务正业&#xff0c;折腾学术科研AI实操的学术人。可以添加我&#xff08;yida985&#xff09;交流学术写作或ChatGPT等AI领域相关问题&#xff0c;多多交流&#xff0c;相互成就&#xff0c;共同进步。 在学术写…

二叉树最大宽度

文章目录 前言二叉树最大宽度1.题目解析2.算法原理3.代码编写 总结 前言 二叉树最大宽度 1.题目解析 给你一棵二叉树的根节点 root &#xff0c;返回树的 最大宽度 。 树的 最大宽度 是所有层中最大的 宽度 。 每一层的 宽度 被定义为该层最左和最右的非空节点&#xff08;即…

商城项目【尚品汇】08异步编排

文章目录 1.线程的创建方式1.1继承Thread类&#xff0c;重写run方法1.2实现Runnable接口&#xff0c;重写run方法。1.3实现Callable接口&#xff0c;重新call方法1.4以上三种总结1.5使用线程池创建线程1.5.1线程池创建线程的方式1.5.2线程池的七大参数含义1.5.3线程池的工作流程…

Java面向对象-[封装、继承、多态、权限修饰符]

Java面向对象-封装、继承、权限修饰符 一、封装1、案例12、案例2 二、继承1、案例12、总结 三、多态1、案例 四、权限修饰符1、private2、default3、protected4、public 一、封装 1、案例1 package com.msp_oop;public class Girl {private int age;public int getAge() {ret…

Redis系列-5 Redis分布式锁

背景&#xff1a; 本文介绍Redis分布式锁的内容&#xff0c;包括Redis相关命令和Lua脚本的介绍&#xff0c;以及操作分布式锁的流程与消息&#xff0c;最后结合Redission源码介绍分布式锁的实现原理。 1.基本命令 1.1 基本键值对的设置 设值: set key value 取值: get key …

SPI通信协议

SPI通信结介绍 W25Q64是一个Flash存储器芯片&#xff0c;内部可以存储8M字节的数据&#xff0c;并且是掉电不丢失的。 四根通信线&#xff1a;SCK&#xff08;Serial Clock&#xff09;串行时钟线、MOSI&#xff08;Master Output Slave Input&#xff09;主机输出从机输入、M…

【十大排序算法】快速排序

在乱序的世界中&#xff0c;快速排序如同一位智慧的园丁&#xff0c; 以轻盈的手法&#xff0c;将无序的花朵们重新安排&#xff0c; 在每一次比较中&#xff0c;沐浴着理性的阳光&#xff0c; 终使它们在有序的花园里&#xff0c;开出绚烂的芬芳。 文章目录 一、快速排序二、…

profile-3d-contrib,github三维立体图的使用

图片展示: 提示: 这个profile-3d-contrib存储库有时候会出现问题,导致又有使用这个存储库svg的用户显示出现问题. 参考: https://zhuanlan.zhihu.com/p/681786778 原仓库链接&#xff1a; GitHub - yoshi389111/github-profile-3d-contrib: This GitHub Action creates a Gi…

【算法刷题 | 动态规划08】6.9(单词拆分、打家劫舍、打家劫舍||)

文章目录 21.单词拆分21.1题目21.2解法&#xff1a;动规21.2.1动规思路21.2.2代码实现 22.打家劫舍22.1题目22.2解法&#xff1a;动规22.2.1动规思路22.2.2代码实现 23.打家劫舍||23.1题目23.2解法&#xff1a;动规23.2.1动规思路23.2.2代码实现 21.单词拆分 21.1题目 给你一…

java中的异常-异常处理(try、catch、finally、throw、throws)+自定义异常

一、概述 1、java程序员在编写程序时提前编写好对异常的处理程序&#xff0c;在程序发生异常时就可以执行预先设定好的处理程序&#xff0c;处理程序执行完之后&#xff0c;可以继续向后执行后面的程序 2、异常处理程序是在程序执行出现异常时才执行的 二、5个关键字 1、tr…

Redis实战篇02

1.分布式锁Redisson 简单介绍&#xff1a; 使用setnx可能会出现的极端问题&#xff1a; Redisson的简介&#xff1a; 简单的使用&#xff1a; 业务代码的改造&#xff1a; private void handleVoucherOrder(VoucherOrder voucherOrder) {Long userId voucherOrder.getUserI…

2024真机项目

项目需求&#xff1a; 1. 172.25.250.101 主机上的 Web 服务要求提供 www.exam.com 加密站点&#xff0c;该站点在任何路由可达 的主机上被访问&#xff0c;页面内容显示为 "Hello&#xff0c;Welcome to www.exam.com !"&#xff0c;并提供 content.exam.com/yum/A…

数据:人工智能的基石 | Scale AI 创始人兼 CEO 亚历山大·王的创业故事与行业洞见

引言 在人工智能领域&#xff0c;数据被誉为“新石油”&#xff0c;其重要性不言而喻。随着GPT-4的问世&#xff0c;AI技术迎来了新的浪潮。众多年轻创业者纷纷投身这一领域&#xff0c;Scale AI的创始人兼CEO亚历山大王&#xff08;Alexander Wang&#xff09;就是其中的佼佼…