发布
在TaskWeaver中,post是一个数据概念,表示对话中的单条消息。
@dataclass
class Post:
"""
A post is the message used to communicate between two roles.
It should always have a text_message to denote the string message,
while other data formats should be put in the attachment.
The role can be either a User, a Planner, or others.
Args:
id: the unique id of the post.
send_from: the role who sends the post.
send_to: the role who receives the post.
message: the text message in the post.
attachment_list: a list of attachments in the post.
"""
id: str
send_from: RoleName
send_to: RoleName
message: str
attachment_list: List[Attachment]
帖子是用于两个角色之间通信的消息。它始终应包含一个文本message来表示字符串消息。
此外,帖子具有send_from和send_to角色,分别表示发送和接收帖子的角色。
在某些情况下,send_from和send_to角色相同,表示角色的自我通信。
attachment_list是一个包含帖子中附件的列表。附件用于存储除文本消息外的各种数据,例如代码片段或工件文件路径。附件可能仅供发送帖子的角色使用,也可能供接收帖子的角色使用。
通常情况下,message会作为历史对话轮次出现在提示词中。
但有时消息可能过长,应当仅保留在当前轮次。
下一轮对话时,该消息将从提示词中删除以保持简洁。
例如,代码解释器可能生成冗长的执行结果,这些结果只需在当前轮次保留。
针对这种情况,我们提供了一种标注方式,可以指定消息(或部分消息)仅保留在当前轮次。
message = PromptUtil.wrap_text_with_delimiter(message, delimiter=PromptUtil.DELIMITER_TEMPORAL)
通过这种方式,消息将仅保留在当前轮次,从下一轮开始不会出现在提示中。