集成 NeMo Guardrails#

NeMo Guardrails 使用 LangChain ChatNVIDIA 连接器来连接到本地运行的 NIM 微服务,例如 Llama 3.1 NemoGuard 8B TopicControl NIM。 主题控制微服务在 v1/completionsv1/chat/completions 端点上公开标准的 OpenAI 接口。

NeMo Guardrails 简化了构建提示模板、解析主题控制模型响应的复杂性,并提供了一种可编程的方法来构建具有内容安全护栏的聊天机器人。

要将 NeMo Guardrails 与主题控制微服务集成,请创建一个类似于以下示例的 config.yml 文件

models:
  - type: main
    engine: openai
    model: gpt-3.5-turbo-instruct

  - type: "topic_control"
    engine: nim
    parameters:
      base_url: "http://127.0.0.1:8000/v1"
      model_name: "llama-3.1-nemoguard-8b-topic-control"

rails:
  input:
    flows:
      - topic safety check input $model=topic_control
  • 字段 engine 指定 nim

  • 字段 parameters.base_url 指定 Llama 3.1 NemoGuard 8B TopicControl NIM 主机的 IP 地址和端口。

  • Guardrails 配置中的字段 parameters.model_name 必须与 Llama 3.1 NemoGuard 8B TopicControl NIM 提供的模型名称匹配。

  • rails 定义将 topic_control 指定为模型。

有关配置文件的更多信息,请参阅 NVIDIA NeMo Guardrails 文档。