feat(llm): 个人选择模型(default_llm_id)接入会话agent+org_id改用户机构优先

This commit is contained in:
ymq 2026-08-17 13:31:04 +08:00
parent 791bd88c6d
commit 286f0cb4dd
2 changed files with 31 additions and 5 deletions

View File

@ -287,7 +287,21 @@ class AgentExecutor:
async def _init_components(self):
"""懒加载各组件"""
# 1. 加载 org_id + workspace_dir + pipeline_id从项目上下文需先于 skill 加载)
# 1. 加载 org_id用户机构优先fallback 项目机构)+ workspace_dir + pipeline_id
# 个人选择 llm 按「用户机构」隔离default_llm_id 指向本机构 llm故 org_id 须取 users.orgid
# 项目机构仅作 fallback无 user_id 的测试场景)。
if self.user_id:
try:
from sqlor.dbpools import DBPools
db = DBPools()
async with db.sqlorContext("pipeline") as sor:
recs = await sor.sqlExe(
"SELECT orgid FROM users WHERE id=${uid}$", {"uid": self.user_id})
if recs:
self.org_id = getattr(recs[0], 'orgid', '') or ''
except Exception:
pass
if self.project_id:
try:
from sqlor.dbpools import DBPools
@ -297,7 +311,8 @@ class AgentExecutor:
"SELECT org_id, workspace_dir, pipeline_id FROM sd_projects WHERE id=${pid}$",
{"pid": self.project_id})
if recs:
self.org_id = getattr(recs[0], 'org_id', '') or ''
if not self.org_id:
self.org_id = getattr(recs[0], 'org_id', '') or ''
ws = getattr(recs[0], 'workspace_dir', '') or ''
if ws:
self.workspace_dir = ws

View File

@ -71,8 +71,11 @@ class Gateway:
# ── 上下文解析 ──
async def resolve_project(self, user_id: str) -> dict:
"""解析用户当前项目 → {pid, pipeline_id, name}。"""
ctx = {"pid": "", "pipeline_id": "", "name": ""}
"""解析用户当前项目 → {pid, pipeline_id, name, default_llm_id, default_llm_name}。
同时读出个人选择的模型default_llm_id llm.name run_message 覆盖 config.model_name
"""
ctx = {"pid": "", "pipeline_id": "", "name": "", "default_llm_id": "", "default_llm_name": ""}
if not user_id:
return ctx
try:
@ -80,10 +83,15 @@ class Gateway:
db = DBPools()
async with db.sqlorContext("pipeline") as sor:
recs = await sor.sqlExe(
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$",
"SELECT s.current_project_id, s.default_llm_id, l.name as llm_name "
"FROM pipeline_agent_settings s "
"LEFT JOIN llm l ON l.id = s.default_llm_id AND l.status='active' "
"WHERE s.user_id=${u}$",
{"u": user_id})
if recs:
ctx["pid"] = getattr(recs[0], "current_project_id", "") or ""
ctx["default_llm_id"] = getattr(recs[0], "default_llm_id", "") or ""
ctx["default_llm_name"] = getattr(recs[0], "llm_name", "") or ""
if ctx["pid"]:
proj = await sor.sqlExe(
"SELECT name, pipeline_id FROM sd_projects WHERE id=${p}$",
@ -138,6 +146,9 @@ class Gateway:
# 3. 加载产线能力 + 创建 executorgeneric 时不装产线能力)
config = await load_agent_config(
pipeline_id=ctx["pipeline_id"], project_id=ctx["pid"], generic=generic)
# 个人选择的模型优先default_llm_id → llm.name覆盖产线 default_model
if ctx.get("default_llm_name"):
config.model_name = ctx["default_llm_name"]
executor = AgentExecutor(
config=config, project_id=ctx["pid"], user_id=user_id, role=role)