Prompt Templates#
关于 Prompt Templates#
Llama 3.1 NemoGuard 8B TopicControl NIM 执行输入审核,例如确保用户 prompt 与系统 prompt 中指定的规则一致。
Prompt 模板由两个关键部分组成:系统指令 和 对话历史,其中包括一系列用户 prompt 和 LLM 响应。通常,prompt 以当前用户查询结束。
系统指令#
Prompt 的系统指令部分充当引导对话的综合指南。这部分包括以下内容
- 核心规则
一套用于管理交互的原则,以确保相关性并遵守任何指定的边界。
- 角色分配
使模型能够采用特定角色,例如银行助理。在这种情况下
默认情况下,角色领域之外的查询被视为离题。
您可以指定要在角色范围内阻止的子类别或主题。例如,可以指示银行助理阻止诸如加密货币或保险索赔之类的主题。
主题控制模型使用这些指令来确定用户查询是否符合定义的规则。
系统 prompt 必须以 TOPIC_SAFETY_OUTPUT_RESTRICTION 字符串结尾。这确保了模型预测是 “on-topic” 或 “off-topic”。TOPIC_SAFETY_OUTPUT_RESTRICTION 字符串定义如下
If any of the above conditions are violated, please respond with "off-topic". Otherwise, respond with "on-topic". You must respond with "on-topic" or "off-topic".
对话历史#
对话历史记录维护用户 prompt 和 LLM 响应的顺序记录,并且可以包括单轮或多轮交互。通常,历史记录以最新的用户 prompt 结束,该 prompt 必须由主题控制模型审核。
请参考以下行业标准有效负载格式的用户到 LLM 对话示例
[
{
"role": "system",
"content": "In the next conversation always use a polite tone and do not engage in any talk about travelling and touristic destinations",
},
{
"role": "user",
"content": "Hi there!",
},
{
"role": "assistant",
"content": "Hello! How can I help today?",
},
{
"role": "user",
"content": "Do you know which is the most popular beach in Barcelona?",
},
]
主题控制模型以类似 off-topic
的响应来响应最终用户 prompt。