fix openai error message

This commit is contained in:
Cyberes 2023-10-01 22:58:08 -06:00
parent a594729d00
commit 21da2f6373
5 changed files with 21 additions and 2 deletions

View File

@ -61,3 +61,6 @@ def validate_oai(parameters):
return format_oai_err(f"{parameters['top_p']} is greater than the maximum of 1 - 'top_p'")
if parameters.get('top_p', 1) < 0:
return format_oai_err(f"{parameters['top_p']} less than the minimum of 0 - 'top_p'")
if parameters.get('max_tokens', 2) < 1:
return format_oai_err(f"{parameters['max_tokens']} is less than the minimum of 1 - 'max_tokens'")

View File

@ -100,4 +100,4 @@ def validate_json(data: Union[str, flask.Request, requests.models.Response, flas
j = json.loads(str(data))
return True, j
except Exception as e:
return False, e
return False, e

View File

@ -27,6 +27,9 @@ def openai_chat_completions():
handler = OpenAIRequestHandler(incoming_request=request, incoming_json=request_json_body)
if not request_json_body.get('stream'):
try:
invalid_oai_err_msg = validate_oai(request_json_body)
if invalid_oai_err_msg:
return invalid_oai_err_msg
return handler.handle_request()
except Exception:
traceback.print_exc()

View File

@ -44,6 +44,9 @@ def openai_completions():
pass
if not request_json_body.get('stream'):
invalid_oai_err_msg = validate_oai(request_json_body)
if invalid_oai_err_msg:
return invalid_oai_err_msg
response, status_code = handler.handle_request(return_ok=False)
if status_code == 429:
return handler.handle_ratelimited()

View File

@ -171,7 +171,17 @@ class RequestHandler:
else:
error_msg = error_msg.strip('.') + '.'
backend_response = self.handle_error(error_msg)
log_prompt(self.client_ip, self.token, prompt, backend_response[0].data.decode('utf-8'), None, self.parameters, dict(self.request.headers), response_status_code, self.request.url, self.backend_url, is_error=True)
log_prompt(ip=self.client_ip,
token=self.token,
prompt=prompt,
response=backend_response[0].data.decode('utf-8'),
gen_time=None,
parameters=self.parameters,
headers=dict(self.request.headers),
backend_response_code=response_status_code,
request_url=self.request.url,
backend_url=self.backend_url,
is_error=True)
return (False, None, None, 0), backend_response
# ===============================================