This repo extends Open WebUI with pluggable Python pipelines and filters. If you’re adding or modifying code, follow these project-specific rules to be productive immediately.
- Two building blocks:
- Pipelines in
pipelines/<provider>/expose aPipewith innerValves(config via env). They list models withpipes()and execute requests inpipe(...)(streaming and non-streaming). - Filters in
filters/expose aFilterwithinlet(body)and/oroutlet(body)to mutate requests/responses.
- Pipelines in
- Secrets are declared as
EncryptedStrin valves and are auto-encrypted on assignment; decrypt only right before use. RequiresWEBUI_SECRET_KEYin Open WebUI. - Status/events: emit via
__event_emitter__using{type:"status"|"chat:*", data:{...}}. Always send a completion or error status.
- Model IDs are normalized early to avoid provider mismatches:
- Azure: set header
x-ms-model-mesh-model-name(or put model in body whenAZURE_AI_MODEL_IN_BODY=true).pipelines/azure/azure_ai_foundry.pyparses semicolon/comma/space model lists. - Google Gemini: strip prefixes like
models/andpublishers/google/models/viastrip_prefix()and_prepare_model_id().
- Azure: set header
- Streaming rules by provider:
- Azure and N8N stream with SSE (
StreamingResponse); always closeaiohttpClientSession/response infinally(seecleanup_response). - Gemini disables streaming for image-generation models; thinking is wrapped in
<details>and emitted incrementally.
- Azure and N8N stream with SSE (
- Cross-component integration:
- Gemini reads
search_webandfetch_urltools from__metadata__.get("tools", {})to enable grounding tools natively when function calling is enabled. - N8N non-streaming responses can append a tool-calls section built by
_format_tool_calls_sectionwith verbosity and truncation valves.
- Gemini reads
- Use Pixi tasks for quality:
- Format:
pixi run format - Lint:
pixi run lint(Ruff config inruff.toml)
- Format:
- Fast manual test path: paste a single pipeline/filter into Open WebUI Admin → Functions, set required env (see each
Valves), and call it from a chat. Encryption works onceWEBUI_SECRET_KEYis set. - Useful references when implementing:
- Azure pipeline: citations handling and SSE in
pipelines/azure/azure_ai_foundry.py - Gemini pipeline: model caching, image optimization/upload, grounding in
pipelines/google/google_gemini.py - N8N pipeline: mixed stream parsing and tool display in
pipelines/n8n/n8n.py - Filters:
filters/time_token_tracker.py,filters/google_search_tool.py
- Azure pipeline: citations handling and SSE in
- Validate and filter inputs (keep an explicit allow-list of request fields).
- Emit status at start, on streaming start, and on completion/error.
- Avoid blocking I/O in async paths; prefer
aiohttp/aiofiles. - Close network resources when not streaming; set SSE headers in streaming responses.
- Keep valve names stable; add new ones with backward-compatible defaults.