Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/server/rest_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,13 @@ void RestHandler::handle_openai_chat_completion(const json& request,
header_print("FLM", "Start prefill...");
bool success = auto_chat_engine->insert(meta_info, uniformed_input);
if (!success) {
json error_response = { {"error", "Max length reached"} };
json error_response = {
{"error", {
{"message", "Max length reached!"},
{"type", "model_error"},
{"code", 400}
}}
};
send_response(error_response);
return;
}
Expand Down
17 changes: 16 additions & 1 deletion src/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,22 @@ bool WebServer::handle_request(http::request<http::string_body>& req,

// catch is_deferred
auto send_response = [&res, session, this, request_id, needs_npu, is_deferred](const json& response_data) {
res.result(http::status::ok);
http::status status = http::status::ok;

if (response_data.contains("error") &&
response_data["error"].contains("code"))
{
int code = response_data["error"]["code"].get<int>();

if (code == 400) {
status = http::status::bad_request;
}
//else if () {

//}
}

res.result(status);
res.body() = response_data.dump();
res.set(http::field::content_type, "application/json");
res.prepare_payload();
Expand Down