MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / string_parse_kv_override

Function string_parse_kv_override

smallthinker/common/common.cpp:639–683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

637}
638
639bool string_parse_kv_override(const char * data, std::vector<llama_model_kv_override> & overrides) {
640 const char * sep = strchr(data, '=');
641 if (sep == nullptr || sep - data >= 128) {
642 LOG_ERR("%s: malformed KV override '%s'\n", __func__, data);
643 return false;
644 }
645 llama_model_kv_override kvo;
646 std::strncpy(kvo.key, data, sep - data);
647 kvo.key[sep - data] = 0;
648 sep++;
649 if (strncmp(sep, "int:", 4) == 0) {
650 sep += 4;
651 kvo.tag = LLAMA_KV_OVERRIDE_TYPE_INT;
652 kvo.val_i64 = std::atol(sep);
653 } else if (strncmp(sep, "float:", 6) == 0) {
654 sep += 6;
655 kvo.tag = LLAMA_KV_OVERRIDE_TYPE_FLOAT;
656 kvo.val_f64 = std::atof(sep);
657 } else if (strncmp(sep, "bool:", 5) == 0) {
658 sep += 5;
659 kvo.tag = LLAMA_KV_OVERRIDE_TYPE_BOOL;
660 if (std::strcmp(sep, "true") == 0) {
661 kvo.val_bool = true;
662 } else if (std::strcmp(sep, "false") == 0) {
663 kvo.val_bool = false;
664 } else {
665 LOG_ERR("%s: invalid boolean value for KV override '%s'\n", __func__, data);
666 return false;
667 }
668 } else if (strncmp(sep, "str:", 4) == 0) {
669 sep += 4;
670 kvo.tag = LLAMA_KV_OVERRIDE_TYPE_STR;
671 if (strlen(sep) > 127) {
672 LOG_ERR("%s: malformed KV override '%s', value cannot exceed 127 chars\n", __func__, data);
673 return false;
674 }
675 strncpy(kvo.val_str, sep, 127);
676 kvo.val_str[127] = '\0';
677 } else {
678 LOG_ERR("%s: invalid type for KV override '%s'\n", __func__, data);
679 return false;
680 }
681 overrides.emplace_back(std::move(kvo));
682 return true;
683}
684
685//
686// Filesystem utils

Callers 2

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected