refactor: kimi_t2t data 模板 — build_kimi_content 一行搞定多模态
This commit is contained in:
parent
f1930af597
commit
c8b7d0cd07
@ -2,7 +2,7 @@
|
|||||||
-- Kimi K3 API 接入 (月之暗面 / Moonshot)
|
-- Kimi K3 API 接入 (月之暗面 / Moonshot)
|
||||||
-- Base URL: https://api.moonshot.cn/v1
|
-- Base URL: https://api.moonshot.cn/v1
|
||||||
-- 兼容 OpenAI 格式, 文档: https://platform.kimi.com/docs/api/chat
|
-- 兼容 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: ',
|
'/chat/completions', 'POST', 'data: ',
|
||||||
'{"Authorization": "Bearer {{apikey}}", "Content-Type": "application/json"}',
|
'{"Authorization": "Bearer {{apikey}}", "Content-Type": "application/json"}',
|
||||||
NULL,
|
NULL,
|
||||||
-- === data 模板 ===
|
|
||||||
'{
|
'{
|
||||||
{% if stream %}
|
{% if stream %}
|
||||||
"stream_options":{"include_usage": true},
|
"stream_options":{"include_usage": true},
|
||||||
@ -38,37 +37,12 @@ VALUES (
|
|||||||
{% if messages %}
|
{% if messages %}
|
||||||
"messages": {{json.dumps(messages, ensure_ascii=False)}},
|
"messages": {{json.dumps(messages, ensure_ascii=False)}},
|
||||||
{% else %}
|
{% 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": [
|
"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(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 %}
|
{% endif %}
|
||||||
{% if stream %}
|
{% if stream %}
|
||||||
"stream":true,
|
"stream":true,
|
||||||
@ -76,7 +50,6 @@ VALUES (
|
|||||||
"model": "{{model}}",
|
"model": "{{model}}",
|
||||||
"reasoning_effort": "max"
|
"reasoning_effort": "max"
|
||||||
}',
|
}',
|
||||||
-- === response 模板 ===
|
|
||||||
'{
|
'{
|
||||||
"id": "{{id}}", "object": "{{object}}", "created": {{created}},
|
"id": "{{id}}", "object": "{{object}}", "created": {{created}},
|
||||||
"choices": {{json.dumps(choices, ensure_ascii=False)}}, "model": "{{model}}",
|
"choices": {{json.dumps(choices, ensure_ascii=False)}}, "model": "{{model}}",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user