pipeline-llm/wwwroot/api/v1/models.dspy

46 lines
1.8 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.

# models.dspy — 按能力分类列出可用模型(对齐 llmage v1/models 的分类方式)
#
# URL: /pipeline_llm/api/v1/models?catelogid=t2t
# catelogid 可选t2t / t2i / t2v / embedding / rerank / tts / asr / i2t ...
# (能力类型标准 = 模型治理 appcodes llm_capability新增走评审禁止野生标签
# 不传 = 全部能力
#
# 鉴权Authorization: Bearer *** token>(与 chat/completions 一致)。
# 机构隔离:只列本机构治理链可用的模型(无策略 = 空列表)。
auth = ''
try:
auth = request.headers.get('Authorization', '') or ''
except Exception:
auth = ''
if not auth:
auth = (params_kw or {}).get('api_key', '') or ''
if not auth:
return json.dumps({"error": {"message": "缺少 Authorization Bearer token",
"type": "invalid_request_error", "code": "missing_token"}},
ensure_ascii=False)
ok, info = await verify_llm_token(auth)
if not ok:
return json.dumps({"error": {"message": str(info),
"type": "invalid_request_error", "code": "invalid_token"}},
ensure_ascii=False)
catelogid = (params_kw or {}).get('catelogid', '') or ''
rows = await llm_list_models(info.get('org_id', '') or '', catelogid=catelogid)
# OpenAI 兼容输出 + 分类字段catelogid 照 llmage 叫法,值 = 能力类型标准)
out = {"object": "list", "data": []}
for r in rows:
out["data"].append({
"id": r.get('model_id', '') or r.get('name', ''),
"object": "model",
"name": r.get('name', ''),
"catelogid": r.get('capability', ''),
"vendor": r.get('vendor', ''),
"price_input": r.get('price_input', 0),
"price_output": r.get('price_output', 0),
})
return json.dumps(out, ensure_ascii=False)