From 50dff552175ad2e904067fee0d965fccf6c76460 Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Sat, 31 Jan 2026 13:24:33 +0800 Subject: [PATCH] feat: enhance LLM model creation with optional default pipeline setting - Updated create_llm_model method to include auto_set_to_default_pipeline parameter. - Adjusted ModelManager to set auto_set_to_default_pipeline to False when creating models. - Improved logic for setting the default pipeline model based on the new parameter. --- src/langbot/pkg/api/http/service/model.py | 27 ++++++++++--------- src/langbot/pkg/provider/modelmgr/modelmgr.py | 1 + 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/langbot/pkg/api/http/service/model.py b/src/langbot/pkg/api/http/service/model.py index e3184de4..15d31f6e 100644 --- a/src/langbot/pkg/api/http/service/model.py +++ b/src/langbot/pkg/api/http/service/model.py @@ -64,7 +64,9 @@ class LLMModelsService: models = result.all() return [self.ap.persistence_mgr.serialize_model(persistence_model.LLMModel, m) for m in models] - async def create_llm_model(self, model_data: dict, preserve_uuid: bool = False) -> str: + async def create_llm_model( + self, model_data: dict, preserve_uuid: bool = False, auto_set_to_default_pipeline: bool = True + ) -> str: """Create a new LLM model""" if not preserve_uuid: model_data['uuid'] = str(uuid.uuid4()) @@ -95,18 +97,19 @@ class LLMModelsService: ) self.ap.model_mgr.llm_models.append(runtime_llm_model) - # set the default pipeline model to this model - result = await self.ap.persistence_mgr.execute_async( - sqlalchemy.select(persistence_pipeline.LegacyPipeline).where( - persistence_pipeline.LegacyPipeline.is_default == True + if auto_set_to_default_pipeline: + # set the default pipeline model to this model + result = await self.ap.persistence_mgr.execute_async( + sqlalchemy.select(persistence_pipeline.LegacyPipeline).where( + persistence_pipeline.LegacyPipeline.is_default == True + ) ) - ) - pipeline = result.first() - if pipeline is not None and pipeline.config['ai']['local-agent']['model'] == '': - pipeline_config = pipeline.config - pipeline_config['ai']['local-agent']['model'] = model_data['uuid'] - pipeline_data = {'config': pipeline_config} - await self.ap.pipeline_service.update_pipeline(pipeline.uuid, pipeline_data) + pipeline = result.first() + if pipeline is not None and pipeline.config['ai']['local-agent']['model'] == '': + pipeline_config = pipeline.config + pipeline_config['ai']['local-agent']['model'] = model_data['uuid'] + pipeline_data = {'config': pipeline_config} + await self.ap.pipeline_service.update_pipeline(pipeline.uuid, pipeline_data) return model_data['uuid'] diff --git a/src/langbot/pkg/provider/modelmgr/modelmgr.py b/src/langbot/pkg/provider/modelmgr/modelmgr.py index 41b401de..bd70ce61 100644 --- a/src/langbot/pkg/provider/modelmgr/modelmgr.py +++ b/src/langbot/pkg/provider/modelmgr/modelmgr.py @@ -149,6 +149,7 @@ class ModelManager: 'prefered_ranking': space_model.featured_order, }, preserve_uuid=True, + auto_set_to_default_pipeline=False, ) elif space_model.category == 'embedding':