Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit e57f80c

Browse files
fix: bypass check model id if llama_model_path exists (#1706)
* fix: bypass check model id if llama_model_path exists * fix: correct logic * fix: check db first --------- Co-authored-by: vansangpfiev <sang@jan.ai>
1 parent e5e506a commit e57f80c

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

engine/controllers/models.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,14 @@ void Models::StartModel(
442442
// model_path has higher priority
443443
if (auto& o = (*(req->getJsonObject()))["llama_model_path"]; !o.isNull()) {
444444
params_override.model_path = o.asString();
445+
if (auto& mp = (*(req->getJsonObject()))["model_path"]; mp.isNull()) {
446+
// Bypass if model does not exist in DB and llama_model_path exists
447+
if (std::filesystem::exists(params_override.model_path.value()) &&
448+
!model_service_->HasModel(model_handle)) {
449+
CTL_INF("llama_model_path exists, bypass check model id");
450+
params_override.bypass_llama_model_path = true;
451+
}
452+
}
445453
}
446454

447455
if (auto& o = (*(req->getJsonObject()))["model_path"]; !o.isNull()) {
@@ -489,7 +497,7 @@ void Models::StartModel(
489497
auto& v = result.value();
490498
Json::Value ret;
491499
ret["message"] = "Started successfully!";
492-
if(v.warning) {
500+
if (v.warning) {
493501
ret["warning"] = *(v.warning);
494502
}
495503
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);

engine/services/model_service.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ cpp::result<std::string, std::string> ModelService::HandleUrl(
381381
return unique_model_id;
382382
}
383383

384+
bool ModelService::HasModel(const std::string& id) const {
385+
return cortex::db::Models().HasModel(id);
386+
}
387+
384388
cpp::result<DownloadTask, std::string>
385389
ModelService::DownloadModelFromCortexsoAsync(
386390
const std::string& name, const std::string& branch,
@@ -745,7 +749,8 @@ cpp::result<StartModelResult, std::string> ModelService::StartModel(
745749
return cpp::fail(
746750
"Not enough VRAM - required: " + std::to_string(vram_needed_MiB) +
747751
" MiB, available: " + std::to_string(free_vram_MiB) +
748-
" MiB - Should adjust ngl to " + std::to_string(free_vram_MiB / (vram_needed_MiB / ngl) - 1));
752+
" MiB - Should adjust ngl to " +
753+
std::to_string(free_vram_MiB / (vram_needed_MiB / ngl) - 1));
749754
}
750755

751756
if (ram_needed_MiB > free_ram_MiB) {

engine/services/model_service.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#include <memory>
44
#include <optional>
55
#include <string>
6+
#include "common/engine_servicei.h"
67
#include "config/model_config.h"
78
#include "services/download_service.h"
89
#include "services/inference_service.h"
9-
#include "common/engine_servicei.h"
1010

1111
struct ModelPullInfo {
1212
std::string id;
@@ -26,12 +26,15 @@ struct StartParameterOverride {
2626
std::optional<std::string> cache_type;
2727
std::optional<std::string> mmproj;
2828
std::optional<std::string> model_path;
29-
bool bypass_model_check() const { return mmproj.has_value(); }
29+
bool bypass_llama_model_path = false;
30+
bool bypass_model_check() const {
31+
return mmproj.has_value() || bypass_llama_model_path;
32+
}
3033
};
3134

3235
struct StartModelResult {
33-
bool success;
34-
std::optional<std::string> warning;
36+
bool success;
37+
std::optional<std::string> warning;
3538
};
3639

3740
class ModelService {
@@ -89,6 +92,8 @@ class ModelService {
8992
const std::string& url, std::optional<std::string> temp_model_id,
9093
std::optional<std::string> temp_name);
9194

95+
bool HasModel(const std::string& id) const;
96+
9297
private:
9398
/**
9499
* Handle downloading model which have following pattern: author/model_name

0 commit comments

Comments
 (0)