From 21da2f63738953d64e7000d608941308a42f3c92 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Sun, 1 Oct 2023 22:58:08 -0600 Subject: [PATCH] fix openai error message --- llm_server/llm/openai/oai_to_vllm.py | 3 +++ llm_server/routes/helpers/http.py | 2 +- llm_server/routes/openai/chat_completions.py | 3 +++ llm_server/routes/openai/completions.py | 3 +++ llm_server/routes/request_handler.py | 12 +++++++++++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/llm_server/llm/openai/oai_to_vllm.py b/llm_server/llm/openai/oai_to_vllm.py index 237dc16..ce59e9b 100644 --- a/llm_server/llm/openai/oai_to_vllm.py +++ b/llm_server/llm/openai/oai_to_vllm.py @@ -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'") diff --git a/llm_server/routes/helpers/http.py b/llm_server/routes/helpers/http.py index 2fa1190..a3f1906 100644 --- a/llm_server/routes/helpers/http.py +++ b/llm_server/routes/helpers/http.py @@ -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 \ No newline at end of file diff --git a/llm_server/routes/openai/chat_completions.py b/llm_server/routes/openai/chat_completions.py index e00d665..e59f255 100644 --- a/llm_server/routes/openai/chat_completions.py +++ b/llm_server/routes/openai/chat_completions.py @@ -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() diff --git a/llm_server/routes/openai/completions.py b/llm_server/routes/openai/completions.py index 7bed9fa..e772842 100644 --- a/llm_server/routes/openai/completions.py +++ b/llm_server/routes/openai/completions.py @@ -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() diff --git a/llm_server/routes/request_handler.py b/llm_server/routes/request_handler.py index a595b89..f93547b 100644 --- a/llm_server/routes/request_handler.py +++ b/llm_server/routes/request_handler.py @@ -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 # ===============================================