第 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-38m或deberta-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 生成或文本分类,或两者都部署在命名空间中。
流程
在 YAML 文件中定义
ConfigMap对象,以指定chat_generation和detectors服务。例如,使用以下内容创建一个名为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部署
orchestrator_cm.yaml配置映射:$ oc apply -f orchestrator_cm.yaml -n <TEST_NAMESPACE>指定在
GuardrailsOrchestrator自定义资源(CR)中创建的之前创建的ConfigMap对象。例如,使用以下内容创建名为orchestrator_cr.yaml的文件:orchestrator_cr.yamlCR 示例apiVersion: trustyai.opendatahub.io/v1alpha1 kind: GuardrailsOrchestrator metadata: name: gorch-sample spec: orchestratorConfig: "fms-orchestr8-config-nlp" replicas: 1部署编配器 CR,在命名空间中创建服务帐户、部署、服务和路由对象:
oc apply -f orchestrator_cr.yaml -n <TEST_NAMESPACE>
验证
确认编配器和 LLM pod 正在运行:
$ oc get pods -n <TEST_NAMESPACE>响应示例
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查询编配器路由的
/health端点,以检查检测器和生成器服务的当前状态。如果返回200 OK响应,则服务可以正常工作:$ GORCH_ROUTE_HEALTH=$(oc get routes gorch-test-health -o jsonpath='{.spec.host}')$ curl -v https://$GORCH_ROUTE_HEALTH/health响应示例
* 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"}