Filters for Open WebUI that handle context management and response formatting.
Cleans up the message history before it reaches the LLM.
-
Timestamp injection: Fetches real timestamps from the Open WebUI API and prepends them to historical messages; injects the current date and time into the latest message.
-
History trimming: Keeps only the last
Nmessages (default:50) to reduce token usage. -
Image pruning: Strips image attachments from older messages so text-only models (e.g., DeepSeek R1) do not process multimodal chat history unnecessarily.
-
Token optimization: Disabled by default. Removes filler words (e.g., "just", "really", "very") from user messages while preserving code blocks, Markdown formatting, and quotes. This reduces token counts without sacrificing critical information.
| Valve | Default | Description |
|---|---|---|
priority |
0 |
Execution order (higher equals later execution). |
n_last_messages |
50 |
Messages to keep (user and assistant each count as 1). |
ignore_images_after_n_messages |
10 |
Strip images from messages older than this (0 strips all). |
api_base_url |
http://127.0.0.1:8080 |
Open WebUI API base URL. |
inject_system_instructions |
True |
Adds a system prompt explaining the timestamp format to the LLM. |
enable_token_optimizer |
False |
Toggles filler-word removal. |
min_words_to_optimize |
60 |
Skips optimization below this word count. |
max_words_to_optimize |
2000 |
Skips optimization above this word count. |
optimize_current_only |
True |
Only optimizes the latest message. |
Requires httpx>=0.24.0 (included in the default Open WebUI Docker image).
Injects system-level instructions that push the LLM toward concise, structured output.
- Sets a soft target word count (default:
240). - Enforces bold-caps headers and bullet lists.
- Suppresses preambles (e.g., "As an AI") and filler phrases (e.g., "Certainly!").
| Valve | Default | Description |
|---|---|---|
priority |
0 |
Execution order (higher equals later execution). |
target_word_count |
240 |
Soft word-count target; the model can exceed it when accuracy requires. |
No extra dependencies are required.
Requirements: Open WebUI v0.8.4 or higher.
- Navigate to Admin Panel β Functions β Import From Link.
- Paste the preferred raw URL:
https://raw.githubusercontent.com/fractuscontext/openwebui-filters/main/filters/token_saver.pyhttps://raw.githubusercontent.com/fractuscontext/openwebui-filters/main/filters/concise_output.py
- Enable the filter.
Copy and paste the code from the respective filter files directly into the Open WebUI Admin Panel.
MIT License