fix openai error message
This commit is contained in:
parent
a594729d00
commit
21da2f6373
|
@ -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'")
|
return format_oai_err(f"{parameters['top_p']} is greater than the maximum of 1 - 'top_p'")
|
||||||
if parameters.get('top_p', 1) < 0:
|
if parameters.get('top_p', 1) < 0:
|
||||||
return format_oai_err(f"{parameters['top_p']} less than the minimum of 0 - 'top_p'")
|
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'")
|
||||||
|
|
|
@ -100,4 +100,4 @@ def validate_json(data: Union[str, flask.Request, requests.models.Response, flas
|
||||||
j = json.loads(str(data))
|
j = json.loads(str(data))
|
||||||
return True, j
|
return True, j
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return False, e
|
return False, e
|
|
@ -27,6 +27,9 @@ def openai_chat_completions():
|
||||||
handler = OpenAIRequestHandler(incoming_request=request, incoming_json=request_json_body)
|
handler = OpenAIRequestHandler(incoming_request=request, incoming_json=request_json_body)
|
||||||
if not request_json_body.get('stream'):
|
if not request_json_body.get('stream'):
|
||||||
try:
|
try:
|
||||||
|
invalid_oai_err_msg = validate_oai(request_json_body)
|
||||||
|
if invalid_oai_err_msg:
|
||||||
|
return invalid_oai_err_msg
|
||||||
return handler.handle_request()
|
return handler.handle_request()
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
|
@ -44,6 +44,9 @@ def openai_completions():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not request_json_body.get('stream'):
|
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)
|
response, status_code = handler.handle_request(return_ok=False)
|
||||||
if status_code == 429:
|
if status_code == 429:
|
||||||
return handler.handle_ratelimited()
|
return handler.handle_ratelimited()
|
||||||
|
|
|
@ -171,7 +171,17 @@ class RequestHandler:
|
||||||
else:
|
else:
|
||||||
error_msg = error_msg.strip('.') + '.'
|
error_msg = error_msg.strip('.') + '.'
|
||||||
backend_response = self.handle_error(error_msg)
|
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
|
return (False, None, None, 0), backend_response
|
||||||
|
|
||||||
# ===============================================
|
# ===============================================
|
||||||
|
|
Reference in New Issue