Skip to content

Commit aa0e797

Browse files
committed
perf: add debug msg
1 parent bf13397 commit aa0e797

5 files changed

Lines changed: 50 additions & 3 deletions

File tree

backend/open_webui/routers/openai.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import hashlib
33
import json
44
import logging
5+
import time
56
from typing import Optional
67

78
import aiohttp
@@ -488,6 +489,7 @@ async def get_filtered_models(models, user):
488489
)
489490
async def get_all_models(request: Request, user: UserModel) -> dict[str, list]:
490491
log.info("get_all_models()")
492+
t1 = time.time()
491493

492494
if not request.app.state.config.ENABLE_OPENAI_API:
493495
return {"data": []}
@@ -548,6 +550,9 @@ def get_merged_models(model_lists):
548550
models = get_merged_models(map(extract_data, responses))
549551
log.debug(f"models: {models}")
550552

553+
t2 = time.time()
554+
delta = round(t2 - t1, 2)
555+
log.debug(f"OpenAI get_all_models() took {delta}s")
551556
request.app.state.OPENAI_MODELS = models
552557
return {"data": list(models.values())}
553558

@@ -939,6 +944,7 @@ async def generate_chat_completion(
939944
trust_env=True, timeout=aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT)
940945
)
941946

947+
t1 = time.time()
942948
r = await session.request(
943949
method="POST",
944950
url=request_url,
@@ -947,6 +953,9 @@ async def generate_chat_completion(
947953
cookies=cookies,
948954
ssl=AIOHTTP_CLIENT_SESSION_SSL,
949955
)
956+
t2 = time.time()
957+
delta = round(t2 - t1, 2)
958+
log.debug(f"OpenAI request session.request() took {delta}s")
950959

951960
# Check if response is SSE
952961
if "text/event-stream" in r.headers.get("Content-Type", ""):

backend/open_webui/utils/middleware.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,16 @@ def get_tools_function_calling_payload(messages, task_model_id, content):
338338
)
339339

340340
try:
341+
t1 = time.time()
341342
response = await generate_chat_completion(request, form_data=payload, user=user)
343+
t2 = time.time()
344+
delta = round(t2 - t1, 2)
345+
log.debug(f"Chat completion tools handler took {delta}s")
342346
log.debug(f"{response=}")
343347
content = await get_content_from_response(response)
348+
t3 = time.time()
349+
delta = round(t3 - t2, 2)
350+
log.debug(f"Get content from response took {delta}s")
344351
log.debug(f"{content=}")
345352

346353
if not content:
@@ -383,6 +390,7 @@ async def tool_call_handler(tool_call):
383390
if k in allowed_params
384391
}
385392

393+
t4 = time.time()
386394
if tool.get("direct", False):
387395
tool_result = await event_caller(
388396
{
@@ -399,6 +407,9 @@ async def tool_call_handler(tool_call):
399407
else:
400408
tool_function = tool["callable"]
401409
tool_result = await tool_function(**tool_function_params)
410+
t5 = time.time()
411+
delta = round(t5 - t4, 2)
412+
log.info(f"Tool {tool_function_name} took {delta}s")
402413

403414
except Exception as e:
404415
tool_result = str(e)
@@ -437,7 +448,7 @@ async def tool_call_handler(tool_call):
437448
)
438449

439450
print(
440-
f"Tool {tool_function_name} result: {tool_result}",
451+
f"Tool {tool_function_name}",
441452
tool_result_files,
442453
tool_result_embeds,
443454
)

backend/open_webui/utils/models.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import asyncio
44
import sys
5+
import copy
56

67
from aiocache import cached
78
from fastapi import Request
@@ -78,9 +79,25 @@ async def get_all_base_models(request: Request, user: UserModel = None):
7879

7980

8081
async def get_all_models(request, refresh: bool = False, user: UserModel = None):
82+
t1 = time.time()
83+
84+
# Early return if cached final result exists and cache is enabled
8185
if (
8286
request.app.state.MODELS
83-
and request.app.state.BASE_MODELS
87+
and request.app.state.config.ENABLE_BASE_MODELS_CACHE
88+
and not refresh
89+
):
90+
# Convert cached dict to list format with deep copy and return immediately
91+
# This avoids all expensive processing below (lines 107-337)
92+
models = [copy.deepcopy(model) for model in request.app.state.MODELS.values()]
93+
log.debug(f"get_all_models() returned {len(models)} models from cache")
94+
t2 = time.time()
95+
log.debug(f"get_all_models() took {t2 - t1} seconds (cached)")
96+
return models
97+
98+
# Continue with full processing if cache miss or refresh requested
99+
if (
100+
request.app.state.BASE_MODELS
84101
and (request.app.state.config.ENABLE_BASE_MODELS_CACHE and not refresh)
85102
):
86103
base_models = request.app.state.BASE_MODELS
@@ -323,6 +340,8 @@ def get_function_module_by_id(function_id):
323340
log.debug(f"get_all_models() returned {len(models)} models")
324341

325342
request.app.state.MODELS = {model["id"]: model for model in models}
343+
t2 = time.time()
344+
log.debug(f"get_all_models() took {t2 - t1} seconds")
326345
return models
327346

328347

src/lib/components/chat/Chat.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2307,7 +2307,7 @@
23072307
_chatId = chat.id;
23082308
await chatId.set(_chatId);
23092309
2310-
window.history.replaceState(history.state, '', `/c/${_chatId}`);
2310+
window.history.replaceState(history.state, '', `/kael/c/${_chatId}`);
23112311
23122312
await tick();
23132313

vite.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export default defineConfig({
2929
},
3030
server: {
3131
port: 5173,
32+
watch: {
33+
// Exclude backend files from triggering HMR reloads
34+
ignored: [
35+
'**/backend/**',
36+
'**/backend/open_webui/jms/data/**',
37+
'**/*.cast'
38+
]
39+
},
3240
proxy: {
3341
'^/kael/api/': {
3442
target: 'http://localhost:8083',

0 commit comments

Comments
 (0)