Skip to content

Commit c2d8f61

Browse files
fix: remote engine: mistral error on stream mode (#1871)
Co-authored-by: vansangpfiev <[email protected]>
1 parent d847779 commit c2d8f61

File tree

3 files changed

+63
-61
lines changed

3 files changed

+63
-61
lines changed

engine/controllers/models.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ void Models::StartModel(
526526
if (auto& o = (*(req->getJsonObject()))["llama_model_path"]; !o.isNull()) {
527527
auto model_path = o.asString();
528528
if (auto& mp = (*(req->getJsonObject()))["model_path"]; mp.isNull()) {
529+
mp = model_path;
529530
// Bypass if model does not exist in DB and llama_model_path exists
530531
if (std::filesystem::exists(model_path) &&
531532
!model_service_->HasModel(model_handle)) {

engine/extensions/remote-engine/remote_engine.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ size_t StreamWriteCallback(char* ptr, size_t size, size_t nmemb,
2727
auto* context = static_cast<StreamContext*>(userdata);
2828
std::string chunk(ptr, size * nmemb);
2929
CTL_DBG(chunk);
30-
auto check_error = json_helper::ParseJsonString(chunk);
31-
if (check_error.isMember("error")) {
30+
Json::Value check_error;
31+
Json::Reader reader;
32+
if (reader.parse(chunk, check_error)) {
3233
CTL_WRN(chunk);
3334
Json::Value status;
3435
status["is_done"] = true;

engine/services/model_service.cc

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -819,75 +819,75 @@ cpp::result<StartModelResult, std::string> ModelService::StartModel(
819819
constexpr const int kDefautlContextLength = 8192;
820820
int max_model_context_length = kDefautlContextLength;
821821
Json::Value json_data;
822-
auto model_entry = db_service_->GetModelInfo(model_handle);
823-
if (model_entry.has_error()) {
824-
CTL_WRN("Error: " + model_entry.error());
825-
return cpp::fail(model_entry.error());
826-
}
827-
yaml_handler.ModelConfigFromFile(
828-
fmu::ToAbsoluteCortexDataPath(
829-
fs::path(model_entry.value().path_to_model_yaml))
830-
.string());
831-
auto mc = yaml_handler.GetModelConfig();
832-
833-
// Check if Python model first
834-
if (mc.engine == kPythonEngine) {
835-
836-
config::PythonModelConfig python_model_config;
837-
python_model_config.ReadFromYaml(
838-
822+
// Currently we don't support download vision models, so we need to bypass check
823+
if (!bypass_model_check) {
824+
auto model_entry = db_service_->GetModelInfo(model_handle);
825+
if (model_entry.has_error()) {
826+
CTL_WRN("Error: " + model_entry.error());
827+
return cpp::fail(model_entry.error());
828+
}
829+
yaml_handler.ModelConfigFromFile(
839830
fmu::ToAbsoluteCortexDataPath(
840831
fs::path(model_entry.value().path_to_model_yaml))
841832
.string());
842-
// Start all depends model
843-
auto depends = python_model_config.depends;
844-
for (auto& depend : depends) {
845-
Json::Value temp;
846-
auto res = StartModel(depend, temp, false);
847-
if (res.has_error()) {
848-
CTL_WRN("Error: " + res.error());
849-
for (auto& depend : depends) {
850-
if (depend != model_handle) {
851-
StopModel(depend);
833+
auto mc = yaml_handler.GetModelConfig();
834+
835+
// Check if Python model first
836+
if (mc.engine == kPythonEngine) {
837+
838+
config::PythonModelConfig python_model_config;
839+
python_model_config.ReadFromYaml(
840+
841+
fmu::ToAbsoluteCortexDataPath(
842+
fs::path(model_entry.value().path_to_model_yaml))
843+
.string());
844+
// Start all depends model
845+
auto depends = python_model_config.depends;
846+
for (auto& depend : depends) {
847+
Json::Value temp;
848+
auto res = StartModel(depend, temp, false);
849+
if (res.has_error()) {
850+
CTL_WRN("Error: " + res.error());
851+
for (auto& depend : depends) {
852+
if (depend != model_handle) {
853+
StopModel(depend);
854+
}
852855
}
856+
return cpp::fail("Model failed to start dependency '" + depend +
857+
"' : " + res.error());
853858
}
854-
return cpp::fail("Model failed to start dependency '" + depend +
855-
"' : " + res.error());
856859
}
857-
}
858860

859-
json_data["model"] = model_handle;
860-
json_data["model_path"] =
861-
fmu::ToAbsoluteCortexDataPath(
862-
fs::path(model_entry.value().path_to_model_yaml))
863-
.string();
864-
json_data["engine"] = mc.engine;
865-
assert(!!inference_svc_);
866-
// Check if python engine
867-
868-
auto ir =
869-
inference_svc_->LoadModel(std::make_shared<Json::Value>(json_data));
870-
auto status = std::get<0>(ir)["status_code"].asInt();
871-
auto data = std::get<1>(ir);
872-
873-
if (status == drogon::k200OK) {
874-
return StartModelResult{.success = true, .warning = ""};
875-
} else if (status == drogon::k409Conflict) {
876-
CTL_INF("Model '" + model_handle + "' is already loaded");
877-
return StartModelResult{.success = true, .warning = ""};
878-
} else {
879-
// only report to user the error
880-
for (auto& depend : depends) {
861+
json_data["model"] = model_handle;
862+
json_data["model_path"] =
863+
fmu::ToAbsoluteCortexDataPath(
864+
fs::path(model_entry.value().path_to_model_yaml))
865+
.string();
866+
json_data["engine"] = mc.engine;
867+
assert(!!inference_svc_);
868+
// Check if python engine
869+
870+
auto ir =
871+
inference_svc_->LoadModel(std::make_shared<Json::Value>(json_data));
872+
auto status = std::get<0>(ir)["status_code"].asInt();
873+
auto data = std::get<1>(ir);
881874

882-
StopModel(depend);
875+
if (status == drogon::k200OK) {
876+
return StartModelResult{.success = true, .warning = ""};
877+
} else if (status == drogon::k409Conflict) {
878+
CTL_INF("Model '" + model_handle + "' is already loaded");
879+
return StartModelResult{.success = true, .warning = ""};
880+
} else {
881+
// only report to user the error
882+
for (auto& depend : depends) {
883+
884+
StopModel(depend);
885+
}
883886
}
887+
CTL_ERR("Model failed to start with status code: " << status);
888+
return cpp::fail("Model failed to start: " +
889+
data["message"].asString());
884890
}
885-
CTL_ERR("Model failed to start with status code: " << status);
886-
return cpp::fail("Model failed to start: " + data["message"].asString());
887-
}
888-
889-
// Currently we don't support download vision models, so we need to bypass check
890-
if (!bypass_model_check) {
891891

892892
// Running remote model
893893
if (engine_svc_->IsRemoteEngine(mc.engine)) {

0 commit comments

Comments
 (0)