feat(llm): 个人选择模型(default_llm_id)接入会话agent+org_id改用户机构优先
This commit is contained in:
parent
791bd88c6d
commit
286f0cb4dd
@ -287,7 +287,21 @@ class AgentExecutor:
|
|||||||
|
|
||||||
async def _init_components(self):
|
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:
|
if self.project_id:
|
||||||
try:
|
try:
|
||||||
from sqlor.dbpools import DBPools
|
from sqlor.dbpools import DBPools
|
||||||
@ -297,7 +311,8 @@ class AgentExecutor:
|
|||||||
"SELECT org_id, workspace_dir, pipeline_id FROM sd_projects WHERE id=${pid}$",
|
"SELECT org_id, workspace_dir, pipeline_id FROM sd_projects WHERE id=${pid}$",
|
||||||
{"pid": self.project_id})
|
{"pid": self.project_id})
|
||||||
if recs:
|
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 ''
|
ws = getattr(recs[0], 'workspace_dir', '') or ''
|
||||||
if ws:
|
if ws:
|
||||||
self.workspace_dir = ws
|
self.workspace_dir = ws
|
||||||
|
|||||||
@ -71,8 +71,11 @@ class Gateway:
|
|||||||
# ── 上下文解析 ──
|
# ── 上下文解析 ──
|
||||||
|
|
||||||
async def resolve_project(self, user_id: str) -> dict:
|
async def resolve_project(self, user_id: str) -> dict:
|
||||||
"""解析用户当前项目 → {pid, pipeline_id, name}。"""
|
"""解析用户当前项目 → {pid, pipeline_id, name, default_llm_id, default_llm_name}。
|
||||||
ctx = {"pid": "", "pipeline_id": "", "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:
|
if not user_id:
|
||||||
return ctx
|
return ctx
|
||||||
try:
|
try:
|
||||||
@ -80,10 +83,15 @@ class Gateway:
|
|||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext("pipeline") as sor:
|
async with db.sqlorContext("pipeline") as sor:
|
||||||
recs = await sor.sqlExe(
|
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})
|
{"u": user_id})
|
||||||
if recs:
|
if recs:
|
||||||
ctx["pid"] = getattr(recs[0], "current_project_id", "") or ""
|
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"]:
|
if ctx["pid"]:
|
||||||
proj = await sor.sqlExe(
|
proj = await sor.sqlExe(
|
||||||
"SELECT name, pipeline_id FROM sd_projects WHERE id=${p}$",
|
"SELECT name, pipeline_id FROM sd_projects WHERE id=${p}$",
|
||||||
@ -138,6 +146,9 @@ class Gateway:
|
|||||||
# 3. 加载产线能力 + 创建 executor(generic 时不装产线能力)
|
# 3. 加载产线能力 + 创建 executor(generic 时不装产线能力)
|
||||||
config = await load_agent_config(
|
config = await load_agent_config(
|
||||||
pipeline_id=ctx["pipeline_id"], project_id=ctx["pid"], generic=generic)
|
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(
|
executor = AgentExecutor(
|
||||||
config=config, project_id=ctx["pid"], user_id=user_id, role=role)
|
config=config, project_id=ctx["pid"], user_id=user_id, role=role)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user