From 5d52d023192617cc2c663d1d3b9c0981b078e8e8 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 30 May 2026 20:36:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20V1=20API=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=96=B0=20catelogid=20=E7=BC=A9=E5=86=99(t2t/t2v/t2i=E7=AD=89?= =?UTF-8?q?)=EF=BC=8C=E5=90=91=E5=90=8E=E5=85=BC=E5=AE=B9=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - v1/chat/completions: 默认值 '文生文' → 't2t',SQL 匹配 b.id OR b.name - v1/video/generations: SQL 匹配 b.id OR b.name,注释示例更新 - v1/image/generations: SQL 匹配 b.id OR b.name,注释示例更新 - t2t/index.dspy: 默认值 '文生文' → 't2t',SQL 匹配 b.id OR b.name - get_type_llms.dspy: 硬编码中文名改为 alias 映射(t2v/i2v/r2v) - docs/API.md: 添加完整 catelogid ID 对照表,示例参数更新 --- docs/API.md | 32 +++++++++++++++++++++---- wwwroot/get_type_llms.dspy | 11 +++++---- wwwroot/t2t/index.dspy | 4 ++-- wwwroot/v1/chat/completions/index.dspy | 4 ++-- wwwroot/v1/image/generations/index.dspy | 4 ++-- wwwroot/v1/video/generations/index.dspy | 4 ++-- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/docs/API.md b/docs/API.md index aa1c4f2..e2378ee 100644 --- a/docs/API.md +++ b/docs/API.md @@ -21,7 +21,7 @@ Base Path: `/llmage/v1` | 参数 | 类型 | 说明 | |------|------|------| -| `catelogid` | string | 目录类型,默认 `"文生文"` | +| `catelogid` | string | 目录类型ID,默认 `"t2t"`,也支持中文名(向后兼容) | | `stream` | boolean | 是否启用流式输出 | | `off_peak` | boolean | 是否使用非高峰时段 | | `transno` | string | 交易流水号(不传则自动生成) | @@ -83,7 +83,7 @@ data: [DONE] | 参数 | 类型 | 说明 | |------|------|------| | `model` | string | 模型名称,如 `"keling-2.1"` | -| `catelogid` | string | 目录类型,如 `"文生视频"` / `"图生视频"` | +| `catelogid` | string | 目录类型ID,如 `"t2v"` / `"i2v"` / `"r2v"` | | `prompt` | string | 生成提示词 | ### 可选参数 @@ -101,7 +101,7 @@ data: [DONE] ```json { "model": "keling-2.1", - "catelogid": "文生视频", + "catelogid": "t2v", "prompt": "A beautiful sunset over the ocean", "duration": "5s", "resolution": "1080p" @@ -136,7 +136,7 @@ data: [DONE] | 参数 | 类型 | 说明 | |------|------|------| | `model` | string | 模型名称,如 `"jimeng-4.0"` | -| `catelogid` | string | 目录类型,如 `"文生图"` / `"图生图"` | +| `catelogid` | string | 目录类型ID,如 `"t2i"` | | `prompt` | string | 生成提示词 | ### 可选参数 @@ -155,7 +155,7 @@ data: [DONE] ```json { "model": "jimeng-4.0", - "catelogid": "文生图", + "catelogid": "t2i", "prompt": "A beautiful sunset over the ocean", "size": "1024x1024", "n": 1 @@ -248,6 +248,28 @@ GET /llmage/v1/models ## 通用说明 +### catelogid 目录类型ID对照表 + +| ID | 中文名 | 说明 | +|----|--------|------| +| `t2t` | 文生文 | 文本生成(默认) | +| `t2i` | 文生图 | 图像生成 | +| `t2v` | 文生视频 | 文本生成视频 | +| `i2v` | 图生视频 | 图像生成视频 | +| `r2v` | 参考生视频 | 参考图像生成视频 | +| `tts` | 语音合成 | 文本转语音 | +| `asr` | 语音识别 | 语音转文本 | +| `vision` | 图理解 | 图像理解 | +| `ai_search` | AI搜索 | AI搜索 | +| `digital_human` | 数字人 | 数字人 | +| `music_gen` | 音乐生成 | 音乐生成 | +| `text_cls` | 文本分类 | 文本分类 | +| `3d_gen` | 3D生成 | 3D模型生成 | +| `video_tool` | 视频工具 | 视频处理工具 | +| `translate` | 翻译 | 文本翻译 | + +> 向后兼容:catelogid 参数同时支持新ID(如 `"t2v"`)和旧中文名(如 `"文生视频"`),推荐使用新ID。 + ### 参数统一 所有 v1 接口统一使用 `catelogid` 参数标识目录类型,替代原有的 `lctype` / `llmcatelogid`。 diff --git a/wwwroot/get_type_llms.dspy b/wwwroot/get_type_llms.dspy index 1c9d0fa..1367dda 100644 --- a/wwwroot/get_type_llms.dspy +++ b/wwwroot/get_type_llms.dspy @@ -1,7 +1,10 @@ -lt = '文生视频' -if params_kw.type in ['文生视频', '参考生视频', '图生视频']: - lt = params_kw.type +_CATELOG_ALIAS = { + '文生视频': 't2v', '参考生视频': 'r2v', '图生视频': 'i2v', +} +lt = 't2v' +if params_kw.type: + lt = _CATELOG_ALIAS.get(params_kw.type, params_kw.type) async with get_sor_context(request._run_ns, 'llmage') as sor: sql = '''select distinct a.*, e.input_fields from llm a join llm_api_map m on a.id = m.llmid @@ -9,7 +12,7 @@ join llmcatelog b on m.llmcatelogid = b.id join upapp c on a.upappid = c.id join uapi d on c.apisetid = d.apisetid and a.apiname = d.name join uapiio e on d.ioid = e.id -where b.name=${lt}$ +where (b.id=${lt}$ OR b.name=${lt}$) and a.enabled_date <= ${biz_date}$ and ${biz_date}$ < a.expired_date and a.status = 'published' diff --git a/wwwroot/t2t/index.dspy b/wwwroot/t2t/index.dspy index 61b7a2a..ac5f811 100644 --- a/wwwroot/t2t/index.dspy +++ b/wwwroot/t2t/index.dspy @@ -1,5 +1,5 @@ debug_params('params_kw', params_kw) -lctype='文生文' +lctype='t2t' if params_kw.off_peak: off_peak = params_kw.off_peak if off_peak in [True, "Y" "y", 1, "1"]: @@ -20,7 +20,7 @@ async with get_sor_context(env, 'llmage') as sor: sql = """select distinct a.* from llm a join llm_api_map m on a.id = m.llmid join llmcatelog b on m.llmcatelogid = b.id -where b.name = ${lctype}$ +where (b.id = ${lctype}$ OR b.name = ${lctype}$) and a.model=${model}$ and a.status = 'published'""" recs = await sor.sqlExe(sql, { diff --git a/wwwroot/v1/chat/completions/index.dspy b/wwwroot/v1/chat/completions/index.dspy index bfe1905..dda731b 100644 --- a/wwwroot/v1/chat/completions/index.dspy +++ b/wwwroot/v1/chat/completions/index.dspy @@ -10,7 +10,7 @@ async def gen(): yield l debug_params('params_kw', params_kw) -catelogid = params_kw.catelogid or '文生文' +catelogid = params_kw.catelogid or 't2t' if params_kw.off_peak: off_peak = params_kw.off_peak if off_peak in [True, "Y" "y", 1, "1"]: @@ -33,7 +33,7 @@ async with get_sor_context(env, 'llmage') as sor: sql = """select distinct a.* from llm a join llm_api_map m on a.id = m.llmid join llmcatelog b on m.llmcatelogid = b.id -where b.name = ${catelogid}$ +where (b.id = ${catelogid}$ OR b.name = ${catelogid}$) and a.model=${model}$ and a.status = 'published'""" recs = await sor.sqlExe(sql, { diff --git a/wwwroot/v1/image/generations/index.dspy b/wwwroot/v1/image/generations/index.dspy index 3161df4..08fe83b 100644 --- a/wwwroot/v1/image/generations/index.dspy +++ b/wwwroot/v1/image/generations/index.dspy @@ -6,7 +6,7 @@ # Example request: # { # "model": "jimeng-4.0", -# "catelogid": "文生图", +# "catelogid": "t2i", # "prompt": "A beautiful sunset over the ocean", # "size": "1024x1024", # "n": 1 @@ -52,7 +52,7 @@ async with get_sor_context(env, 'llmage') as sor: sql = """select distinct a.* from llm a join llm_api_map m on a.id = m.llmid join llmcatelog b on m.llmcatelogid = b.id -where b.name = ${lctype}$ +where (b.id = ${lctype}$ OR b.name = ${lctype}$) and a.model=${model}$ and a.status = 'published'""" recs = await sor.sqlExe(sql, { diff --git a/wwwroot/v1/video/generations/index.dspy b/wwwroot/v1/video/generations/index.dspy index 1d84476..5704481 100644 --- a/wwwroot/v1/video/generations/index.dspy +++ b/wwwroot/v1/video/generations/index.dspy @@ -6,7 +6,7 @@ # Example request: # { # "model": "keling-2.1", -# "catelogid": "文生视频", +# "catelogid": "t2v", # "prompt": "A beautiful sunset over the ocean", # "duration": "5s", # "resolution": "1080p" @@ -60,7 +60,7 @@ async with get_sor_context(env, 'llmage') as sor: sql = """select distinct a.* from llm a join llm_api_map m on a.id = m.llmid join llmcatelog b on m.llmcatelogid = b.id -where b.name = ${lctype}$ +where (b.id = ${lctype}$ OR b.name = ${lctype}$) and a.model=${model}$ and a.status = 'published'""" recs = await sor.sqlExe(sql, {