diff --git a/scripts/kimi_k3_uapi.sql b/scripts/kimi_k3_uapi.sql index eda9b1e..5f360b8 100644 --- a/scripts/kimi_k3_uapi.sql +++ b/scripts/kimi_k3_uapi.sql @@ -2,7 +2,7 @@ -- Kimi K3 API 接入 (月之暗面 / Moonshot) -- Base URL: https://api.moonshot.cn/v1 -- 兼容 OpenAI 格式, 文档: https://platform.kimi.com/docs/api/chat --- 多模态: 图片/视频通过 webpath_to_base64() 转 data URI +-- 多模态: image_files/video_files 通过 build_kimi_content() 转 data URI 数组 -- ============================================================ -- ============================================================ @@ -24,7 +24,6 @@ VALUES ( '/chat/completions', 'POST', 'data: ', '{"Authorization": "Bearer {{apikey}}", "Content-Type": "application/json"}', NULL, - -- === data 模板 === '{ {% if stream %} "stream_options":{"include_usage": true}, @@ -38,37 +37,12 @@ VALUES ( {% if messages %} "messages": {{json.dumps(messages, ensure_ascii=False)}}, {% else %} -{% if images or videos %}{# === 多模态: 构造 content 数组 === #} -{% set content_parts = [] %} -{% if prompt %} -{% do content_parts.append({"type": "text", "text": prompt}) %} -{% endif %} -{% for img in images %} -{% set img_b64 = rfexe("webpath_to_base64", img) %} -{% if img_b64 %} -{% do content_parts.append({"type": "image_url", "image_url": img_b64}) %} -{% endif %} -{% endfor %} -{% for vid in videos %} -{% set vid_b64 = rfexe("webpath_to_base64", vid) %} -{% if vid_b64 %} -{% do content_parts.append({"type": "video_url", "video_url": vid_b64}) %} -{% endif %} -{% endfor %} "messages": [ {% if sys_prompt %} {"role": "system", "content": {{json.dumps(sys_prompt, ensure_ascii=False)}}}, {% endif %} - {"role": "user", "content": {{json.dumps(content_parts, ensure_ascii=False)}}} + {"role": "user", "content": {{build_kimi_content(prompt, image_files, video_files)}}} ], -{% else %}{# === 纯文本 === #} - "messages": [ -{% if sys_prompt %} - {"role": "system", "content": {{json.dumps(sys_prompt, ensure_ascii=False)}}}, -{% endif %} - {"role": "user", "content": {{json.dumps(prompt, ensure_ascii=False)}}} - ], -{% endif %} {% endif %} {% if stream %} "stream":true, @@ -76,7 +50,6 @@ VALUES ( "model": "{{model}}", "reasoning_effort": "max" }', - -- === response 模板 === '{ "id": "{{id}}", "object": "{{object}}", "created": {{created}}, "choices": {{json.dumps(choices, ensure_ascii=False)}}, "model": "{{model}}",