自定义示例
目前有两种类型的示例:(1) 规划器示例和(2)代码解释器示例。 规划示例用于展示规划器应如何为用户的具体查询制定计划。 代码生成示例用于帮助代码解释器生成代码或协调插件来执行特定任务。
这两种类型的示例实际上是多个角色之间的对话,例如用户(User)、规划者(Planner)和代码解释器(CodeInterpreter)。 每次对话包含一个或多个回合,每个回合都有一个用户查询并包含一个或多个帖子。 帖子是一个角色发送给另一个角色的消息,可能包含一些附件。
一个示例如下所示:
enabled: True
rounds:
- User_query: ping
state: created
post_list:
- message: ping
send_from: User
send_to: Planner
attachment_list: []
- message: pong
send_from: Planner
send_to: User
attachment_list: []
我们特意将所有示例分为两种类型,只是为了便于理解和维护。 当角色初始化时,每个角色只会读取其对应类型的示例。
示例中的所有文本字段(如消息)均采用Markdown格式。
规划器示例
规划示例向大语言模型展示如何针对用户的特定查询进行规划,与代码解释器交互,接收代码解释器的执行结果,并对执行结果进行总结。
以下是用户、规划器(Planner)和代码解释器(CodeInterpreter)之间的对话示例。 这个示例的目的之一是教导规划器如何标注计划步骤之间的依赖关系。 另一个目的是教导规划器遵循正确的输出格式。
enabled: True
rounds:
- User_query: count the rows of /home/data.csv
state: created
post_list:
- message: count the rows of /home/data.csv
send_from: User
send_to: Planner
attachment_list:
- message: Please load the data file /home/data.csv and count the rows of the loaded data
send_from: Planner
send_to: CodeInterpreter
attachment_list:
- type: init_plan
content: |-
1. load the data file
2. count the rows of the loaded data <sequentially depends on 1>
3. report the result to the User <interactively depends on 2>
- type: plan
content: |-
1. instruct CodeInterpreter to load the data file and count the rows of the loaded data
2. report the result to the User
- type: current_plan_step
content: 1. instruct CodeInterpreter to load the data file and count the rows of the loaded data
- message: Load the data file /home/data.csv successfully and there are 100 rows in the data file
send_from: CodeInterpreter
send_to: Planner
attachment_list:
- message: The data file /home/data.csv is loaded and there are 100 rows in the data file
send_from: Planner
send_to: User
attachment_list:
- type: init_plan
content: |-
1. load the data file
2. count the rows of the loaded data <sequentially depends on 1>
3. report the result to the User <interactively depends on 2>
- type: plan
content: |-
1. instruct CodeInterpreter to load the data file and count the rows of the loaded data
2. report the result to the User
- type: current_plan_step
content: 2. report the result to the User
为了更好地理解包含init_plan、plan和current_plan_step的附件,
请参考Planner's prompt。
在这个例子中,共有4篇文章:
- 第一条消息从用户发送给规划器(Planner)。 消息内容是"统计/home/data.csv文件的行数",必须与用户查询保持一致。
- The second post is sent from the Planner to the CodeInterpreter.
The message is "Please load the data file /home/data.csv and count the rows of the loaded data".
The attachment list contains 3 attachments:
- 第一个附件是初始计划。
- 第二个附件是最终计划。
- 第三个附件是当前的计划步骤。
- 第三条消息从代码解释器发送给规划器。 消息内容是"成功加载数据文件/home/data.csv,该数据文件包含100行记录"。
- 第四条消息由规划器(Planner)发送给用户。 消息内容为"数据文件/home/data.csv已加载,数据文件中共有100行数据"。 附件列表包含3个附件,与第二条消息中的附件相同。
代码解释器示例
一个CodeInterpreter示例告诉CodeInterpreter如何生成代码或编排插件来执行特定任务。该任务始终来自Planner。
本示例的目的是教会CodeInterpreter如何处理执行中的错误。
enabled: True
rounds:
- User_query: read file /abc/def.txt
state: finished
post_list:
- message: read file /abc/def.txt
send_from: Planner
send_to: CodeInterpreter
attachment_list: []
- message: I'm sorry, I cannot find the file /abc/def.txt. An FileNotFoundException has been raised.
send_from: CodeInterpreter
send_to: Planner
attachment_list:
- type: thought
content: "{ROLE_NAME} will generate a code snippet to read the file /abc/def.txt and present the content to the User."
- type: python
content: |-
file_path = "/abc/def.txt"
with open(file_path, "r") as file:
file_contents = file.read()
print(file_contents)
- type: verification
content: CORRECT
- type: code_error
content: No code error.
- type: execution_status
content: FAILURE
- type: execution_result
content: FileNotFoundException, the file /abc/def.txt does not exist.
阅读代码生成的提示语,以更好地理解示例中的附件 code generator prompt。
本次对话包含两条消息:
- 第一条消息由Planner发送给CodeInterpreter。 消息内容是"请读取文件 /abc/def.txt"。
- The second post is sent from the CodeInterpreter to the Planner.
The message is "read file /abc/def.txt".
The attachment list contains 6 attachments:
- 第一个附件是CodeInterpreter的思考过程。
- 第二个附件是生成的代码,使用Python编写。
- 第三个附件是验证状态,可能为CORRECT(正确)、INCORRECT(错误)或NONE(无)。
- 第四个附件是验证错误信息。
- 第五个附件是执行状态,可能是SUCCESS(成功)、FAILURE(失败)或NONE(无)。
- 第六个附件是执行结果,它是一个markdown字符串。
在这个例子中,verification指的是检查生成的代码是否正确。
我们实现了一个模块来验证生成的代码。如果代码存在语法错误,
或者违反了约束条件,验证状态将显示为INCORRECT
并返回一些错误信息。
NONE的验证状态表示代码尚未经过验证,这意味着验证功能已被关闭。
在这个例子中,execution_status表示生成的代码是否能成功执行。
如果执行成功,执行状态将为SUCCESS并返回执行结果。
否则,执行状态将为FAILURE并返回一些错误信息。
当NONE状态时,表示代码尚未被执行。