fix: kimi uapi 补全 uapiio 定义,移除所有占位符

This commit is contained in:
yumoqing 2026-07-17 17:42:07 +08:00
parent 20833b8e90
commit afced72c3c

View File

@ -1,39 +1,40 @@
-- ============================================================ -- ============================================================
-- Kimi K3 API 接入 (月之暗面 / Moonshot) -- Kimi K3 API 接入 (月之暗面 / Moonshot)
-- Base URL: https://api.moonshot.cn/v1 -- Base URL: https://api.moonshot.cn/v1
-- 兼容 OpenAI 格式 -- 兼容 OpenAI 格式, 文档: https://platform.kimi.com/docs/api/chat
-- 文档: https://platform.kimi.com/docs/api/chat
-- ============================================================ -- ============================================================
-- ============================================================ -- ============================================================
-- 1. 确认 modelprovider 和 upapp 存在 -- 0. 前置: modelprovider / upapp (如不存在先创建)
-- ============================================================ -- ============================================================
-- INSERT IGNORE INTO modelprovider (id, name) VALUES ('<provider_id>', '月之暗面'); -- INSERT IGNORE INTO modelprovider (id, name) VALUES ('moonshot', '月之暗面');
-- INSERT IGNORE INTO upapp (id, name, key, baseurl, enabled_date) VALUES ('<upapp_id>', '月之暗面', 'MOONSHOT_API_KEY', 'https://api.moonshot.cn', '2026-07-17'); -- INSERT IGNORE INTO upapp (id, name, `key`, baseurl, enabled_date)
-- VALUES ('upapp_moonshot', '月之暗面', 'MOONSHOT_API_KEY', 'https://api.moonshot.cn', '2026-07-17');
SET @upapp_id = 'upapp_moonshot'; -- 替换为实际的月之暗面 upapp.id
-- ============================================================ -- ============================================================
-- 2. Chat Completions (对话补全) — OpenAI 兼容,支持流式 -- 1. uapiio — 文件管理输入输出定义
-- POST /v1/chat/completions -- ============================================================
REPLACE INTO `uapiio` (`id`, `name`, `description`, `input_fields`) VALUES
('kimi_file_upload_io', 'kimi文件上传', 'Kimi文件上传 multipart/form-data', '[]'),
('kimi_file_list_io', 'kimi文件列表', 'Kimi文件列表查询', '[]'),
('kimi_file_retrieve_io', 'kimi文件详情', 'Kimi文件元数据查询', '[]'),
('kimi_file_delete_io', 'kimi文件删除', 'Kimi文件删除', '[]'),
('kimi_file_content_io', 'kimi文件内容', 'Kimi文件内容提取', '[]');
-- ============================================================
-- 2. Chat Completions — POST /v1/chat/completions
-- t2t 复用已有 ioid Is8l4TGkcZcqFSjbbeIK2 (文本会话)
-- ============================================================ -- ============================================================
REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`) REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`)
VALUES ( VALUES (
'kimi_t2t', 'kimi_t2t', 't2t', '0', 'stream',
't2t', '/chat/completions', 'POST', 'data: ',
'0', '{"Authorization": "Bearer {{apikey}}", "Content-Type": "application/json"}',
'stream',
'/chat/completions',
'POST',
'data: ',
'{
"Authorization": "Bearer {{apikey}}",
"Content-Type": "application/json"
}',
NULL, NULL,
'{ '{
{% if stream %} {% if stream %}
"stream_options":{ "stream_options":{"include_usage": true},
"include_usage": true
},
{% endif %} {% endif %}
{% if tools %} {% if tools %}
"tools": {{json.dumps(tools, ensure_ascii=False)}}, "tools": {{json.dumps(tools, ensure_ascii=False)}},
@ -46,15 +47,9 @@ VALUES (
{% else %} {% else %}
"messages": [ "messages": [
{% if sys_prompt %} {% if sys_prompt %}
{ {"role": "system", "content": {{json.dumps(sys_prompt, ensure_ascii=False)}}},
"role": "system",
"content": {{json.dumps(sys_prompt, ensure_ascii=False)}}
},
{% endif %} {% endif %}
{ {"role": "user", "content": {{json.dumps(prompt, ensure_ascii=False)}}}
"role": "user",
"content": {{json.dumps(prompt, ensure_ascii=False)}}
}
], ],
{% endif %} {% endif %}
{% if stream %} {% if stream %}
@ -62,14 +57,10 @@ VALUES (
{% endif %} {% endif %}
"model": "{{model}}", "model": "{{model}}",
"reasoning_effort": "max" "reasoning_effort": "max"
} }',
',
'{ '{
"id": "{{id}}", "id": "{{id}}", "object": "{{object}}", "created": {{created}},
"object": "{{object}}", "choices": {{json.dumps(choices, ensure_ascii=False)}}, "model": "{{model}}",
"created": {{created}},
"choices": {{json.dumps(choices, ensure_ascii=False)}},
"model": "{{model}}",
{% if object == "chat.completion" %} {% if object == "chat.completion" %}
"reasoning_content": {{json.dumps(choices[0].message.reasoning_content, ensure_ascii=False)}}, "reasoning_content": {{json.dumps(choices[0].message.reasoning_content, ensure_ascii=False)}},
"content":{{json.dumps(choices[0].message.content, ensure_ascii=False)}}, "content":{{json.dumps(choices[0].message.content, ensure_ascii=False)}},
@ -77,49 +68,25 @@ VALUES (
"reasoning_content": {{json.dumps(choices[0].delta.reasoning_content, ensure_ascii=False)}}, "reasoning_content": {{json.dumps(choices[0].delta.reasoning_content, ensure_ascii=False)}},
"content":{{json.dumps(choices[0].delta.content, ensure_ascii=False)}}, "content":{{json.dumps(choices[0].delta.content, ensure_ascii=False)}},
{% endif %} {% endif %}
{% if usage %} {% if usage %}{% set usage1 = usage.update({"model": model}) %}
{% set usage1 = usage.update({"model": model}) %} "finish": "1", "usage":{{json.dumps(usage)}}
"finish": "1",
"usage":{{json.dumps(usage)}}
{% else %} {% else %}
"finish":"0" "finish":"0"
{% endif %} {% endif %}}',
} 'Is8l4TGkcZcqFSjbbeIK2', NULL, @upapp_id
',
'Is8l4TGkcZcqFSjbbeIK2', -- 复用文本会话 ioid
NULL,
'<upapp_id>' -- 替换为月之暗面的 upapp.id
); );
-- ============================================================ -- ============================================================
-- 3. 上传文件 POST /v1/files (multipart/form-data) -- 3. 上传文件 POST /v1/files
-- ============================================================ -- ============================================================
REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`) REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`)
VALUES ( VALUES (
'kimi_file_upload', 'kimi_file_upload', 'file_upload', '0', 'none',
'file_upload', '/files', 'POST', NULL,
'0', '{"Authorization": "Bearer {{apikey}}"}',
'none', NULL, NULL,
'/files', '{"id": "{{id}}", "object": "{{object}}", "filename": "{{filename}}", "purpose": "{{purpose}}", "bytes": {{bytes}}, "created_at": {{created_at}}, "status": "{{status}}"}',
'POST', 'kimi_file_upload_io', NULL, @upapp_id
NULL,
'{
"Authorization": "Bearer {{apikey}}"
}',
NULL,
NULL, -- multipart 由 Sage 框架自动处理
'{
"id": "{{id}}",
"object": "{{object}}",
"filename": "{{filename}}",
"purpose": "{{purpose}}",
"bytes": {{bytes}},
"created_at": {{created_at}},
"status": "{{status}}"
}',
'<ioid_file>', -- 需新建 file_upload ioid
NULL,
'<upapp_id>'
); );
-- ============================================================ -- ============================================================
@ -127,25 +94,12 @@ VALUES (
-- ============================================================ -- ============================================================
REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`) REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`)
VALUES ( VALUES (
'kimi_file_list', 'kimi_file_list', 'file_list', '0', 'none',
'file_list', '/files', 'GET', NULL,
'0', '{"Authorization": "Bearer {{apikey}}"}',
'none', NULL, NULL,
'/files', '{"object": "{{object}}", "data": {{json.dumps(data)}}}',
'GET', 'kimi_file_list_io', NULL, @upapp_id
NULL,
'{
"Authorization": "Bearer {{apikey}}"
}',
NULL,
NULL,
'{
"object": "{{object}}",
"data": {{json.dumps(data)}}
}',
'<ioid_file_list>', -- 需新建 ioid
NULL,
'<upapp_id>'
); );
-- ============================================================ -- ============================================================
@ -153,31 +107,12 @@ VALUES (
-- ============================================================ -- ============================================================
REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`) REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`)
VALUES ( VALUES (
'kimi_file_retrieve', 'kimi_file_retrieve', 'file_retrieve', '0', 'none',
'file_retrieve', '/files/{{file_id}}', 'GET', NULL,
'0', '{"Authorization": "Bearer {{apikey}}"}',
'none', NULL, NULL,
'/files/{{file_id}}', '{"id": "{{id}}", "object": "{{object}}", "filename": "{{filename}}", "purpose": "{{purpose}}", "bytes": {{bytes}}, "created_at": {{created_at}}, "status": "{{status}}", "status_details": "{{status_details}}"}',
'GET', 'kimi_file_retrieve_io', NULL, @upapp_id
NULL,
'{
"Authorization": "Bearer {{apikey}}"
}',
NULL,
NULL,
'{
"id": "{{id}}",
"object": "{{object}}",
"filename": "{{filename}}",
"purpose": "{{purpose}}",
"bytes": {{bytes}},
"created_at": {{created_at}},
"status": "{{status}}",
"status_details": "{{status_details}}"
}',
'<ioid_file_info>', -- 需新建 ioid
NULL,
'<upapp_id>'
); );
-- ============================================================ -- ============================================================
@ -185,26 +120,12 @@ VALUES (
-- ============================================================ -- ============================================================
REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`) REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`)
VALUES ( VALUES (
'kimi_file_delete', 'kimi_file_delete', 'file_delete', '0', 'none',
'file_delete', '/files/{{file_id}}', 'DELETE', NULL,
'0', '{"Authorization": "Bearer {{apikey}}"}',
'none', NULL, NULL,
'/files/{{file_id}}', '{"id": "{{id}}", "object": "{{object}}", "deleted": {{deleted}}}',
'DELETE', 'kimi_file_delete_io', NULL, @upapp_id
NULL,
'{
"Authorization": "Bearer {{apikey}}"
}',
NULL,
NULL,
'{
"id": "{{id}}",
"object": "{{object}}",
"deleted": {{deleted}}
}',
'<ioid_file_delete>', -- 需新建 ioid
NULL,
'<upapp_id>'
); );
-- ============================================================ -- ============================================================
@ -212,22 +133,10 @@ VALUES (
-- ============================================================ -- ============================================================
REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`) REPLACE INTO `uapi` (`id`, `name`, `need_auth`, `stream`, `path`, `httpmethod`, `chunk_match`, `headers`, `params`, `data`, `response`, `ioid`, `callbackurl`, `upappid`)
VALUES ( VALUES (
'kimi_file_content', 'kimi_file_content', 'file_content', '0', 'none',
'file_content', '/files/{{file_id}}/content', 'GET', NULL,
'0', '{"Authorization": "Bearer {{apikey}}"}',
'none', NULL, NULL,
'/files/{{file_id}}/content', '{"content": "{{content}}"}',
'GET', 'kimi_file_content_io', NULL, @upapp_id
NULL,
'{
"Authorization": "Bearer {{apikey}}"
}',
NULL,
NULL,
'{
"content": "{{content}}"
}',
'<ioid_file_content>', -- 需新建 ioid
NULL,
'<upapp_id>'
); );