File size: 1,212 Bytes
5cb93ca
 
 
 
 
 
 
 
 
 
27ca70c
 
 
 
 
 
 
5cb93ca
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import asyncio,json
from pathlib import Path
import torch
from coreai_mini import AmosMini
async def main():
 def forbidden(*a,**kw):raise AssertionError('PyTorch neural execution is forbidden in runtime smoke')
 torch.nn.Linear.forward=forbidden;torch.nn.Embedding.forward=forbidden;torch.nn.Conv2d.forward=forbidden
 root=Path('bundles/amos-1-mini-CoreAI');m=await AmosMini.load(root)
 out=await m.request({'state':'Please refund the duplicate charge.','questions':{'refund':{'type':'noul','instructions':'Is a refund requested?'}}})
 assert out['answers']['refund']['noul']>0.5,out
 from PIL import Image
 image_result=await m.predict('A red image.',[{'type':'region','text':'Point to the red area.'}],[Image.new('RGB',(360,240),'red')])
 assert image_result[0]['type']=='region'
 try:await m.predict('word '*1000,[{'type':'noul','text':'Is there text?'}])
 except ValueError:capacity_guard=True
 else:raise AssertionError('Over-capacity request was accepted')
 (root/'runtime-smoke.json').write_text(json.dumps({'passed':True,'pytorch_neural_execution_disabled':True,'capacity_guard':capacity_guard,'result':out,'image_result':image_result},indent=2))
 print(out)
if __name__=='__main__':asyncio.run(main())