mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-16 06:03:26 -05:00
[PR #23898] [CLOSED] refactor: extract provider-facing helpers from routers into open_webui.clients #43061
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23898
Author: @ashm-dev
Created: 4/20/2026
Status: ❌ Closed
Base:
dev← Head:refactor/extract-provider-clients📝 Commits (5)
78c772frefactor: add clients package460e3a0refactor: extract pipelines client from router4399ce6refactor: extract memories client from router1fcd87erefactor: extract tasks client from router70a4cdbrefactor: preserve original template fallback semantics📊 Changes
10 files changed (+651 additions, -705 deletions)
View changed files
➕
backend/open_webui/clients/__init__.py(+0 -0)➕
backend/open_webui/clients/memories.py(+173 -0)➕
backend/open_webui/clients/pipelines.py(+136 -0)➕
backend/open_webui/clients/tasks.py(+260 -0)📝
backend/open_webui/routers/memories.py(+30 -162)📝
backend/open_webui/routers/pipelines.py(+12 -172)📝
backend/open_webui/routers/tasks.py(+35 -366)📝
backend/open_webui/tools/builtin.py(+1 -1)📝
backend/open_webui/utils/chat.py(+1 -1)📝
backend/open_webui/utils/middleware.py(+3 -3)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.
Before submitting, make sure you've checked the following:
devbranch. PRs targetingmainwill be immediately closed.devto ensure no unrelated commits (e.g. frommain) are included. Push updates to the existing PR branch instead of closing and reopening.refactor.Changelog Entry
Description
Internal, behavior-preserving refactor. The
utils/layer currently imports FastAPI endpoint-adjacent helpers directly fromrouters/(14 top-level edges; e.g.utils/middleware.pyimportsprocess_pipeline_inlet_filterfromrouters/pipelines.py,query_memoryfromrouters/memories.py, and five task-generation helpers fromrouters/tasks.py). This creates a package-level import cycle (routers ↔ utils) and forces any utility or test to drag in the full FastAPI router module just to call a helper.This PR introduces a new
open_webui.clientspackage and moves the pure (non-HTTP) helpers for pipelines, memories, and tasks into it. The routers become thin FastAPI wrappers that delegate to the client functions. External call sites (utils/middleware,utils/chat,tools/builtin,routers/tasks) are updated to import fromopen_webui.clients.*. No behavior changes — every endpoint URL, everyresponse_model, every Pydantic form, and every error path is preserved.This is the first of a planned series; subsequent PRs will do the same for
images,files,retrieval,ollama,openai. This one is sized to be trivially reviewable on its own and to prove the pattern.Motivation:
utils → routersback-edges (14 of them today) that makeopen_webui/a strongly-connected component at the package level.utils/middleware.py, 5000+ lines) unit-testable without instantiating FastAPI router state.clients/holds "what the code does",routers/holds "how it's exposed over HTTP".Scope of this PR:
backend/open_webui/clients/withpipelines.py,memories.py,tasks.py.pipelines.py,memories.py,tasks.pynow import fromclients/and keep only theirAPIRouter/ HTTP wrapper responsibilities.utils/middleware.py,utils/chat.py,tools/builtin.py,routers/tasks.pyupdated to import helpers fromclients/instead ofrouters/.X | None,list[...],dict[...]). Functional inputs/outputs unchanged.ruff format --checkpasses on all changed files;ruff checkpasses on all changed files.Explicitly out of scope:
images,files,retrieval,ollama,openaiextractions — follow-up PRs, one per provider, to keep each review small.config.pyor decomposition ofutils/middleware.py(separate problems; separate PRs).Added
backend/open_webui/clients/package exposingpipelines,memories, andtaskshelper modules for reuse byutils/andtools/without pulling in FastAPI router state.Changed
backend/open_webui/routers/pipelines.py:get_sorted_filters,process_pipeline_inlet_filter,process_pipeline_outlet_filtermoved toclients/pipelines.py. Endpoints (/list,/upload,/add,/delete,/,/{pipeline_id}/valves,/{pipeline_id}/valves/spec,/{pipeline_id}/valves/update) unchanged.backend/open_webui/routers/memories.py:add_memory,query_memory,update_memory_by_id, and their Pydantic forms (AddMemoryForm,MemoryUpdateModel,QueryMemoryForm) moved toclients/memories.py; router endpoints (GET /,POST /add,POST /query,POST /reset,DELETE /delete/user,POST /{memory_id}/update,DELETE /{memory_id}) become thin delegators.backend/open_webui/routers/tasks.py:generate_title,generate_follow_ups,generate_chat_tags,generate_image_prompt,generate_queriesmoved toclients/tasks.py; endpoints (/title/completions,/follow_up/completions,/tags/completions,/image_prompt/completions,/queries/completions) become thin delegators.generate_autocompletion,generate_emoji,generate_moa_responseintentionally left in the router (not imported byutils/, so no layering win from moving them).backend/open_webui/utils/middleware.py,utils/chat.py,tools/builtin.py: imports redirected fromopen_webui.routers.{pipelines,memories,tasks}→open_webui.clients.{pipelines,memories,tasks}.Deprecated
Removed
Fixed
Security
Breaking Changes
routers.X→clients.X) only for code inside this repository. No external API, URL, or behavior changes. Third-party code that importsfrom open_webui.routers.memories import query_memorywould need to switch tofrom open_webui.clients.memories import query_memory, but no public documentation advertises those as importable fromrouters/.Additional Information
Review ergonomics: every commit is self-contained and bisect-safe.
The final commit is a defensive tweak: an earlier draft replaced
if CFG.TEMPLATE != '': template = CFG.TEMPLATE else: DEFAULTwithtemplate = CFG.TEMPLATE or DEFAULT. These diverge when the config value isNone(original would passNoneto the template renderer and raiseTypeError; shortened form would silently useDEFAULT). The commit restores the exact!= ''form to keep behavior bit-identical.Verification performed:
ruff format --check .— no regressions; my files are clean (8 pre-existing format violations outside my scope left alone).ruff checkon all touched files — passes.open_webui.clients.*back toopen_webui.routers.*(the whole point of the refactor).Related to:
backend/open_webui/shows one 14-file SCC driven byutils ↔ routersback-edges (not a runtime cycle — all guarded by in-function lazy imports with# Import here to avoid circular imports). This PR removes 3 of those 14 top-level edges; follow-ups will address the rest.Screenshots or Videos
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.