This project demonstrates how to expose a Haystack Agent through an OpenAI-compatible API using Hayhooks.
- agent_deployment: Directory containing deployment files for Hayhooks:
- pipeline_wrapper.py: Implements the OpenAI-compatible API with both streaming and non-streaming support
The agent is accessible through an OpenAI-compatible chat completions API:
curl -X POST "http://localhost:1416/v1/chat/completions" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "How is the weather in London?"}],
"stream": true
}'
curl -X POST "http://localhost:1416/v1/chat/completions" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "How is the weather in London?"}],
"stream": false
}'
-
Make sure you have Haystack and Hayhooks installed:
pip install haystack-ai hayhooks
-
Run the start script to deploy the agent:
./start.sh
-
In a separate terminal, send requests to the API endpoint as shown above.
The implementation:
- Uses Haystack's Agent with the SerperDevWebSearch tool
- Exposes the agent through Hayhooks' OpenAI-compatible interface
- Supports both streaming and non-streaming responses
- Deploys the pipeline with name 'gpt-4o-mini' which is used as the model name in API requests
- Hayhooks requires a file named
pipeline_wrapper.py
that implements theBasePipelineWrapper
interface - The pipeline name must match the model name in OpenAI API requests
- The wrapper class must implement
run_chat_completion
method for OpenAI compatibility - Streaming responses are handled by the
streaming_generator
helper provided by Hayhooks - Non-streaming responses are formatted to match the OpenAI API response format