#!/usr/bin/php no extra flags exit(0); } $json = json_decode(file_get_contents($argv[1]), true); if (!is_array($json)) { fwrite(STDERR, $argv[1]." is not valid JSON\n"); exit(0); } // Map high-level keys to llama.cpp flags. // Add more as needed. $map = [ 'temperature' => '--temp', 'temp' => '--temp', 'max_output_tokens' => '-n', 'n_predict' => '-n', 'top_p' => '--top-p', 'top_k' => '--top-k', 'repeat_penalty' => '--repeat-penalty', 'presence_penalty' => '--presence-penalty', 'frequency_penalty' => '--frequency-penalty', 'seed' => '--seed', 'ctx' => '-c', 'context_size' => '-c', 'mirostat' => '--mirostat', 'mirostat_tau' => '--mirostat-tau', 'mirostat_eta' => '--mirostat-eta', ]; $out = []; // Structured flags foreach ($json as $key => $val) { $k = $key; if (!isset($map[$k])) { // Unknown key: ignore silently (or push to raw if you prefer) continue; } $flag = $map[$k]; // Boolean flags: include only when true if (is_bool($val)) { if ($val) $out[] = $flag; continue; } // Everything else: flag + value // Use escapeshellarg for safety $out[] = $flag . ' ' . escapeshellarg((string)$val); } // Print as a single line for easy inclusion in Makefile pipeline echo implode(' ', $out);