refactor(modelmgr): simplify model sync logic and remove timeout configuration

This commit is contained in:
huanghuoguoguo
2026-05-17 10:23:29 +08:00
parent 948591d439
commit 423fa0f942
2 changed files with 1 additions and 29 deletions

View File

@@ -1,6 +1,5 @@
from __future__ import annotations
import asyncio
import sqlalchemy
import traceback
@@ -56,21 +55,7 @@ class ModelManager:
return
try:
sync_timeout = float(space_config.get('models_sync_timeout', 10))
except (TypeError, ValueError):
sync_timeout = 10
try:
self.ap.logger.info('Syncing new models from LangBot Space...')
if sync_timeout > 0:
await asyncio.wait_for(self.sync_new_models_from_space(), timeout=sync_timeout)
else:
await self.sync_new_models_from_space()
self.ap.logger.info('LangBot Space model sync completed.')
except asyncio.TimeoutError:
self.ap.logger.warning(
f'LangBot Space model sync timed out after {sync_timeout:g}s, skipping startup sync.'
)
await self.sync_new_models_from_space()
except Exception as e:
self.ap.logger.warning('Failed to sync new models from LangBot Space, model list may not be updated.')
self.ap.logger.warning(f' - Error: {e}')
@@ -88,9 +73,6 @@ class ModelManager:
)
for provider in providers_result.all():
try:
self.ap.logger.info(
f'Loading model provider {provider.uuid} ({provider.name}, requester={provider.requester})...'
)
runtime_provider = await self.load_provider(provider)
self.provider_dict[provider.uuid] = runtime_provider
except provider_errors.RequesterNotFoundError as e:
@@ -145,14 +127,6 @@ class ModelManager:
except Exception as e:
self.ap.logger.error(f'Failed to load model {rerank_model.uuid}: {e}\n{traceback.format_exc()}')
self.ap.logger.info(
'Loaded models from db: '
f'{len(self.provider_dict)} providers, '
f'{len(self.llm_models)} llm models, '
f'{len(self.embedding_models)} embedding models, '
f'{len(self.rerank_models)} rerank models.'
)
async def sync_new_models_from_space(self):
"""Sync models from Space"""
space_model_provider = await self.ap.persistence_mgr.execute_async(

View File

@@ -112,6 +112,4 @@ space:
# OAuth authorization page URL (user will be redirected here)
oauth_authorize_url: 'https://space.langbot.app/auth/authorize'
disable_models_service: false
# Max seconds to wait for startup model-list sync. Set to 0 to disable the timeout.
models_sync_timeout: 10
disable_telemetry: false