Filter Functions execute arbitrary Python code on your server. Function creation is restricted to administrators only. Only install from trusted sources and review code before importing. A malicious Function could access your file system, exfiltrate data, or compromise your entire system. For full details, see the Plugin Security Warning.
๐ช Filter Function: Modify Inputs and Outputs
Welcome to the comprehensive guide on Filter Functions in Open WebUI! Filters are a flexible and powerful plugin system for modifying data before it's sent to the Large Language Model (LLM) (input) or after itโs returned from the LLM (output). Whether youโre transforming inputs for better context or cleaning up outputs for improved readability, Filter Functions let you do it all.
This guide will break down what Filters are, how they work, their structure, and everything you need to know to build powerful and user-friendly filters of your own. Letโs dig in, and donโt worryโIโll use metaphors, examples, and tips to make everything crystal clear! ๐
๐ What Are Filters in Open WebUI?โ
Imagine Open WebUI as a stream of water flowing through pipes:
- User inputs and LLM outputs are the water.
- Filters are the water treatment stages that clean, modify, and adapt the water before it reaches the final destination.
Filters sit in the middle of the flowโlike checkpointsโwhere you decide what needs to be adjusted.
Hereโs a quick summary of what Filters do:
- Modify User Inputs (Inlet Function): Tweak the input data before it reaches the AI model. This is where you enhance clarity, add context, sanitize text, or reformat messages to match specific requirements.
- Intercept Model Outputs (Stream Function): Capture and adjust the AIโs responses as theyโre generated by the model. This is useful for real-time modifications, like filtering out sensitive information or formatting the output for better readability.
- Modify Model Outputs (Outlet Function): Adjust the AI's response after itโs processed, before showing it to the user. This can help refine, log, or adapt the data for a cleaner user experience.
Key Concept: Filters are not standalone models but tools that enhance or transform the data traveling to and from models.
Filters are like translators or editors in the AI workflow: you can intercept and change the conversation without interrupting the flow.