Patronus Lynx 集成#
NeMo Guardrails 支持使用 Patronus AI 的 Lynx 模型检测 RAG 系统中的幻觉。该模型托管在 Hugging Face 上,并提供 70B 参数(参见此处)和 8B 参数(参见此处)两种变体。
Lynx 检查幻觉的三个组成部分
来自
bot_message
的信息包含在relevant_chunks
中bot_message
中没有relevant_chunks
中没有的额外信息bot_message
不与relevant_chunks
中的任何信息相矛盾
设置#
由于 Patronus Lynx 是完全开源的,您可以按您喜欢的方式托管它。您可以在此处找到使用 vLLM 托管 Lynx 的指南。
用法#
以下是如何配置您的机器人以使用 Patronus Lynx 检查机器人输出中的 RAG 幻觉
在
config.yml
中添加一个类型为patronus_lynx
的模型 - 下面的示例使用 vLLM 运行 Lynx
models:
...
- type: patronus_lynx
engine: vllm_openai
parameters:
openai_api_base: "https://:5000/v1"
model_name: "PatronusAI/Patronus-Lynx-70B-Instruct" # "PatronusAI/Patronus-Lynx-8B-Instruct"
将 guardrail 名称
patronus lynx check output hallucination
添加到config.yml
中的输出轨道中
rails:
output:
flows:
- patronus lynx check output hallucination
在
prompts.yml
文件中添加一个patronus_lynx_check_output_hallucination
的提示
prompts:
- task: patronus_lynx_check_output_hallucination
content: |
Given the following QUESTION, DOCUMENT and ANSWER you must analyze ...
...
我们建议您根据此处提供的示例来构建您的 Lynx 幻觉检测提示。
在底层,patronus lynx check output hallucination
轨道运行 patronus_lynx_check_output_hallucination
动作,您可以在此处找到该动作。它返回是否检测到幻觉(True
或 False
),并可能提供解释该决策的推理轨迹。如果检测到幻觉(即 True
),机器人的响应将被阻止。注意:如果 Lynx 的输出配置错误或无法找到幻觉决策,该动作默认返回 True
,表示检测到幻觉。
以下是 patronus lynx check output hallucination
流程,展示了该动作如何执行
define bot inform answer unknown
"I don't know the answer to that."
define flow patronus lynx check output hallucination
$patronus_lynx_response = execute patronus_lynx_check_output_hallucination
$hallucination = $patronus_lynx_response["hallucination"]
# The Reasoning trace is currently unused, but can be used to modify the bot output
$reasoning = $patronus_lynx_response["reasoning"]
if $hallucination
bot inform answer unknown
stop