Skip to content

v1.7.0

Choose a tag to compare

@mpangrazzi mpangrazzi released this 26 Nov 14:21
98ed986

✨ New Features

Streaming Responses from /run Endpoint

Now you can stream results directly from the generic /run API endpoint. Previously, streaming was only available through OpenAI-compatible endpoints like /chat/completion. Now you can return a generator from run_api() or run_api_async() and Hayhooks will automatically wrap it in a FastAPI StreamingResponse.

from collections.abc import Generator
from hayhooks import streaming_generator

def run_api(self, query: str) -> Generator:
    return streaming_generator(
        pipeline=self. pipeline,
        pipeline_run_args={"prompt": {"query": query}},
    )

For async pipelines:

from collections.abc import AsyncGenerator
from hayhooks import async_streaming_generator

async def run_api_async(self, query: str) -> AsyncGenerator:
    return async_streaming_generator(
        pipeline=self. pipeline,
        pipeline_run_args={"prompt": {"query": query}},
    )
Method What you return Response media type Notes
run_api() generator / streaming_generator(... ) text/plain Works out of the box with existing clients (CLI, curl).
run_api_async() async generator / async_streaming_generator(...) text/plain Same payload as sync version, emitted from an async task.
Either SSEStream(...) around the generator text/event-stream Opt-in Server-Sent Events with automatic frame wrapping.

SSE (Server-Sent Events) Support

New SSEStream wrapper class for opting into Server-Sent Events format (text/event-stream) instead of plain text streaming:

from hayhooks import SSEStream, streaming_generator

def run_api(self, query: str):
    return SSEStream(
        streaming_generator(
            pipeline=self.pipeline,
            pipeline_run_args={"prompt": {"query": query}},
        )
    )

For async pipelines:

from hayhooks import SSEStream, async_streaming_generator

async def run_api_async(self, query: str):
    return SSEStream(
        async_streaming_generator(
            pipeline=self.pipeline,
            pipeline_run_args={"prompt": {"query": query}},
        )
    )

External Event Queue Support

Both streaming_generator and async_streaming_generator now support an optional external_event_queue parameter. This allows you to inject custom events (dict, OpenWebUIEvent, str, or StreamingChunk) into the streaming output alongside pipeline chunks.

Typical Use Case: Passing the queue to pipeline components that need to emit events during execution—for example, a Human-in-the-Loop (HITL) confirmation strategy that pushes approval request events to the queue while waiting for user input.

CLI Streaming Mode

New --stream / -s flag for the hayhooks pipeline run command to display tokens as they arrive in real-time:

hayhooks pipeline run my_pipeline --stream --param question="What is Redis?"

Note: Streaming mode is not supported with file uploads. If files are provided with --stream, a warning will be shown and the pipeline will run without streaming.

📚 Documentation & Examples

  • Added new run_api_streaming example demonstrating streaming from the /run endpoint
  • Updated documentation with comprehensive guides for:
    • Streaming responses from run_api() and run_api_async()
    • SSE streaming configuration
    • External event queue usage

What's Changed

Full Changelog: v1.6.0...v1.7.0