OA0
OA0 是一个探索 AI 的社区
现在注册
已注册用户请  登录
OA0  ›  代码  ›  Hayhooks — 为 Haystack 工作流提供事件与扩展能力

Hayhooks — 为 Haystack 工作流提供事件与扩展能力

 
  gratitude ·  2026-03-21 18:10:20 · 10 次点击  · 0 条评论  

Hayhooks

Hayhooks 让部署和提供 Haystack 管道智能体 变得简单。

使用 Hayhooks,你可以:

  • 📦 将 Haystack 管道和智能体部署为 REST API,获得最大灵活性并减少样板代码。
  • 🛠️ 通过 MCP 协议暴露你的 Haystack 管道和智能体,使它们能在 CursorClaude Desktop 等 AI 开发环境中作为工具使用。Hayhooks 在底层作为 MCP 服务器 运行,将每个管道和智能体暴露为 MCP 工具
  • 💬 将你的 Haystack 管道和智能体与 Open WebUI 集成,作为支持流式传输的 OpenAI 兼容聊天补全后端。
  • 🖥️ 在 Hayhooks 中直接嵌入 Chainlit 聊天界面,只需 pip install "hayhooks[chainlit]"hayhooks run --with-chainlit —— 这是一个零配置的前端,支持流式传输、管道选择和自定义 UI 组件。
  • 🕹️ 通过聊天控制 Hayhooks 核心 API 端点 —— 通过与 Claude DesktopCursor 或任何其他 MCP 客户端聊天,来部署、卸载、列出或运行 Haystack 管道和智能体。

PyPI - 版本
PyPI - Python 版本
Docker 镜像发布
测试

文档

📚 查看详细的指南、示例和 API 参考,请访问我们的 完整文档

快速开始

1. 安装 Hayhooks

# 安装 Hayhooks
pip install hayhooks

2. 启动 Hayhooks

hayhooks run

3. 创建一个简单的智能体

创建一个支持流式聊天和简单 HTTP POST API 的最小智能体包装器:

from typing import AsyncGenerator
from haystack.components.agents import Agent
from haystack.dataclasses import ChatMessage
from haystack.tools import Tool
from haystack.components.generators.chat import OpenAIChatGenerator
from hayhooks import BasePipelineWrapper, async_streaming_generator


# 定义一个提供给定位置天气信息的 Haystack 工具。
def weather_function(location):
    return f"The weather in {location} is sunny."

weather_tool = Tool(
    name="weather_tool",
    description="Provides weather information for a given location.",
    parameters={
        "type": "object",
        "properties": {"location": {"type": "string"}},
        "required": ["location"],
    },
    function=weather_function,
)

class PipelineWrapper(BasePipelineWrapper):
    def setup(self) -> None:
        self.agent = Agent(
            chat_generator=OpenAIChatGenerator(model="gpt-4o-mini"),
            system_prompt="You're a helpful agent",
            tools=[weather_tool],
        )

    # 这将创建一个 POST /my_agent/run 端点
    # `question` 将是输入参数,并将由 Pydantic 模型自动验证
    async def run_api_async(self, question: str) -> str:
        result = await self.agent.run_async(messages=[ChatMessage.from_user(question)])
        return result["last_message"].text

    # 这将创建一个 OpenAI 兼容的 /chat/completions 端点
    async def run_chat_completion_async(
        self, model: str, messages: list[dict], body: dict
    ) -> AsyncGenerator[str, None]:
        chat_messages = [
            ChatMessage.from_openai_dict_format(message) for message in messages
        ]

        return async_streaming_generator(
            pipeline=self.agent,
            pipeline_run_args={
                "messages": chat_messages,
            },
        )

保存为 my_agent_dir/pipeline_wrapper.py

4. 部署它

hayhooks pipeline deploy-files -n my_agent ./my_agent_dir

5. 运行它

调用 HTTP POST API (/my_agent/run):

curl -X POST http://localhost:1416/my_agent/run \
  -H 'Content-Type: application/json' \
  -d '{"question": "What can you do?"}'

调用 OpenAI 兼容的聊天补全 API(启用流式传输):

curl -X POST http://localhost:1416/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "my_agent",
    "messages": [{"role": "user", "content": "What can you do?"}]
  }'

或者在 嵌入式 Chainlit UI (hayhooks run --with-chainlit) 中与它聊天,或者 将其与 Open WebUI 集成

主要特性

🚀 轻松部署

  • 以最少的设置将 Haystack 管道和智能体部署为 REST API
  • 支持基于 YAML 和基于包装器的管道部署
  • 自动生成 OpenAI 兼容的端点

🌐 多种集成选项

  • MCP 协议:将管道暴露为 MCP 工具,供 AI 开发环境使用
  • Chainlit UI:嵌入式聊天前端,支持流式传输、管道选择和自定义 UI 组件
  • Open WebUI 集成:将 Hayhooks 用作支持流式传输的 Open WebUI 后端
  • OpenAI 兼容性:与 OpenAI 兼容的工具和框架无缝集成

🔧 开发者友好

  • 用于轻松管理管道的 CLI
  • 灵活的配置选项
  • 全面的日志记录和调试支持
  • 自定义路由和中间件支持

📁 文件上传支持

  • 内置支持在管道中处理文件上传
  • 非常适合 RAG 系统和文档处理

后续步骤

社区与支持

Hayhooks 由 deepset 团队积极维护。

10 次点击  ∙  0 人收藏  
登录后收藏  
0 条回复
关于 ·  帮助 ·  PING ·  隐私政策 ·  服务条款   
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
耗时 16 ms
Developed with Cursor