|
511 | 511 | chat_action as chat_action_handler, |
512 | 512 | ) |
513 | 513 | from open_webui.utils.embeddings import generate_embeddings |
514 | | -from open_webui.utils.middleware import process_chat_payload, process_chat_response |
| 514 | +from open_webui.utils.middleware import ( |
| 515 | + build_chat_response_context, |
| 516 | + process_chat_payload, |
| 517 | + process_chat_response, |
| 518 | +) |
515 | 519 | from open_webui.utils.access_control import has_access |
516 | 520 |
|
517 | 521 | from open_webui.utils.auth import ( |
@@ -1379,9 +1383,9 @@ async def check_url(request: Request, call_next): |
1379 | 1383 | # Fallback to cookie token for browser sessions |
1380 | 1384 | if request.state.token is None and request.cookies.get("token"): |
1381 | 1385 | from fastapi.security import HTTPAuthorizationCredentials |
| 1386 | + |
1382 | 1387 | request.state.token = HTTPAuthorizationCredentials( |
1383 | | - scheme="Bearer", |
1384 | | - credentials=request.cookies.get("token") |
| 1388 | + scheme="Bearer", credentials=request.cookies.get("token") |
1385 | 1389 | ) |
1386 | 1390 |
|
1387 | 1391 | request.state.enable_api_keys = app.state.config.ENABLE_API_KEYS |
@@ -1456,9 +1460,7 @@ async def inspect_websocket(request: Request, call_next): |
1456 | 1460 | app.include_router( |
1457 | 1461 | evaluations.router, prefix="/api/v1/evaluations", tags=["evaluations"] |
1458 | 1462 | ) |
1459 | | -app.include_router( |
1460 | | - analytics.router, prefix="/api/v1/analytics", tags=["analytics"] |
1461 | | -) |
| 1463 | +app.include_router(analytics.router, prefix="/api/v1/analytics", tags=["analytics"]) |
1462 | 1464 | app.include_router(utils.router, prefix="/api/v1/utils", tags=["utils"]) |
1463 | 1465 |
|
1464 | 1466 | # SCIM 2.0 API for identity management |
@@ -1746,9 +1748,11 @@ async def process_chat(request, form_data, user, metadata, model): |
1746 | 1748 | except: |
1747 | 1749 | pass |
1748 | 1750 |
|
1749 | | - return await process_chat_response( |
1750 | | - request, response, form_data, user, metadata, model, events, tasks |
| 1751 | + ctx = build_chat_response_context( |
| 1752 | + request, form_data, user, model, metadata, tasks, events |
1751 | 1753 | ) |
| 1754 | + |
| 1755 | + return await process_chat_response(response, ctx) |
1752 | 1756 | except asyncio.CancelledError: |
1753 | 1757 | log.info("Chat processing was cancelled") |
1754 | 1758 | try: |
|
0 commit comments