MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / add_model

Method add_model

tools/server/server-models.cpp:186–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184}
185
186void server_models::add_model(server_model_meta && meta) {
187 if (mapping.find(meta.name) != mapping.end()) {
188 throw std::runtime_error(string_format("model '%s' appears multiple times", meta.name.c_str()));
189 }
190
191 // check model name does not conflict with existing aliases
192 for (const auto & [key, inst] : mapping) {
193 if (inst.meta.aliases.count(meta.name)) {
194 throw std::runtime_error(string_format("model name '%s' conflicts with alias of model '%s'",
195 meta.name.c_str(), key.c_str()));
196 }
197 }
198
199 // parse aliases from preset's --alias option (comma-separated)
200 std::string alias_str;
201 if (meta.preset.get_option("LLAMA_ARG_ALIAS", alias_str) && !alias_str.empty()) {
202 for (auto & alias : string_split<std::string>(alias_str, ',')) {
203 alias = string_strip(alias);
204 if (!alias.empty()) {
205 meta.aliases.insert(alias);
206 }
207 }
208 }
209
210 // parse tags from preset's --tags option (comma-separated)
211 std::string tags_str;
212 if (meta.preset.get_option("LLAMA_ARG_TAGS", tags_str) && !tags_str.empty()) {
213 for (auto & tag : string_split<std::string>(tags_str, ',')) {
214 tag = string_strip(tag);
215 if (!tag.empty()) {
216 meta.tags.insert(tag);
217 }
218 }
219 }
220
221 // validate aliases do not conflict with existing names or aliases
222 for (const auto & alias : meta.aliases) {
223 if (mapping.find(alias) != mapping.end()) {
224 throw std::runtime_error(string_format("alias '%s' for model '%s' conflicts with existing model name",
225 alias.c_str(), meta.name.c_str()));
226 }
227 for (const auto & [key, inst] : mapping) {
228 if (inst.meta.aliases.count(alias)) {
229 throw std::runtime_error(string_format("alias '%s' for model '%s' conflicts with alias of model '%s'",
230 alias.c_str(), meta.name.c_str(), key.c_str()));
231 }
232 }
233 }
234
235 meta.update_args(ctx_preset, bin_path); // render args
236 std::string name = meta.name;
237 mapping[name] = instance_t{
238 /* subproc */ std::make_shared<subprocess_s>(),
239 /* th */ std::thread(),
240 /* meta */ std::move(meta)
241 };
242}
243

Callers

nothing calls this directly

Calls 9

string_stripFunction · 0.85
findMethod · 0.80
endMethod · 0.80
countMethod · 0.80
get_optionMethod · 0.80
update_argsMethod · 0.80
string_formatFunction · 0.50
emptyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected