pipeline_core/wwwroot/api/agent_model_options.dspy

39 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# agent_model_options.dspy - 返回 active 模型列表(供 AgentIO 模型选择下拉)
# llm 表是 pipeline 库的通用配置,产线无关
# org_id 多租户隔离:非系统级机构只看到本机构的模型(不含系统级兜底)
# 返回每项带 selected 标记标识个人之前选择的默认模型default_llm_id
dbname = get_module_dbname('pipeline_core')
uid = await get_user()
org_id = (await get_userorgid()) or ''
async with DBPools().sqlorContext(dbname) as sor:
sql = "SELECT id, name, provider, model_id, capabilities FROM llm WHERE status='active'"
params = {}
if org_id and org_id != '0':
sql += " AND org_id=${org}$"
params['org'] = org_id
sql += " ORDER BY name"
recs = await sor.sqlExe(sql, params)
# 个人之前选择的默认模型
current_llm_id = ''
if uid:
_s = await sor.sqlExe(
"SELECT default_llm_id FROM pipeline_agent_settings WHERE user_id=${u}$", {"u": uid})
if _s:
current_llm_id = getattr(_s[0], 'default_llm_id', '') or ''
rows = []
for r in recs:
rows.append({
'value': r.id,
'text': f"{r.name} ({r.provider})",
'provider': r.provider,
'model_id': r.model_id,
'capabilities': r.capabilities or 'text',
'selected': r.id == current_llm_id,
})
return rows