Skip to content

Commit b10b310

Browse files
committed
perf: update models for common user
1 parent 38257bb commit b10b310

9 files changed

Lines changed: 29 additions & 23 deletions

File tree

backend/open_webui/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,8 @@ def feishu_oauth_register(oauth: OAuth):
10981098
"key": "",
10991099
"config": {
11001100
"enable": True,
1101-
"access_control": None
1101+
"access_control": None,
1102+
"require_admin": True
11021103
},
11031104
"spec_type": "url",
11041105
"spec": "",

backend/open_webui/env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,14 @@ def parse_section(section):
525525
# MODELS
526526
####################################
527527

528-
MODELS_CACHE_TTL = os.environ.get("MODELS_CACHE_TTL", "1")
528+
MODELS_CACHE_TTL = os.environ.get("MODELS_CACHE_TTL", "30")
529529
if MODELS_CACHE_TTL == "":
530530
MODELS_CACHE_TTL = None
531531
else:
532532
try:
533533
MODELS_CACHE_TTL = int(MODELS_CACHE_TTL)
534534
except Exception:
535-
MODELS_CACHE_TTL = 1
535+
MODELS_CACHE_TTL = 30
536536

537537
####################################
538538
# CHAT

backend/open_webui/models/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def get_models_by_user_id(
216216
]
217217

218218
def get_model_by_id(self, id: str) -> Optional[ModelModel]:
219+
return None
219220
try:
220221
with get_db() as db:
221222
model = db.get(Model, id)

backend/open_webui/routers/tools.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ async def get_tools(request: Request, user=Depends(get_verified_user)):
9696

9797
# MCP Tool Servers
9898
for server in request.app.state.config.TOOL_SERVER_CONNECTIONS:
99+
require_admin = server.get("config", {}).get("require_admin", False)
100+
if require_admin and user.role != "admin":
101+
continue
102+
99103
if server.get("type", "openapi") == "mcp":
100104
server_id = server.get("info", {}).get("id")
101105
auth_type = server.get("auth_type", "none")

backend/open_webui/utils/access_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def has_access(
110110
type: str = "write",
111111
access_control: Optional[dict] = None,
112112
user_group_ids: Optional[Set[str]] = None,
113-
strict: bool = True,
113+
strict: bool = False,
114114
) -> bool:
115115
if access_control is None:
116116
if strict:

backend/open_webui/utils/models.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
DEFAULT_ARENA_MODEL,
2828
)
2929

30-
from open_webui.env import BYPASS_MODEL_ACCESS_CONTROL, SRC_LOG_LEVELS, GLOBAL_LOG_LEVEL
30+
from open_webui.env import BYPASS_MODEL_ACCESS_CONTROL, SRC_LOG_LEVELS, GLOBAL_LOG_LEVEL, MODELS_CACHE_TTL
3131
from open_webui.models.users import UserModel
3232

3333

@@ -58,6 +58,10 @@ async def fetch_openai_models(request: Request, user: UserModel = None):
5858
return openai_response["data"]
5959

6060

61+
@cached(
62+
ttl=MODELS_CACHE_TTL,
63+
key=lambda _, user: f"all_base_models_{user.id}" if user else "all_base_models",
64+
)
6165
async def get_all_base_models(request: Request, user: UserModel = None):
6266
openai_task = (
6367
fetch_openai_models(request, user)
@@ -356,9 +360,11 @@ def check_model_access(user, model):
356360
):
357361
raise Exception("Model not found")
358362
else:
359-
model_info = Models.get_model_by_id(model.get("id"))
363+
# model_info = Models.get_model_by_id(model.get("id"))
364+
model_info = None
360365
if not model_info:
361-
raise Exception("Model not found")
366+
return True
367+
# raise Exception("Model not found")
362368
elif not (
363369
user.id == model_info.user_id
364370
or has_access(
@@ -395,10 +401,13 @@ def get_filtered_models(models, user):
395401
or has_access(
396402
user.id,
397403
type="read",
404+
strict=False,
398405
access_control=model_info.access_control,
399406
)
400407
):
401408
filtered_models.append(model)
409+
else:
410+
filtered_models.append(model)
402411

403412
return filtered_models
404413
else:

src/app.html

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,12 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="icon" type="image/png" href="/kael/static/favicon.png" crossorigin="use-credentials" />
6-
<link
7-
rel="icon"
8-
type="image/png"
9-
href="/kael/static/favicon-96x96.png"
10-
sizes="96x96"
11-
crossorigin="use-credentials"
12-
/>
135
<link
146
rel="icon"
157
type="image/svg+xml"
168
href="/kael/static/favicon.svg"
179
crossorigin="use-credentials"
1810
/>
19-
<link rel="shortcut icon" href="/kael/static/favicon.ico" crossorigin="use-credentials" />
20-
<link
21-
rel="apple-touch-icon"
22-
sizes="180x180"
23-
href="/kael/static/apple-touch-icon.png"
24-
crossorigin="use-credentials"
25-
/>
2611
<link rel="manifest" href="/kael/manifest.json" crossorigin="use-credentials" />
2712
<meta
2813
name="viewport"

src/lib/components/chat/ModelSelector/Selector.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
console.log('Items: ');
338338
console.log(items);
339339
340-
if (!selectedModel) {
340+
if (!selectedModel && items.length > 0) {
341341
selectedModel = items[0];
342342
value = selectedModel.value;
343343
}

src/lib/components/layout/Sidebar.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,12 @@
12401240
}}
12411241
/>
12421242
{/each}
1243+
1244+
{#if $chats.length === 0 && !chatListLoading}
1245+
<div class="w-full flex justify-center py-1 text-xs items-center gap-2">
1246+
<div class=" ">{$i18n.t('No chats found')}</div>
1247+
</div>
1248+
{/if}
12431249

12441250
{#if $scrollPaginationEnabled && !allChatsLoaded}
12451251
<Loader

0 commit comments

Comments
 (0)