refac
Co-Authored-By: SpootyMcSpoot <6732450+spootymcspoot@users.noreply.github.com>
This commit is contained in:
co-authored by
SpootyMcSpoot
parent
f1a1e64d2e
commit
f20cc6d7e6
@@ -517,6 +517,7 @@ from open_webui.utils.middleware import (
|
|||||||
process_chat_payload,
|
process_chat_payload,
|
||||||
process_chat_response,
|
process_chat_response,
|
||||||
)
|
)
|
||||||
|
from open_webui.utils.tools import set_tool_servers
|
||||||
|
|
||||||
from open_webui.utils.auth import (
|
from open_webui.utils.auth import (
|
||||||
get_license_data,
|
get_license_data,
|
||||||
@@ -656,6 +657,32 @@ async def lifespan(app: FastAPI):
|
|||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Pre-fetch tool server specs so the first request doesn't pay the latency cost
|
||||||
|
if len(app.state.config.TOOL_SERVER_CONNECTIONS) > 0:
|
||||||
|
log.info("Initializing tool servers...")
|
||||||
|
try:
|
||||||
|
mock_request = Request(
|
||||||
|
{
|
||||||
|
"type": "http",
|
||||||
|
"asgi.version": "3.0",
|
||||||
|
"asgi.spec_version": "2.0",
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/internal",
|
||||||
|
"query_string": b"",
|
||||||
|
"headers": Headers({}).raw,
|
||||||
|
"client": ("127.0.0.1", 12345),
|
||||||
|
"server": ("127.0.0.1", 80),
|
||||||
|
"scheme": "http",
|
||||||
|
"app": app,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
await set_tool_servers(mock_request)
|
||||||
|
log.info(
|
||||||
|
f"Initialized {len(app.state.TOOL_SERVERS)} tool server(s)"
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
log.warning(f"Failed to initialize tool servers at startup: {e}")
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
if hasattr(app.state, "redis_task_command_listener"):
|
if hasattr(app.state, "redis_task_command_listener"):
|
||||||
|
|||||||
Reference in New Issue
Block a user