fix(agent and model):
1. From the model square to the model list, the added models are initially set to be inactive. When manually activating them, a mandatory API key configuration is required. 2. Copying of applications (agent, workflow, multi_agent)
This commit is contained in:
@@ -371,6 +371,11 @@ def update_model(
|
|||||||
|
|
||||||
if model_data.type is not None or model_data.provider is not None:
|
if model_data.type is not None or model_data.provider is not None:
|
||||||
raise BusinessException("不允许更改模型类型和供应商", BizCode.INVALID_PARAMETER)
|
raise BusinessException("不允许更改模型类型和供应商", BizCode.INVALID_PARAMETER)
|
||||||
|
|
||||||
|
if model_data.is_active:
|
||||||
|
active_keys = ModelApiKeyService.get_api_keys_by_model(db=db, model_config_id=model_id, is_active=model_data.is_active)
|
||||||
|
if not active_keys:
|
||||||
|
raise BusinessException("请先为该模型配置可用的 API Key", BizCode.INVALID_PARAMETER)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
api_logger.debug(f"开始更新模型配置: model_id={model_id}")
|
api_logger.debug(f"开始更新模型配置: model_id={model_id}")
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class ModelConfigBase(BaseModel):
|
|||||||
load_balance_strategy: Optional[str] = Field(LoadBalanceStrategy.NONE.value, description="负载均衡策略")
|
load_balance_strategy: Optional[str] = Field(LoadBalanceStrategy.NONE.value, description="负载均衡策略")
|
||||||
capability: List[str] = Field(default_factory=list, description="模型能力列表")
|
capability: List[str] = Field(default_factory=list, description="模型能力列表")
|
||||||
is_omni: bool = Field(False, description="是否为Omni模型")
|
is_omni: bool = Field(False, description="是否为Omni模型")
|
||||||
|
model_id: Optional[uuid.UUID] = Field(None, description="基础模型ID")
|
||||||
|
|
||||||
|
|
||||||
class ApiKeyCreateNested(BaseModel):
|
class ApiKeyCreateNested(BaseModel):
|
||||||
|
|||||||
@@ -703,7 +703,7 @@ class AppService:
|
|||||||
self.db.flush()
|
self.db.flush()
|
||||||
|
|
||||||
# 如果是 agent 类型,复制 AgentConfig
|
# 如果是 agent 类型,复制 AgentConfig
|
||||||
if source_app.type == "agent":
|
if source_app.type == AppType.AGENT:
|
||||||
source_config = self.db.query(AgentConfig).filter(
|
source_config = self.db.query(AgentConfig).filter(
|
||||||
AgentConfig.app_id == source_app.id
|
AgentConfig.app_id == source_app.id
|
||||||
).first()
|
).first()
|
||||||
@@ -725,6 +725,50 @@ class AppService:
|
|||||||
)
|
)
|
||||||
self.db.add(new_config)
|
self.db.add(new_config)
|
||||||
|
|
||||||
|
elif source_app.type == AppType.WORKFLOW:
|
||||||
|
source_config = self.db.query(WorkflowConfig).filter(
|
||||||
|
WorkflowConfig.app_id == source_app.id
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if source_config:
|
||||||
|
new_config = WorkflowConfig(
|
||||||
|
id=uuid.uuid4(),
|
||||||
|
app_id=new_app.id,
|
||||||
|
nodes=source_config.nodes.copy() if source_config.nodes else [],
|
||||||
|
edges=source_config.edges.copy() if source_config.edges else [],
|
||||||
|
variables=source_config.variables.copy() if source_config.variables else [],
|
||||||
|
execution_config=source_config.execution_config.copy() if source_config.execution_config else {},
|
||||||
|
triggers=source_config.triggers.copy() if source_config.triggers else [],
|
||||||
|
is_active=True,
|
||||||
|
created_at=now,
|
||||||
|
updated_at=now,
|
||||||
|
)
|
||||||
|
self.db.add(new_config)
|
||||||
|
|
||||||
|
elif source_app.type == AppType.MULTI_AGENT:
|
||||||
|
source_config = self.db.query(MultiAgentConfig).filter(
|
||||||
|
MultiAgentConfig.app_id == source_app.id
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if source_config:
|
||||||
|
new_config = MultiAgentConfig(
|
||||||
|
id=uuid.uuid4(),
|
||||||
|
app_id=new_app.id,
|
||||||
|
master_agent_id=source_config.master_agent_id,
|
||||||
|
master_agent_name=source_config.master_agent_name,
|
||||||
|
default_model_config_id=source_config.default_model_config_id,
|
||||||
|
model_parameters=source_config.model_parameters,
|
||||||
|
orchestration_mode=source_config.orchestration_mode,
|
||||||
|
sub_agents=source_config.sub_agents.copy() if source_config.sub_agents else [],
|
||||||
|
routing_rules=source_config.routing_rules.copy() if source_config.routing_rules else None,
|
||||||
|
execution_config=source_config.execution_config.copy() if source_config.execution_config else {},
|
||||||
|
aggregation_strategy=source_config.aggregation_strategy,
|
||||||
|
is_active=True,
|
||||||
|
created_at=now,
|
||||||
|
updated_at=now,
|
||||||
|
)
|
||||||
|
self.db.add(new_config)
|
||||||
|
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
self.db.refresh(new_app)
|
self.db.refresh(new_app)
|
||||||
|
|
||||||
|
|||||||
@@ -780,6 +780,7 @@ class ModelBaseService:
|
|||||||
"description": model_base.description,
|
"description": model_base.description,
|
||||||
"capability": model_base.capability,
|
"capability": model_base.capability,
|
||||||
"is_omni": model_base.is_omni,
|
"is_omni": model_base.is_omni,
|
||||||
|
"is_active": False,
|
||||||
"is_composite": False
|
"is_composite": False
|
||||||
}
|
}
|
||||||
model_config = ModelConfigRepository.create(db, model_config_data)
|
model_config = ModelConfigRepository.create(db, model_config_data)
|
||||||
|
|||||||
Reference in New Issue
Block a user