This repository has been archived on 2024-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
2023-08-30 18:53:26 -06:00
|
|
|
"""
|
|
|
|
This file is used by the worker that processes requests.
|
|
|
|
"""
|
2023-09-24 13:02:30 -06:00
|
|
|
import traceback
|
2023-08-30 18:53:26 -06:00
|
|
|
|
2023-08-21 21:28:52 -06:00
|
|
|
import requests
|
|
|
|
|
|
|
|
from llm_server import opts
|
|
|
|
|
|
|
|
|
|
|
|
def generate(json_data: dict):
|
|
|
|
try:
|
2023-09-14 14:05:50 -06:00
|
|
|
r = requests.post(f'{opts.backend_url}/api/v1/generate', json=json_data, verify=opts.verify_ssl, timeout=opts.backend_generate_request_timeout)
|
|
|
|
except requests.exceptions.ReadTimeout:
|
|
|
|
return False, None, 'Request to backend timed out'
|
2023-08-21 21:28:52 -06:00
|
|
|
except Exception as e:
|
2023-09-24 13:02:30 -06:00
|
|
|
traceback.print_exc()
|
2023-09-14 14:05:50 -06:00
|
|
|
return False, None, 'Request to backend encountered error'
|
2023-08-21 21:28:52 -06:00
|
|
|
if r.status_code != 200:
|
|
|
|
return False, r, f'Backend returned {r.status_code}'
|
|
|
|
return True, r, None
|