mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-09 10:50:35 -06:00
[GH-ISSUE #15981] feat: Smart Model Router with Dynamic Rule-Based Routing and Optional Fallback #33269
Reference in New Issue
Block a user
Originally created by @ips972 on GitHub (Jul 24, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/15981
Check Existing Issues
Problem Description
Summary
I’d like to propose an enhancement to Open WebUI: a Smart Model Router filter that routes user queries to the most appropriate LLM backend model based on the content of the query. It uses dynamic keyword-based rules, supports custom descriptions, and has a fallback mechanism if no rule matches.
This gives users and developers the ability to route queries intelligently, improving performance, cost-efficiency, and UX.
Desired Solution you'd like
What It Does
Analyzes user input with configurable keyword-based rules.
Dynamically routes the request to the most appropriate model (e.g. codellama:7b for code, llama2:13b for project planning).
Fallback to a default model when no rules match.
Supports unlimited rules, priority modes (first_match, best_match), case-sensitivity, and keyword thresholds.
Optional UI Integration: Select model manually from dropdown or auto-route based on rule match.
Example Use Case
User query:
“How do I build a REST API with Flask?”
Smart Router:
Matches keywords: build, API, Flask
Routes to: codellama:7b
or any of the other modes configured in the list per subject.
If no rule matched → routes to default model (e.g. llama3:8b)
Technical Highlights
Fully refactored using pydantic models (RouterConfig, Rule)
Enables unlimited rules (via config list rather than hardcoded 5)
Easily pluggable into inlet() and outlet() filters
Debug mode prints matched rule, selected model, and keywords
Optimized for clean integration in Open WebUI’s existing plugin system
Benefits
Smarter model selection without hardcoding use cases
Can be controlled by both backend config and frontend dropdown UI
Reduces token usage by picking specialized, smaller models when possible
Open to future enhancements like model suggestions, weightings, or even user feedback scoring
Alternatives Considered
No response
Additional Context
example code i game chatGPT and claud to try and create.
the amount of subject entries and their coresponding models should be flexible, starting with 1 defaul, and have '+' sign to add more options.. as needed for the amount of models created in "wrokspaces" or in backend apis.
example code.txt
@Ithanil commented on GitHub (Jul 24, 2025):
Not saying that this wouldn't be nice as core feature, but, for your information, something like this is possible via Filters and does exist, e.g. https://openwebui.com/f/haervwe/semantic_router_filter (didn't try that one yet, tbh).