Hayhooks
Hayhooks 使其易于部署和服务 干草堆 管道 和 代理.
使用Hayhooks,您可以:
- 📦 将Haystack管道和代理部署为REST API 具有最大的灵活性和最少的样板代码。
- 💬 将您的Haystack管道和代理与 开放网页界面 因为OpenAI兼容的聊天完成后端支持流媒体。
- 🖥️ 嵌入a Chainlit 聊天界面 直接在Hayhooks
pip install "hayhooks[chainlit]"和hayhooks run --with-chainlit--具有流媒体、管道选择和自定义UI小部件的零配置前端。 - 📈 使用OpenTetry跟踪Hayhooks生命周期操作 (
pip install "hayhooks[tracing]")用于跨REST和MCP的部署/运行/取消部署可见性,具有/dashboardUI通过hayhooks run --with-tracing-dashboard(由本地实时跟踪缓冲区支持)。
](https://pypi.org/project/hayhooks) ](https://pypi.org/project/hayhooks) ](https://github.com/deepset-ai/hayhooks/actions/workflows/docker.yml) 
文档
📚 有关详细指南、示例和API参考,请查看我们的 全面的文件.
快速开始
1.安装Hayhooks
# Install Hayhooks
pip install hayhooks2.启动Hayhooks
hayhooks run3.创建一个简单的代理
创建一个具有流式聊天支持和简单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
# Define a Haystack Tool that provides weather information for a given location.
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],
)
# This will create a POST /my_agent/run endpoint
# `question` will be the input argument and will be auto-validated by a Pydantic model
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
# This will create an OpenAI-compatible /chat/completions endpoint
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_dir5.运行它
调用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用户界面 (hayhooks run --with-chainlit)或 将其与Open WebUI集成!
主要特点
🚀 轻松部署
- 以最少的设置将Haystack管道和代理部署为REST API
- 支持基于YAML和基于包装器的管道部署
- 自动生成与OpenAI兼容的端点
🌐 多种集成选项
- MCP协议:将管道作为MCP工具公开,用于人工智能开发环境
- 链式UI:具有流媒体、管道选择和自定义UI小部件的嵌入式聊天前端
- 打开WebUI集成:使用Hayhooks作为具有流媒体支持的Open WebUI的后端
- OpenAI兼容性:与OpenAI兼容的工具和框架无缝集成
🔧 开发者友好
- CLI,便于管道管理
- 灵活的配置选项
- 全面的日志记录和调试支持
- 基于Haystack跟踪API构建的OpenTetry就绪跟踪挂钩
- 自定义路由和中间件支持
📁 文件上传支持
- 内置支持处理管道中的文件上传
- 非常适合RAG系统和文档处理
接下来的步骤
社区与支持
- GitHub: deepset ai/hayhooks
- 问题:
- 文档: 全部文件
Hayhooks由 深陷的 团队。
