From c8b7d0cd07eb842664ea587bd85ec489b3414e41 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 17 Jul 2026 17:58:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20kimi=5Ft2t=20data=20=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=20=E2=80=94=20build=5Fkimi=5Fcontent=20=E4=B8=80?= =?UTF-8?q?=E8=A1=8C=E6=90=9E=E5=AE=9A=E5=A4=9A=E6=A8=A1=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/kimi_k3_uapi.sql | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) 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}}",