import argparse
import json
import time
import urllib.request

p = argparse.ArgumentParser()
p.add_argument('prompt', help='Pelny prompt zgodny z szablonem modelu')
p.add_argument('--port', type=int, default=5001)
a = p.parse_args()
body = {'prompt': a.prompt, 'max_length': 256, 'max_context_length': 4096,
        'temperature': 0.7, 'sampler_seed': 42}
request = urllib.request.Request(
    f'http://127.0.0.1:{a.port}/api/v1/generate',
    data=json.dumps(body).encode('utf-8'),
    headers={'Content-Type': 'application/json'})
start = time.perf_counter()
with urllib.request.urlopen(request, timeout=240) as response:
    result = json.load(response)
print(result['results'][0]['text'])
print('Czas zadania: %.2f s' % (time.perf_counter() - start))
