11#include " model_get_cmd.h"
22#include < filesystem>
3+ #include < iomanip>
34#include < iostream>
45#include < vector>
56#include " cmd_info.h"
67#include " config/yaml_config.h"
78#include " utils/file_manager_utils.h"
89#include " utils/logging_utils.h"
10+ #include " utils/modellist_utils.h"
911
1012namespace commands {
1113
1214void ModelGetCmd::Exec (const std::string& model_handle) {
13- auto models_path = file_manager_utils::GetModelsContainerPath ();
14- if (std::filesystem::exists (models_path) &&
15- std::filesystem::is_directory (models_path)) {
16- CmdInfo ci (model_handle);
17- std::string model_file =
18- ci.branch == " main" ? ci.model_name : ci.model_name + " -" + ci.branch ;
19- bool found_model = false ;
20- // Iterate through directory
21- for (const auto & entry : std::filesystem::directory_iterator (models_path)) {
22-
23- if (entry.is_regular_file () && entry.path ().stem () == model_file &&
24- entry.path ().extension () == " .yaml" ) {
25- try {
26- config::YamlHandler handler;
27- handler.ModelConfigFromFile (entry.path ().string ());
28- const auto & model_config = handler.GetModelConfig ();
29- std::cout << " ModelConfig Details:\n " ;
30- std::cout << " -------------------\n " ;
31-
32- // Print non-null strings
33- if (!model_config.id .empty ())
34- std::cout << " id: " << model_config.id << " \n " ;
35- if (!model_config.name .empty ())
36- std::cout << " name: " << model_config.name << " \n " ;
37- if (!model_config.model .empty ())
38- std::cout << " model: " << model_config.model << " \n " ;
39- if (!model_config.version .empty ())
40- std::cout << " version: " << model_config.version << " \n " ;
41-
42- // Print non-empty vectors
43- if (!model_config.stop .empty ()) {
44- std::cout << " stop: [" ;
45- for (size_t i = 0 ; i < model_config.stop .size (); ++i) {
46- std::cout << model_config.stop [i];
47- if (i < model_config.stop .size () - 1 )
48- std::cout << " , " ;
49- }
50- std::cout << " ]\n " ;
51- }
52- // Print valid numbers
53- if (!std::isnan (static_cast <double >(model_config.top_p )))
54- std::cout << " top_p: " << model_config.top_p << " \n " ;
55- if (!std::isnan (static_cast <double >(model_config.temperature )))
56- std::cout << " temperature: " << model_config.temperature << " \n " ;
57- if (!std::isnan (static_cast <double >(model_config.frequency_penalty )))
58- std::cout << " frequency_penalty: " << model_config.frequency_penalty
59- << " \n " ;
60- if (!std::isnan (static_cast <double >(model_config.presence_penalty )))
61- std::cout << " presence_penalty: " << model_config.presence_penalty
62- << " \n " ;
63- if (!std::isnan (static_cast <double >(model_config.max_tokens )))
64- std::cout << " max_tokens: " << model_config.max_tokens << " \n " ;
65- if (!std::isnan (static_cast <double >(model_config.stream )))
66-
67- std::cout << " stream: " << std::boolalpha << model_config.stream
68- << " \n " ;
69- if (!std::isnan (static_cast <double >(model_config.ngl )))
70- std::cout << " ngl: " << model_config.ngl << " \n " ;
71- if (!std::isnan (static_cast <double >(model_config.ctx_len )))
72- std::cout << " ctx_len: " << model_config.ctx_len << " \n " ;
73-
74- // Print non-null strings
75- if (!model_config.engine .empty ())
76- std::cout << " engine: " << model_config.engine << " \n " ;
77- if (!model_config.prompt_template .empty ())
78-
79- std::cout << " prompt_template: " << model_config.prompt_template
80- << " \n " ;
81- if (!model_config.system_template .empty ())
82- std::cout << " system_template: " << model_config.system_template
83- << " \n " ;
84- if (!model_config.user_template .empty ())
85- std::cout << " user_template: " << model_config.user_template
86- << " \n " ;
87- if (!model_config.ai_template .empty ())
88- std::cout << " ai_template: " << model_config.ai_template << " \n " ;
89- if (!model_config.os .empty ())
90- std::cout << " os: " << model_config.os << " \n " ;
91- if (!model_config.gpu_arch .empty ())
92- std::cout << " gpu_arch: " << model_config.gpu_arch << " \n " ;
93- if (!model_config.quantization_method .empty ())
94-
95- std::cout << " quantization_method: "
96- << model_config.quantization_method << " \n " ;
97- if (!model_config.precision .empty ())
98- std::cout << " precision: " << model_config.precision << " \n " ;
99-
100- if (!std::isnan (static_cast <double >(model_config.tp )))
101- std::cout << " tp: " << model_config.tp << " \n " ;
102-
103- // Print non-null strings
104- if (!model_config.trtllm_version .empty ())
105-
106- std::cout << " trtllm_version: " << model_config.trtllm_version
107- << " \n " ;
108- if (!std::isnan (static_cast <double >(model_config.text_model )))
109- std::cout << " text_model: " << std::boolalpha
110- << model_config.text_model << " \n " ;
111-
112- // Print non-empty vectors
113- if (!model_config.files .empty ()) {
114- std::cout << " files: [" ;
115- for (size_t i = 0 ; i < model_config.files .size (); ++i) {
116- std::cout << model_config.files [i];
117- if (i < model_config.files .size () - 1 )
118- std::cout << " , " ;
119- }
120- std::cout << " ]\n " ;
121- }
122-
123- // Print valid size_t number
124- if (model_config.created != 0 )
125- std::cout << " created: " << model_config.created << " \n " ;
126-
127- if (!model_config.object .empty ())
128- std::cout << " object: " << model_config.object << " \n " ;
129- if (!model_config.owned_by .empty ())
130- std::cout << " owned_by: " << model_config.owned_by << " \n " ;
131-
132- found_model = true ;
133- break ;
134- } catch (const std::exception& e) {
135- CTL_ERR (" Error reading yaml file '" << entry.path ().string ()
136- << " ': " << e.what ());
137- }
138- }
139- }
140- if (!found_model) {
141- CLI_LOG (" Model not found!" );
142- }
143- } else {
144- CLI_LOG (" Model not found!" );
15+ modellist_utils::ModelListUtils modellist_handler;
16+ config::YamlHandler yaml_handler;
17+ try {
18+ auto model_entry = modellist_handler.GetModelInfo (model_handle);
19+ yaml_handler.ModelConfigFromFile (model_entry.path_to_model_yaml );
20+ auto model_config = yaml_handler.GetModelConfig ();
21+
22+ std::cout << model_config.ToString () << std::endl;
23+
24+ } catch (const std::exception& e) {
25+ CLI_LOG (" Fail to get model information with ID '" + model_handle +
26+ " ': " + e.what ());
14527 }
14628}
147- }; // namespace commands
29+
30+ } // namespace commands
0 commit comments