Skip to content

Commit f3a6bb0

Browse files
authored
Add specific README for events example (#141)
1 parent 2d784ca commit f3a6bb0

File tree

1 file changed

+90
-0
lines changed
  • examples/pipeline_wrappers/open_webui_agent_events

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Open WebUI Agent Events Example
2+
3+
This example demonstrates how to enhance the chat experience in [Open WebUI](https://github.com/open-webui/open-webui) by emitting **events** from a Haystack `Agent` pipeline executed through **Hayhooks**.
4+
5+
The heart of the example is `pipeline_wrapper.py`, which
6+
7+
1. Instantiates a Haystack `Agent` backed by an `OpenAIChatGenerator`.
8+
2. Implements `run_chat_completion_async` that yields an **async generator** mixing
9+
streaming chunks with Open WebUI event objects.
10+
3. Sends two `status` events – one when the pipeline starts and another when it
11+
finishes.
12+
4. Emits an HTML-like `<details>` block with extra information once the run is
13+
complete.
14+
15+
When you invoke the pipeline from Open WebUI you will see:
16+
17+
* A "Running the pipeline!" banner while the agent thinks.
18+
* The answer streamed token by token.
19+
* A "Pipeline completed!" success banner.
20+
* An expandable section labelled *Pipeline completed!* containing additional
21+
details.
22+
23+
## Folder structure
24+
25+
```text
26+
pipeline_wrapper.py # Pipeline implementation
27+
README.md # You are reading it
28+
```
29+
30+
No additional dependencies are required besides `hayhooks` (which already pulls
31+
Haystack).
32+
33+
## Quick start
34+
35+
Create and activate a virtual environment (optional but recommended):
36+
37+
```shell
38+
python -m venv .venv
39+
source .venv/bin/activate
40+
```
41+
42+
Install Hayhooks:
43+
44+
```shell
45+
pip install hayhooks
46+
```
47+
48+
Launch Hayhooks:
49+
50+
```shell
51+
hayhooks run
52+
# The server will listen on http://localhost:1416
53+
```
54+
55+
Deploy the pipeline wrapper:
56+
57+
```shell
58+
hayhooks pipeline deploy-files -n agent_events .
59+
```
60+
61+
Open *Open WebUI**Settings**Connections* and add a **Remote Hayhooks
62+
server** pointing to `http://localhost:1416` (no API key is needed).
63+
64+
Start a new chat, select the *agent_events* pipeline and ask any question.
65+
66+
## Supported Open WebUI events
67+
68+
Hayhooks exposes convenience helpers in `hayhooks.open_webui` to build all event
69+
kinds supported by Open WebUI. You can yield these objects (or plain strings)
70+
from your pipeline generator to control the UI in real time.
71+
72+
| Helper function | `type` value | Purpose / UI effect |
73+
|-----------------|--------------|------------------------------------------------|
74+
| `create_status_event` | `status` | Show progress indicator (`description`, `done`, `hidden`). |
75+
| `create_chat_completion_event` | `chat:completion` | Send a full chat-completion payload (usually not needed manually). |
76+
| `create_message_event` | `message` | Append content to the current assistant message. |
77+
| `create_replace_event` | `replace` | Replace the entire assistant message content. |
78+
| `create_source_event` | `source` | Attach citations, code results or other rich blocks. |
79+
| `create_notification_event` | `notification` | Display toast notifications (`info`, `success`, `warning`, `error`). |
80+
| `create_details_tag`* | *(string)* | Render an expandable `<details>` block (not a real event). |
81+
82+
\* `create_details_tag` returns raw markup – Open WebUI recognises it and adds a
83+
collapsible section to the chat.
84+
85+
For a deeper explanation of every event see the official
86+
[Open WebUI event documentation](https://docs.openwebui.com/features/plugin/events).
87+
88+
---
89+
90+
Feel free to extend the wrapper and experiment with other event types!

0 commit comments

Comments
 (0)