MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / gguf_kv_to_str

Function gguf_kv_to_str

subprojects/llama.cpp/src/llama-impl.cpp:136–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136std::string gguf_kv_to_str(const struct gguf_context * ctx_gguf, int i) {
137 const enum gguf_type type = gguf_get_kv_type(ctx_gguf, i);
138
139 switch (type) {
140 case GGUF_TYPE_STRING:
141 return gguf_get_val_str(ctx_gguf, i);
142 case GGUF_TYPE_ARRAY:
143 {
144 const enum gguf_type arr_type = gguf_get_arr_type(ctx_gguf, i);
145 int arr_n = gguf_get_arr_n(ctx_gguf, i);
146 const void * data = arr_type == GGUF_TYPE_STRING ? nullptr : gguf_get_arr_data(ctx_gguf, i);
147 std::stringstream ss;
148 ss << "[";
149 for (int j = 0; j < arr_n; j++) {
150 if (arr_type == GGUF_TYPE_STRING) {
151 std::string val = gguf_get_arr_str(ctx_gguf, i, j);
152 // escape quotes
153 replace_all(val, "\\", "\\\\");
154 replace_all(val, "\"", "\\\"");
155 ss << '"' << val << '"';
156 } else if (arr_type == GGUF_TYPE_ARRAY) {
157 ss << "???";
158 } else {
159 ss << gguf_data_to_str(arr_type, data, j);
160 }
161 if (j < arr_n - 1) {
162 ss << ", ";
163 }
164 }
165 ss << "]";
166 return ss.str();
167 }
168 default:
169 return gguf_data_to_str(type, gguf_get_val_data(ctx_gguf, i), 0);
170 }
171}

Callers 3

load_hparamsMethod · 0.70
llama_model_loaderMethod · 0.70

Calls 10

gguf_get_kv_typeFunction · 0.85
gguf_get_val_strFunction · 0.85
gguf_get_arr_typeFunction · 0.85
gguf_get_arr_nFunction · 0.85
gguf_get_arr_dataFunction · 0.85
gguf_get_arr_strFunction · 0.85
replace_allFunction · 0.85
gguf_get_val_dataFunction · 0.85
gguf_data_to_strFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected