refactor: 移除 build_kimi_content (迁移至 llmage/utils)
This commit is contained in:
parent
add70d67de
commit
6165795aa7
@ -238,22 +238,6 @@ def webpath_to_base64(webpath):
|
|||||||
b64 = base64.b64encode(f.read()).decode('utf-8')
|
b64 = base64.b64encode(f.read()).decode('utf-8')
|
||||||
return f'data:{mime};base64,{b64}'
|
return f'data:{mime};base64,{b64}'
|
||||||
|
|
||||||
def build_kimi_content(prompt='', image_files=None, video_files=None):
|
|
||||||
"""构造 kimi 多模态 content 数组 JSON"""
|
|
||||||
import json
|
|
||||||
parts = []
|
|
||||||
if prompt:
|
|
||||||
parts.append({"type": "text", "text": prompt})
|
|
||||||
for f in (image_files or []):
|
|
||||||
b64 = webpath_to_base64(f)
|
|
||||||
if b64:
|
|
||||||
parts.append({"type": "image_url", "image_url": b64})
|
|
||||||
for f in (video_files or []):
|
|
||||||
b64 = webpath_to_base64(f)
|
|
||||||
if b64:
|
|
||||||
parts.append({"type": "video_url", "video_url": b64})
|
|
||||||
return json.dumps(parts, ensure_ascii=False)
|
|
||||||
|
|
||||||
async def base642file(b64str):
|
async def base642file(b64str):
|
||||||
filename = getFilenameFromBase64(b64str)
|
filename = getFilenameFromBase64(b64str)
|
||||||
if ',' in b64str:
|
if ',' in b64str:
|
||||||
@ -299,6 +283,5 @@ async def data2qrpath(data, logo=None):
|
|||||||
|
|
||||||
from .serverenv import ServerEnv
|
from .serverenv import ServerEnv
|
||||||
ServerEnv().webpath_to_base64 = webpath_to_base64
|
ServerEnv().webpath_to_base64 = webpath_to_base64
|
||||||
ServerEnv().build_kimi_content = build_kimi_content
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user