📘 **TELUS Agriculture & Consumer Goods** 如何通过 **Haystack Agents** 转变促销交易

集成:Opik

使用 Opik 跟踪和评估您的 Haystack 管道

作者
Comet ML

目录

概述

Opik 是一个开源工具,可帮助您跟踪、评估和监控您的 LLM 应用程序。通过 Opik 平台,您可以

  • 调试您的管道
  • 使用诸如幻觉或上下文相关性之类的内置指标自动评估您的管道
  • 跟踪管道运行的延迟和成本
  • 在生产环境中监控您的管道

您可以在 Opik 的 Haystack 集成指南 中了解有关 Haystack 和 Opik 集成的更多信息。

安装

要使用 Opik 与 Haystack 的集成,请安装 opik

pip install opik haystack-ai

使用

要使用 Opik,您需要

  1. 通过将环境变量 HAYSTACK_CONTENT_TRACING_ENABLED 设置为 True 来启用 Haystack 中的内容跟踪
  2. OpikConnector 添加到您的管道

下面显示了一个使用 Opik 的示例管道

# Enable content tracing
import os
os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"

from haystack import Pipeline
from haystack.components.builders import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage

from opik.integrations.haystack import OpikConnector


pipe = Pipeline()

# Add the OpikConnector component to the pipeline
pipe.add_component(
    "tracer", OpikConnector("Chat example")
)

# Continue building the pipeline
pipe.add_component("prompt_builder", ChatPromptBuilder())
pipe.add_component("llm", OpenAIChatGenerator(model="gpt-3.5-turbo"))

pipe.connect("prompt_builder.prompt", "llm.messages")

OpikConnector 组件将自动跟踪管道并将其记录在 Opik 中。它还将增强响应,包含一个 tracer 键,其中包含 Opik traceId

messages = [
    ChatMessage.from_system(
        "Always respond in German even if some input data is in other languages."
    ),
    ChatMessage.from_user("Tell me about {{location}}"),
]

response = pipe.run(
    data={
        "prompt_builder": {
            "template_variables": {"location": "Berlin"},
            "template": messages,
        }
    }
)

print(response)

Opik Gif

许可证

Opik 是完全开源的,并根据 Apache-2.0 许可证分发。