-
Notifications
You must be signed in to change notification settings - Fork 317
fix error response format to match OpenAI API standard #1259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -58,11 +58,24 @@ | |||||
| logger = init_logger(__name__) | ||||||
|
|
||||||
|
|
||||||
| def create_error_response(status_code: HTTPStatus, message: str) -> JSONResponse: | ||||||
| def create_error_response( | ||||||
| status_code: HTTPStatus, message: str, err_type: str = None, param: str = None | ||||||
| ) -> JSONResponse: | ||||||
|
Comment on lines
+61
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is a duplicate of the one implemented in |
||||||
| from .api_http import g_objs | ||||||
|
|
||||||
| if err_type is None: | ||||||
| if status_code.value >= 500: | ||||||
| err_type = "InternalServerError" | ||||||
| elif status_code == HTTPStatus.NOT_FOUND: | ||||||
| err_type = "NotFoundError" | ||||||
| else: | ||||||
| err_type = "BadRequestError" | ||||||
|
|
||||||
| g_objs.metric_client.counter_inc("lightllm_request_failure") | ||||||
| return JSONResponse({"message": message}, status_code=status_code.value) | ||||||
| return JSONResponse( | ||||||
| {"error": {"message": message, "type": err_type, "param": param, "code": status_code.value}}, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
| status_code=status_code.value, | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def _process_tool_call_id( | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OpenAI API specification typically expects the
codefield to be a string ornull. Using an integer might cause issues with some client libraries that strictly validate types. Converting the status code to a string is a safer approach and matches the behavior of other OpenAI-compatible servers like vLLM.