[GH-ISSUE #15981] feat: Smart Model Router with Dynamic Rule-Based Routing and Optional Fallback #33269

Closed
opened 2026-04-25 07:11:39 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @ips972 on GitHub (Jul 24, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/15981

Check Existing Issues

  • I have searched the existing issues and discussions.

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

Originally created by @ips972 on GitHub (Jul 24, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/15981 ### Check Existing Issues - [x] I have searched the existing issues and discussions. ### 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](https://github.com/user-attachments/files/21405578/example.code.txt)
Author
Owner

@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).

<!-- gh-comment-id:3113209542 --> @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).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#33269