MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / task_result_json

Function task_result_json

app/server/runtime.cpp:229–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227 return wav;
228}
229
230std::unordered_map<std::string, std::string> options_from_object(const Value * value);
231
232std::string safe_upload_name(std::string value) {
233 value = std::filesystem::path(value).filename().string();
234 for (char & ch : value) {
235 const auto uch = static_cast<unsigned char>(ch);
236 if (!(std::isalnum(uch) || ch == '.' || ch == '-' || ch == '_')) {
237 ch = '_';
238 }
239 }
240 if (value.empty() || value == "." || value == "..") {
241 value = "audio.wav";
242 }
243 return value;
244}
245
246ServerModelConfig model_config_from_json(
247 const Value & body,
248 const std::filesystem::path & request_base,
249 bool lazy) {
250 ServerModelConfig model;
251 model.id = engine::io::json::require_string(body, "id");
252 model.path = resolve_path(request_base, engine::io::json::require_string(body, "path"));
253 model.family = engine::io::json::require_string(body, "family");
254 model.task = engine::io::json::optional_string(body, "task", model.task);
255 model.mode = engine::io::json::optional_string(body, "mode", model.mode);
256 model.lazy = lazy;
257 if (const auto * value = body.find("model_spec_override")) {
258 model.model_spec_override = resolve_path(request_base, value->as_string());
259 }
260 if (const auto * value = body.find("config")) {
261 model.config_id = value->as_string();
262 }
263 if (const auto * value = body.find("weight")) {
264 model.weight_id = value->as_string();
265 }
266 model.load_options = options_from_object(body.find("load_options"));
267 model.session_options = options_from_object(body.find("session_options"));
268 return model;
269}
270
271// Minimal application/x-www-form-urlencoded query string lookup, e.g.
272// query_param("model=pocket-tts&foo=bar", "model") -> "pocket-tts".
273std::string query_param(const std::string & query, const std::string & key) {
274 size_t pos = 0;
275 while (pos < query.size()) {
276 const size_t amp = query.find('&', pos);
277 const std::string pair = query.substr(pos, amp == std::string::npos ? std::string::npos : amp - pos);
278 const auto eq = pair.find('=');
279 const std::string name = pair.substr(0, eq);
280 if (name == key) {
281 return eq == std::string::npos ? "" : pair.substr(eq + 1);
282 }
283 if (amp == std::string::npos) {
284 break;
285 }
286 pos = amp + 1;

Callers 1

handle_generic_runMethod · 0.85

Calls 7

encode_pcm16_wavFunction · 0.85
base64_encodeFunction · 0.85
timing_jsonFunction · 0.85
strMethod · 0.80
json_quoteFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected