feat: llm 组织隔离(org_id) + 产线缺省模型(default_model) + load_agent_config 缺省查找

This commit is contained in:
p 2026-08-14 18:03:01 +08:00
parent 6b908fd88e
commit 8d431721fa
4 changed files with 28 additions and 3 deletions

View File

@ -3,6 +3,7 @@
"title": "大语言模型管理",
"params": {
"sortby": "created_at",
"logined_userorgid": "org_id",
"browserfields": {
"exclouded": ["id", "api_key"],
"cwidth": {}

View File

@ -15,6 +15,7 @@
{"name": "api_key", "title": "API密钥", "type": "str", "length": 500},
{"name": "max_tokens", "title": "最大Token", "type": "int", "default": "8192"},
{"name": "status", "title": "状态", "type": "str", "length": 20, "default": "active"},
{"name": "org_id", "title": "所属机构ID", "type": "str", "length": 32, "default": "0"},
{"name": "description", "title": "描述", "type": "text"},
{"name": "created_at", "title": "创建时间", "type": "timestamp"},
{"name": "updated_at", "title": "更新时间", "type": "timestamp"}

View File

@ -76,6 +76,13 @@
"length": 500,
"uitype": "text"
},
{
"name": "default_model",
"title": "缺省模型",
"type": "str",
"length": 100,
"uitype": "code"
},
{
"name": "org_id",
"title": "所属机构ID",
@ -134,6 +141,13 @@
"valuefield": "k",
"textfield": "v",
"cond": "parentid='pipeline_status'"
},
{
"field": "default_model",
"table": "llm",
"valuefield": "name",
"textfield": "name",
"cond": "status='active'"
}
]
}

View File

@ -360,21 +360,30 @@ async def load_agent_config(pipeline_id: str = None, project_id: str = None) ->
except (json.JSONDecodeError, TypeError):
pass
# 产线级配置
# 产线级配置 + 产线缺省模型
if pipeline_id:
recs = await sor.sqlExe(
"SELECT agent_config FROM pipelines WHERE id=${pid}$",
"SELECT agent_config, default_model FROM pipelines WHERE id=${pid}$",
{"pid": pipeline_id},
)
if recs:
raw = getattr(recs[0], "agent_config", "")
raw = getattr(recs[0], "agent_config", "") or ""
default_model = getattr(recs[0], "default_model", "") or ""
if raw:
try:
data = json.loads(raw) if isinstance(raw, str) else raw
data["tools"] = _merge_tools(data.get("tools", []), SDLC_DEFAULT_TOOLS)
# 产线缺省模型agent_config 未显式设 model_name 时用 default_model 兜底
if not data.get("model_name") and default_model:
data["model_name"] = default_model
return AgentConfig.from_dict(data)
except (json.JSONDecodeError, TypeError):
pass
elif default_model:
# agent_config 为空,仅产线设了缺省模型
cfg = AgentConfig.from_dict(SDLC_DEFAULT_CONFIG.to_dict())
cfg.model_name = default_model
return cfg
except Exception:
pass