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

集成:Weights & Biases Weave Tracer

将 Haystack 跟踪发送到 Weights & Biases 进行监控和可视化

作者
deepset

目录

概述

此集成允许您使用 Weights & Biases Weave 框架 来跟踪和监控 Haystack 管道组件。它提供了一个连接器,用于将 Haystack 跟踪发送到 Weights & Biases 进行监控和可视化。

安装

pip install weave-haystack

使用

组件

此集成引入了一个新组件,一个名为 WeaveConnector 的连接器,其唯一职责是将跟踪发送到 Weights & Biases。

请注意,您需要将 WANDB_API_KEY 环境变量设置为您的 Weights & Biases API 密钥。

注意:如果您没有 Weights & Biases 帐户,它将与您交互式地要求您设置一个,然后您的输入将存储在 ~/.netrc 中

此外,您需要将 HAYSTACK_CONTENT_TRACING_ENABLED 环境变量设置为 true,以便在您的管道中启用 Haystack 跟踪。

要使用此连接器,只需将其添加到管道中,无需任何连接,它将自动开始将跟踪发送到 Weights & Biases。

import os

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

from haystack_integrations.components.connectors.weave import WeaveConnector

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

pipe = Pipeline()
pipe.add_component("prompt_builder", ChatPromptBuilder(template=messages))
pipe.add_component("llm", OpenAIChatGenerator(model="gpt-4o-mini"))
pipe.connect("prompt_builder.prompt", "llm.messages")

connector = WeaveConnector(pipeline_name="test_pipeline")
pipe.add_component("weave", connector)

response = pipe.run(
    data={
        "prompt_builder": {
            "location": "Berlin"
        }
    }
)
print(response["llm"]["replies"][0])

然后,您应该访问 https://wandb.ai/<user_name>/projects,并在创建 WeaveConnector 时指定的管道名称下查看管道的完整跟踪。

许可证

weights_biases-haystack 根据 Apache-2.0 许可的条款分发。