This repository was archived by the owner on Jul 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 181
Feat/model import cmd #1248
Merged
Merged
Feat/model import cmd #1248
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f606e66
add model import command
nguyenhoangthuan99 cc4200b
Add name to model.yml
nguyenhoangthuan99 f9af680
add e2e test
nguyenhoangthuan99 e372d94
Merge branch 'dev' of github.com:janhq/cortex into feat/model-import-cmd
nguyenhoangthuan99 c8bd76e
Add API for import model
nguyenhoangthuan99 4560f90
Merge branch 'dev' into feat/model-import-cmd
nguyenhoangthuan99 db17979
Merge branch 'dev' of github.com:janhq/cortex into feat/model-import-cmd
nguyenhoangthuan99 17973f0
Merge branch 'feat/model-import-cmd' of github.com:janhq/cortex into …
nguyenhoangthuan99 68e7c69
Merge branch 'dev' into feat/model-import-cmd
nguyenhoangthuan99 4a6d08d
Update model_import_cmd.cc
nguyenhoangthuan99 009139d
Fix comment
nguyenhoangthuan99 f9d09dd
Merge branch 'dev' of github.com:janhq/cortex into feat/model-import-cmd
nguyenhoangthuan99 b1c26f0
Merge branch 'feat/model-import-cmd' of github.com:janhq/cortex into …
nguyenhoangthuan99 5cc0161
Merge branch 'dev' into feat/model-import-cmd
nguyenhoangthuan99 ad72ea4
Fix comment
nguyenhoangthuan99 054203e
merge from dev
nguyenhoangthuan99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include "model_import_cmd.h" | ||
| #include <filesystem> | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include "config/gguf_parser.h" | ||
| #include "config/yaml_config.h" | ||
| #include "trantor/utils/Logger.h" | ||
| #include "utils/file_manager_utils.h" | ||
| #include "utils/logging_utils.h" | ||
| #include "utils/modellist_utils.h" | ||
|
|
||
| namespace commands { | ||
|
|
||
| ModelImportCmd::ModelImportCmd(std::string model_handle, std::string model_path) | ||
| : model_handle_(std::move(model_handle)), | ||
| model_path_(std::move(model_path)) {} | ||
|
|
||
| void ModelImportCmd::Exec() { | ||
| config::GGUFHandler gguf_handler; | ||
| config::YamlHandler yaml_handler; | ||
| modellist_utils::ModelListUtils modellist_utils_obj; | ||
|
|
||
| std::string model_yaml_path = (file_manager_utils::GetModelsContainerPath() / | ||
| std::filesystem::path("imported") / | ||
| std::filesystem::path(model_handle_ + ".yml")) | ||
| .string(); | ||
| modellist_utils::ModelEntry model_entry{ | ||
| model_handle_, "local", "imported", | ||
| model_yaml_path, model_handle_, modellist_utils::ModelStatus::READY}; | ||
| try { | ||
| std::filesystem::create_directories( | ||
| std::filesystem::path(model_yaml_path).parent_path()); | ||
| gguf_handler.Parse(model_path_); | ||
| auto model_config = gguf_handler.GetModelConfig(); | ||
| model_config.files.push_back(model_path_); | ||
| model_config.model = model_handle_; | ||
| yaml_handler.UpdateModelConfig(model_config); | ||
|
|
||
| if (modellist_utils_obj.AddModelEntry(model_entry)) { | ||
| yaml_handler.WriteYamlFile(model_yaml_path); | ||
| CLI_LOG("Model is imported successfully!"); | ||
| } else { | ||
| CLI_LOG("Fail to import model, model_id '" + model_handle_ + | ||
| "' already exists!"); | ||
| } | ||
|
|
||
| } catch (const std::exception& e) { | ||
| std::remove(model_yaml_path.c_str()); | ||
| CLI_LOG("Error importing model path '" + model_path_ + "' with model_id '" + | ||
| model_handle_ + "': " + e.what()); | ||
| } | ||
| } | ||
| } // namespace commands |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
| namespace commands { | ||
|
|
||
| class ModelImportCmd { | ||
| public: | ||
| ModelImportCmd(std::string model_handle, std::string model_path); | ||
| void Exec(); | ||
|
|
||
| private: | ||
| std::string model_handle_; | ||
| std::string model_path_; | ||
| }; | ||
| } // namespace commands |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import pytest | ||
| from test_runner import run | ||
|
|
||
| class TestCliModelImport: | ||
|
|
||
| @pytest.mark.skipif(True, reason="Expensive test. Only test when you have local gguf file.") | ||
| def test_model_import_should_be_success(self): | ||
|
|
||
| exit_code, output, error = run( | ||
| "Pull model", ["models", "import", "--model_id","test_model","--model_path","/path/to/local/gguf"], | ||
| timeout=None | ||
| ) | ||
| assert exit_code == 0, f"Model import failed failed with error: {error}" | ||
| # TODO: skip this test. since download model is taking too long | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.