32 lines
1.9 KiB
Python
32 lines
1.9 KiB
Python
"""Verify actual image/video ingestion using deterministic local probes."""
|
|
import argparse
|
|
import base64
|
|
import json
|
|
import time
|
|
import urllib.request
|
|
from pathlib import Path
|
|
|
|
p=argparse.ArgumentParser()
|
|
p.add_argument('--output',type=Path,required=True)
|
|
p.add_argument('--assets',type=Path,default=Path('/data/flash-next/cache'))
|
|
a=p.parse_args()
|
|
key=(Path(__file__).resolve().parents[1]/'secrets/api-key').read_text().strip()
|
|
cases=[('image','image/png','probe.png','What is the main color of this image? Reply with one English word.', ['red']),
|
|
('video','video/mp4','probe.mp4','List the background colors in chronological order. Reply only with the three English color names.', ['red','green','blue'])]
|
|
with a.output.open('x') as out:
|
|
for kind,mime,name,prompt,colors in cases:
|
|
url='data:'+mime+';base64,'+base64.b64encode((a.assets/name).read_bytes()).decode()
|
|
part=kind+'_url'
|
|
body=dict(model='qwen3.8-flash-next',temperature=0,reasoning_effort='low',max_tokens=1024,
|
|
messages=[dict(role='user',content=[dict(type='text',text=prompt),{'type':part,part:{'url':url}}])])
|
|
start=time.monotonic()
|
|
req=urllib.request.Request('http://127.0.0.1:8000/v1/chat/completions',data=json.dumps(body).encode(),
|
|
headers={'Content-Type':'application/json','Authorization':'Bearer '+key})
|
|
with urllib.request.urlopen(req,timeout=600) as response: result=json.load(response)
|
|
choice=result['choices'][0]; content=choice['message'].get('content') or ''
|
|
pos=[content.lower().find(c) for c in colors]
|
|
passed=all(x>=0 for x in pos) and pos==sorted(pos) and choice['finish_reason']=='stop'
|
|
row=dict(test=kind,passed=passed,elapsed_s=time.monotonic()-start,response=result)
|
|
line=json.dumps(row,ensure_ascii=False); out.write(line+'\n'); out.flush(); print(line,flush=True)
|
|
if not passed: raise SystemExit('Multimodal probe failed: '+kind)
|