Prompt Security 集成#

Prompt Security AI 允许您保护 LLM 交互。此集成使 NeMo Guardrails 能够使用 Prompt Security 来保护输入和输出流。

您需要设置以下环境变量才能使用 Prompt Security

  1. PS_PROTECT_URL - 这是 Prompt Security 提供的保护端点 URL。它将类似于 https://[REGION].prompt.security/api/protect,其中 REGION 为 eu、useast 或 apac

  2. PS_APP_ID - 这是 Prompt Security 提供的应用程序 ID(类似于 API 密钥)。您可以从管理门户 https://[REGION].prompt.security/ 获取,其中 REGION 为 eu、useast 或 apac

设置#

  1. 确保您有权访问 Prompt Security API 服务器(SaaS 或本地部署)。

  2. 更新您的 config.yml 文件以包含 Private AI settings

rails:
  input:
    flows:
      - protect prompt
  output:
    flows:
      - protect response

不要忘记设置 PS_PROTECT_URLPS_APP_ID 环境变量。

使用方法#

配置完成后,Prompt Security 集成将自动执行以下操作

  1. 在提示由 LLM 处理之前进行保护。

  2. 在 LLM 输出发送回用户之前进行保护。

nemoguardrails/library/prompt_security/actions.py 中的 protect_text action 处理保护过程。

错误处理#

如果 Prompt Security API 请求失败,它将以“开门”模式运行(不阻止提示/响应)。

注意#

有关 Prompt Security 及其功能的更多信息,请参阅Prompt Security 文档