[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)&…

使用Spring Boot设计对象存储系统

对象存储系统是一种以对象为存储单位的存储架构&#xff0c;适合存储大量非结构化数据&#xff0c;如图片、音视频文件、文档等。MinIO是一个高性能的对象存储系统&#xff0c;基于开源和云原生的设计理念。本文将讨论如何使用Spring Boot设计一个类似MinIO的对象存储系统。 目…

Day17—JavaScript与Ajax请求分析

Ajax(Asynchronous JavaScript and XML)是一种在不重新加载整个页面的情况下,能够与服务器交换数据并更新部分网页的技术。随着Web应用的广泛使用,Ajax请求已成为动态网页数据加载的常见方式。在爬虫中处理JavaScript动态加载的数据,需要对Ajax请求有深入的理解。 1. Aja…

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

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

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

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

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

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

MoreTable 方法selectWithFun,count 使用实例

ORM Bee, example for MoreTable methods:selectWithFun,count ORM Bee时, MoreTable 方法selectWithFun,count 使用实例 package org.teasoft.exam.bee.osql;import org.teasoft.bee.osql.BeeException; import org.teasoft.bee.osql.FunctionType; import org.teasoft.be…

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脚本将视频抽帧为图像数据集

AI应用开发相关目录 本专栏包括AI应用开发相关内容分享&#xff0c;包括不限于AI算法部署实施细节、AI应用后端分析服务相关概念及开发技巧、AI应用后端应用服务相关概念及开发技巧、AI应用前端实现路径及开发技巧 适用于具备一定算法及Python使用基础的人群 AI应用开发流程概…

程序猿大战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;共同进步。 在学术写…

【ai】Audio2Face简介

Audio2Face 简介 FACEGOODAudio2Face是英伟达Omniverse平台的一部分,它使用先进的AI技术来生成基于音频输入的逼真面部动画。这个技术主要利用深度学习模型来解析人声,进而驱动一个三维模型的面部表情。下面是Audio2Face工作流程的详细说明: 预备阶段 在使用Audio2Face之前,…

Java基础 - Stream流操作

Stream将要处理的元素集合看作一种流&#xff0c;在流的过程中&#xff0c;借助Stream API对流中的元素进行操作&#xff0c;比如&#xff1a;筛选、排序、聚合等。 Stream流操作 遍历/匹配&#xff08;foreach、find、match&#xff09; List<Integer> list Arrays.…

二叉树最大宽度

文章目录 前言二叉树最大宽度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…

44.SQLserver中 DATEFROMPARTS() 函数的语法

1.基本语法&#xff1a; DATEFROMPARTS(year, month, day) 2.SQL参数 该函数接受三个参数&#xff0c;具体描述如下&#xff1a; year - 一个整数值&#xff0c;指定日期的’YEAR’部分&#xff0c;表示为整数。 month - 一个整数值&#xff0c;指定日期的’MONTH’部分。 day…

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…