feat(llm): 运行时媒体别名归一升级为三数组契约——xxx_file/xxx_url→xxx_files,media数组按type分组进image_files/video_files/audio_files
This commit is contained in:
parent
c3cf1a3a4f
commit
825dd2e130
@ -92,15 +92,42 @@ def _media_ns_extra():
|
||||
|
||||
|
||||
def _normalize_media_aliases(upstream):
|
||||
"""同类接口对外契约统一(2026-09-05 用户规则):上传媒体一律 xxx_file 命名。
|
||||
"""同类接口对外契约统一(2026-09-06 用户定夺,对齐 sage/llmage):
|
||||
上传媒体一律三数组参数 image_files / audio_files / video_files,
|
||||
值为字符串或数组均可(模板 Jinja 动态判断两种形态)。
|
||||
|
||||
旧别名 xxx_url 归一到 xxx_file——同能力模板写法一致(如 i2v 统一
|
||||
image_file 进 → video 出),模板不用为同一类能力写多套参数名。
|
||||
旧别名归一:xxx_file / xxx_url(单值)→ xxx_files(数组);
|
||||
DashScope 形态的 media 数组([{"type": "reference_image", "url": ...}]
|
||||
或纯 URL 列表)→ 按 type 分组进三数组(r2v 实测调用方直接传 media)。
|
||||
"""
|
||||
for media in ('image', 'video', 'audio'):
|
||||
fk, uk = media + '_file', media + '_url'
|
||||
if not upstream.get(fk) and upstream.get(uk):
|
||||
upstream[fk] = upstream.get(uk)
|
||||
files_k = media + '_files'
|
||||
if not upstream.get(files_k):
|
||||
for alt in (media + '_file', media + '_url'):
|
||||
v = upstream.get(alt)
|
||||
if v:
|
||||
upstream[files_k] = [v] if isinstance(v, str) else list(v)
|
||||
break
|
||||
m = upstream.get('media')
|
||||
if m and not any(upstream.get(x + '_files') for x in ('image', 'video', 'audio')):
|
||||
groups = {'image': [], 'video': [], 'audio': []}
|
||||
items = m if isinstance(m, list) else [m]
|
||||
for it in items:
|
||||
if isinstance(it, str) and it.strip():
|
||||
groups['image'].append(it)
|
||||
elif isinstance(it, dict):
|
||||
url = next((v for v in it.values()
|
||||
if isinstance(v, str) and v.strip().lower().startswith(
|
||||
('http://', 'https://', 'data:', 'asset://', '/'))), '')
|
||||
if not url:
|
||||
continue
|
||||
t = str(it.get('type') or '').lower()
|
||||
g = 'video' if 'video' in t else ('audio' if 'audio' in t else 'image')
|
||||
groups[g].append(url)
|
||||
for media, lst in groups.items():
|
||||
if lst:
|
||||
upstream[media + '_files'] = lst
|
||||
upstream.pop('media', None)
|
||||
|
||||
|
||||
def _texts_len(messages):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user