|
15 | 15 | #include "utils/logging_utils.h" |
16 | 16 | #include "utils/result.hpp" |
17 | 17 | #include "utils/string_utils.h" |
18 | | -#include "utils/json_helper.h" |
19 | 18 |
|
20 | 19 | namespace { |
21 | 20 | void ParseGguf(const DownloadItem& ggufDownloadItem, |
@@ -577,39 +576,44 @@ cpp::result<bool, std::string> ModelService::StartModel( |
577 | 576 | config::YamlHandler yaml_handler; |
578 | 577 |
|
579 | 578 | try { |
580 | | - auto model_entry = modellist_handler.GetModelInfo(model_handle); |
581 | | - if (model_entry.has_error()) { |
582 | | - CTL_WRN("Error: " + model_entry.error()); |
583 | | - return cpp::fail(model_entry.error()); |
584 | | - } |
585 | | - yaml_handler.ModelConfigFromFile( |
586 | | - fmu::ToAbsoluteCortexDataPath( |
587 | | - fs::path(model_entry.value().path_to_model_yaml)) |
588 | | - .string()); |
589 | | - auto mc = yaml_handler.GetModelConfig(); |
590 | | - |
591 | | - httplib::Client cli(host + ":" + std::to_string(port)); |
| 579 | + Json::Value json_data; |
| 580 | + // Currently we don't support download vision models, so we need to bypass check |
| 581 | + if (!params_override.bypass_model_check()) { |
| 582 | + auto model_entry = modellist_handler.GetModelInfo(model_handle); |
| 583 | + if (model_entry.has_error()) { |
| 584 | + CTL_WRN("Error: " + model_entry.error()); |
| 585 | + return cpp::fail(model_entry.error()); |
| 586 | + } |
| 587 | + yaml_handler.ModelConfigFromFile( |
| 588 | + fmu::ToAbsoluteCortexDataPath( |
| 589 | + fs::path(model_entry.value().path_to_model_yaml)) |
| 590 | + .string()); |
| 591 | + auto mc = yaml_handler.GetModelConfig(); |
592 | 592 |
|
593 | | - Json::Value json_data = mc.ToJson(); |
594 | | - if (mc.files.size() > 0) { |
595 | | - // TODO(sang) support multiple files |
596 | | - json_data["model_path"] = |
597 | | - fmu::ToAbsoluteCortexDataPath(fs::path(mc.files[0])).string(); |
| 593 | + json_data = mc.ToJson(); |
| 594 | + if (mc.files.size() > 0) { |
| 595 | + // TODO(sang) support multiple files |
| 596 | + json_data["model_path"] = |
| 597 | + fmu::ToAbsoluteCortexDataPath(fs::path(mc.files[0])).string(); |
| 598 | + } else { |
| 599 | + LOG_WARN << "model_path is empty"; |
| 600 | + return false; |
| 601 | + } |
| 602 | + json_data["system_prompt"] = mc.system_template; |
| 603 | + json_data["user_prompt"] = mc.user_template; |
| 604 | + json_data["ai_prompt"] = mc.ai_template; |
598 | 605 | } else { |
599 | | - LOG_WARN << "model_path is empty"; |
600 | | - return false; |
| 606 | + bypass_stop_check_set_.insert(model_handle); |
601 | 607 | } |
| 608 | + httplib::Client cli(host + ":" + std::to_string(port)); |
| 609 | + |
602 | 610 | json_data["model"] = model_handle; |
603 | 611 | if (auto& cpt = params_override.custom_prompt_template; |
604 | 612 | !cpt.value_or("").empty()) { |
605 | 613 | auto parse_prompt_result = string_utils::ParsePrompt(cpt.value()); |
606 | 614 | json_data["system_prompt"] = parse_prompt_result.system_prompt; |
607 | 615 | json_data["user_prompt"] = parse_prompt_result.user_prompt; |
608 | 616 | json_data["ai_prompt"] = parse_prompt_result.ai_prompt; |
609 | | - } else { |
610 | | - json_data["system_prompt"] = mc.system_template; |
611 | | - json_data["user_prompt"] = mc.user_template; |
612 | | - json_data["ai_prompt"] = mc.ai_template; |
613 | 617 | } |
614 | 618 |
|
615 | 619 | #define ASSIGN_IF_PRESENT(json_obj, param_override, param_name) \ |
@@ -655,29 +659,38 @@ cpp::result<bool, std::string> ModelService::StopModel( |
655 | 659 | config::YamlHandler yaml_handler; |
656 | 660 |
|
657 | 661 | try { |
658 | | - auto model_entry = modellist_handler.GetModelInfo(model_handle); |
659 | | - if (model_entry.has_error()) { |
660 | | - CTL_WRN("Error: " + model_entry.error()); |
661 | | - return cpp::fail(model_entry.error()); |
| 662 | + auto bypass_check = (bypass_stop_check_set_.find(model_handle) != |
| 663 | + bypass_stop_check_set_.end()); |
| 664 | + Json::Value json_data; |
| 665 | + if (!bypass_check) { |
| 666 | + auto model_entry = modellist_handler.GetModelInfo(model_handle); |
| 667 | + if (model_entry.has_error()) { |
| 668 | + CTL_WRN("Error: " + model_entry.error()); |
| 669 | + return cpp::fail(model_entry.error()); |
| 670 | + } |
| 671 | + yaml_handler.ModelConfigFromFile( |
| 672 | + fmu::ToAbsoluteCortexDataPath( |
| 673 | + fs::path(model_entry.value().path_to_model_yaml)) |
| 674 | + .string()); |
| 675 | + auto mc = yaml_handler.GetModelConfig(); |
| 676 | + json_data["engine"] = mc.engine; |
662 | 677 | } |
663 | | - yaml_handler.ModelConfigFromFile( |
664 | | - fmu::ToAbsoluteCortexDataPath( |
665 | | - fs::path(model_entry.value().path_to_model_yaml)) |
666 | | - .string()); |
667 | | - auto mc = yaml_handler.GetModelConfig(); |
668 | 678 |
|
669 | 679 | httplib::Client cli(host + ":" + std::to_string(port)); |
670 | | - |
671 | | - Json::Value json_data; |
672 | 680 | json_data["model"] = model_handle; |
673 | | - json_data["engine"] = mc.engine; |
| 681 | + if (bypass_check) { |
| 682 | + json_data["engine"] = kLlamaEngine; |
| 683 | + } |
674 | 684 | CTL_INF(json_data.toStyledString()); |
675 | 685 | assert(inference_svc_); |
676 | 686 | auto ir = |
677 | 687 | inference_svc_->UnloadModel(std::make_shared<Json::Value>(json_data)); |
678 | 688 | auto status = std::get<0>(ir)["status_code"].asInt(); |
679 | 689 | auto data = std::get<1>(ir); |
680 | 690 | if (status == httplib::StatusCode::OK_200) { |
| 691 | + if (bypass_check) { |
| 692 | + bypass_stop_check_set_.erase(model_handle); |
| 693 | + } |
681 | 694 | return true; |
682 | 695 | } else { |
683 | 696 | CTL_ERR("Model failed to stop with status code: " << status); |
|
0 commit comments