AstheralPlus / tests /test_live_modes.py
SEE7's picture
Add real Instruct and Thinking endpoint smoke tests
8ae83bd verified
Raw History Blame Contribute Delete
1.34 kB
import os,json,time,urllib.request
from pathlib import Path
url='https://see7-astheralplus.hf.space/v1/chat/completions'
results=[]
for mode,prompt,expected in [('Instruct','Reply with just OK.','OK'),('Thinking','What is 17 multiplied by 19?','323')]:
payload={'model':'SEE7/AstheralPlus','messages':[{'role':'user','content':prompt}],'stream':True,'max_tokens':512,'temperature':0,'chat_template_kwargs':{'enable_thinking':mode=='Thinking'}}
req=urllib.request.Request(url,data=json.dumps(payload).encode(),headers={'Content-Type':'application/json','Authorization':'Bearer '+os.environ['HF_TOKEN']})
start=time.monotonic();parts=[];events=[]
with urllib.request.urlopen(req,timeout=170) as response:
for line in response:
s=line.decode().strip()
if not s.startswith('data:'):continue
raw=s[5:].strip()
if raw=='[DONE]':break
event=json.loads(raw);events.append(event)
if 'error' in event:raise RuntimeError(str(event['error']))
for c in event.get('choices',[]):parts.append(c.get('delta',{}).get('content',''))
text=''.join(parts);assert expected in text,(mode,text)
row={'mode':mode,'prompt':prompt,'response':text,'elapsed_seconds':time.monotonic()-start,'passed':True}
results.append(row);print(json.dumps(row),flush=True)
Path('/tmp/live_plus_results.json').write_text(json.dumps(results,indent=2))