第 7 章 配置 Guardrails Orchestrator 服务


TrustyAI Guardrails Orchestrator 服务是一个在文本生成输入和输出中调用检测的工具,以及独立检测。

它被 IBM 的 open-source 项目 FMS-Guardrails Orchestrator 进行固定。您可以通过由 TrustyAI Operator 管理的自定义资源定义(CRD)部署 Guardrails Orchestrator 服务。

您可以将以下检测器与 trustyai_fms 搭配使用:

  • 正则表达式检测 程序:结构化规则强制的基于 Pattern 的内容检测。这些是 Guardrails Orchestrator 服务中的内置检测器。了解有关 guardrails-regex-detector 的更多信息。
  • Hugging Face Detectors :与大多数 Hugging Face AutoModelForSequenceClassification 模型兼容,如 granite-guardian-hap-38mdeberta-v3-base-prompt-injection-v2。了解有关 FMS Guardrails Orchestrator 的检测器算法的更多信息。
  • vLLM Detector Adapter: 与 Hugging Face AutoModelForCausalLM 模型兼容的内容检测,如 ibm-granite/granite-guardian-3.1-2b。了解有关 vllm-detector-adapter 的更多信息。

以下小节介绍了如何部署 Guardrails Orchestrator 并提供示例用例:

  • 部署 Guardrails Orchestrator 实例
  • 将 user-inputs 监视到您的 LLM
  • 配置和使用内置检测器
  • 配置和使用 guardrails 网关
  • 启用 OpenTelemetry 导出器来观察指标和追踪

7.1. 部署 Guardrails Orchestrator 服务

您可以在命名空间中部署一个 Guardrails Orchestrator 实例,以监控元素,如用户输入到您的 Large Language Model (LLM)。

先决条件

  • 具有集群管理员特权。
  • 您已下载并安装 OpenShift 命令行界面 (CLI)。请参阅安装 OpenShift CLI
  • 您熟悉如何创建 configMap 来监控用户定义的工作流。您在此过程中执行类似的步骤。请参阅了解配置映射
  • 您已将 KServe 配置为使用 RawDeployment 模式。如需更多信息,请参阅在 单模式服务平台上部署模型
  • 在 OpenShift AI DataScienceCluster 中将 TrustyAI 组件设置为 Managed
  • 您有一个大型语言模型(LLM),用于 chat 生成或文本分类,或两者都部署在命名空间中。

流程

  1. 在 YAML 文件中定义 ConfigMap 对象,以指定 chat_generationdetectors 服务。例如,使用以下内容创建一个名为 orchestrator_cm.yaml 的文件:

    orchestrator_cm.yaml示例

    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: fms-orchestr8-config-nlp
    data:
      config.yaml: |
        chat_generation: 
    1
    
          service:
            hostname: <CHAT_GENERATION_HOSTNAME>
            port: the generation service port (for example 8033)
    
        detectors:       
    2
    
          regex_language:
            type: text_contents
            service:
                hostname: "127.0.0.1"
                port: 8080
            chunker_id: whole_doc_chunker
            default_threshold: 0.5
          hap:
            type: text_contents
            service:
              hostname: guardrails-detector-ibm-hap-predictor.model-namespace.svc.cluster.local
              port: the generation service port (for example 8000)
            chunker_id: whole_doc_chunker
            default_threshold: 0.5
    Copy to Clipboard Toggle word wrap

    1
    用于聊天生成的服务,引用您添加保护rails的命名空间中部署的 LLM。
    2
    负责在文本 span 上运行特定类型的内容的服务列表。
  2. 部署 orchestrator_cm.yaml 配置映射:

    $ oc apply -f orchestrator_cm.yaml -n <TEST_NAMESPACE>
    Copy to Clipboard Toggle word wrap
  3. 指定在 GuardrailsOrchestrator 自定义资源(CR)中创建的之前创建的 ConfigMap 对象。例如,使用以下内容创建名为 orchestrator_cr.yaml 的文件:

    orchestrator_cr.yaml CR 示例

    apiVersion: trustyai.opendatahub.io/v1alpha1
    kind: GuardrailsOrchestrator
    metadata:
      name: gorch-sample
    spec:
      orchestratorConfig: "fms-orchestr8-config-nlp"
      replicas: 1
    Copy to Clipboard Toggle word wrap

  4. 部署编配器 CR,在命名空间中创建服务帐户、部署、服务和路由对象:

    oc apply -f orchestrator_cr.yaml -n <TEST_NAMESPACE>
    Copy to Clipboard Toggle word wrap

验证

  1. 确认编配器和 LLM pod 正在运行:

    $ oc get pods -n <TEST_NAMESPACE>
    Copy to Clipboard Toggle word wrap

    响应示例

    NAME                                       READY   STATUS    RESTARTS   AGE
    gorch-test-55bf5f84d9-dd4vm                3/3     Running   0          3h53m
    ibm-container-deployment-bd4d9d898-52r5j   1/1     Running   0          3h53m
    ibm-hap-predictor-5d54c877d5-rbdms         1/1     Running   0          3h53m
    llm-container-deployment-bd4d9d898-52r5j   1/1     Running   0          3h53m
    llm-predictor-5d54c877d5-rbdms             1/1     Running   0          57m
    Copy to Clipboard Toggle word wrap

  2. 查询编配器路由的 /health 端点,以检查检测器和生成器服务的当前状态。如果返回 200 OK 响应,则服务可以正常工作:

    $ GORCH_ROUTE_HEALTH=$(oc get routes gorch-test-health -o jsonpath='{.spec.host}')
    Copy to Clipboard Toggle word wrap
    $ curl -v https://$GORCH_ROUTE_HEALTH/health
    Copy to Clipboard Toggle word wrap

    响应示例

    *   Trying ::1:8034...
    * connect to ::1 port 8034 failed: Connection refused
    *   Trying 127.0.0.1:8034...
    * Connected to localhost (127.0.0.1) port 8034 (#0)
    > GET /health HTTP/1.1
    > Host: localhost:8034
    > User-Agent: curl/7.76.1
    > Accept: */*
    >
    * Mark bundle as not supporting multiuse
    < HTTP/1.1 200 OK
    < content-type: application/json
    < content-length: 36
    < date: Fri, 31 Jan 2025 14:04:25 GMT
    <
    * Connection #0 to host localhost left intact
    {"fms-guardrails-orchestr8":"0.1.0"}
    Copy to Clipboard Toggle word wrap

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat