89 lines
2.6 KiB
Plaintext
89 lines
2.6 KiB
Plaintext
llmid = params_kw.get('llmid', '')
|
|
action = params_kw.get('action', 'check')
|
|
|
|
if not llmid:
|
|
return json.dumps({'error': 'missing llmid'}, ensure_ascii=False)
|
|
|
|
if action == 'inference':
|
|
# 验证推理配置是否完整
|
|
async with get_sor_context(request._run_ns, 'llmage') as sor:
|
|
recs = await sor.sqlExe(
|
|
"select * from llm where id=${llmid}$", {'llmid': llmid})
|
|
if not recs:
|
|
return '❌ 模型记录不存在'
|
|
llm = recs[0]
|
|
|
|
# 检查 API 映射
|
|
maps = await sor.sqlExe(
|
|
"select * from llm_api_map where llmid=${llmid}$",
|
|
{'llmid': llmid})
|
|
if not maps:
|
|
return '❌ 无 API 映射配置'
|
|
|
|
# 检查 upapp 和 uapi
|
|
uapi_recs = await sor.sqlExe("""
|
|
select a.*, e.ioid, e.stream, e.name as api_name
|
|
from llm a
|
|
join llm_api_map m on a.id = m.llmid
|
|
join upapp c on a.upappid = c.id
|
|
join uapi e on c.id = e.upappid and m.apiname = e.name
|
|
where a.id=${llmid}$""", {'llmid': llmid})
|
|
|
|
if not uapi_recs:
|
|
return '❌ uapi 配置不完整,无法调用'
|
|
|
|
uapi = uapi_recs[0]
|
|
|
|
# 检查 ioid
|
|
io_recs = await sor.sqlExe(
|
|
"select * from uapiio where id=${ioid}$", {'ioid': uapi.ioid})
|
|
if not io_recs:
|
|
return '❌ IO 定义不存在'
|
|
|
|
return f'✅ 推理配置验证通过\n模型: {llm.name}\nAPI: {uapi.api_name}\nIO: {uapi.ioid}\nStream: {uapi.stream}'
|
|
|
|
elif action == 'check_charging':
|
|
# 验证计费配置是否完整
|
|
usages_str = params_kw.get('usages', '{}')
|
|
|
|
try:
|
|
usages = json.loads(usages_str) if isinstance(usages_str, str) else usages_str
|
|
except:
|
|
usages = {}
|
|
|
|
async with get_sor_context(request._run_ns, 'llmage') as sor:
|
|
maps = await sor.sqlExe(
|
|
"select * from llm_api_map where llmid=${llmid}$",
|
|
{'llmid': llmid})
|
|
if not maps:
|
|
return '❌ 无 API 映射'
|
|
|
|
ppids = [m.ppid for m in maps if m.ppid]
|
|
if not ppids:
|
|
return '❌ 无定价项目(ppid)'
|
|
|
|
ppid = ppids[0]
|
|
|
|
# 检查 pricing_program
|
|
async with get_sor_context(request._run_ns, 'pricing') as psor:
|
|
pregs = await psor.sqlExe(
|
|
"select * from pricing_program where id=${ppid}$", {'ppid': ppid})
|
|
if not pregs:
|
|
return f'❌ 定价项目不存在 (ppid={ppid})'
|
|
|
|
pp = pregs[0]
|
|
|
|
# 检查 pricing_program_timing
|
|
try:
|
|
timings = await psor.sqlExe(
|
|
"select * from pricing_program_timing where ppid=${ppid}$",
|
|
{'ppid': ppid})
|
|
if timings:
|
|
return f'✅ 计费配置验证通过\n定价项目: {pp.name}\n定价数据: {len(timings)}条记录\n测试用量: {json.dumps(usages)}'
|
|
else:
|
|
return f'⚠️ 定价项目存在但无定价数据\n定价项目: {pp.name}'
|
|
except Exception as e:
|
|
return f'⚠️ 定价数据查询失败: {e}'
|
|
|
|
return '无效的操作'
|