diff --git a/Makefile b/Makefile index 7b74864..9cda1a3 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ LLM_FLAGS=--no-display-prompt -no-cnv --simple-io SHELL=/bin/bash -x -agent_message.txt: llm_chat.php consolidated_system_message.txt user_message.txt - php $^ | $(LLM_BIN) -m $(LLM_MODEL) -f /dev/stdin $(LLM_FLAGS) 2> /dev/null | sed -e 's/\[end of text\]//' | tee $@ +agent_message.txt: llm_chat.php consolidated_system_message.txt user_message.txt settings.json settings_to_flags.php + php $^ | $(LLM_BIN) -m $(LLM_MODEL) -f /dev/stdin $(LLM_FLAGS) `php settings_to_flags.php` 2> /dev/null | sed -e 's/\[end of text\]//' | tee $@ consolidated_system_message.txt: $(wildcard *.sys) cat $^ > $@ diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/settings.json @@ -0,0 +1 @@ +{} diff --git a/settings_to_flags.php b/settings_to_flags.php new file mode 100755 index 0000000..d42f4b4 --- /dev/null +++ b/settings_to_flags.php @@ -0,0 +1,90 @@ +#!/usr/bin/php + no extra flags + exit(0); +} + +$json = json_decode(file_get_contents($path), true); +if (!is_array($json)) { + fwrite(STDERR, "settings.json is not valid JSON\n"); + exit(0); +} + +$flags = isset($json['flags']) && is_array($json['flags']) ? $json['flags'] : []; +$raw = isset($json['raw']) && is_array($json['raw']) ? $json['raw'] : []; + +// Normalize keys: strip leading dashes, kebab→snake, lowercase +$norm = function(string $k): string { + $k = ltrim($k, '-'); + $k = strtolower(str_replace('-', '_', $k)); + return $k; +}; + +// 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 ($flags as $key => $val) { + $k = $norm($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); +} + +// Raw passthrough flags (assumed already valid for llama.cpp) +foreach ($raw as $r) { + if (is_string($r) && strlen(trim($r)) > 0) { + $out[] = $r; + } +} + +// Print as a single line for easy inclusion in Makefile pipeline +echo implode(' ', $out);