This commit is contained in:
Frederico @ VilaRosa02 2025-08-26 10:14:35 +00:00
parent 119ad98cdf
commit 5a24d4946d
2 changed files with 7 additions and 24 deletions

View File

@ -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 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 $@
agent_message.txt: llm_chat.php consolidated_system_message.txt user_message.txt
php $^ | $(LLM_BIN) -m $(LLM_MODEL) -f /dev/stdin $(LLM_FLAGS) $(shell php settings_to_flags.php settings.json) 2> /dev/null | sed -e 's/\[end of text\]//' | tee $@
consolidated_system_message.txt: $(wildcard *.sys)
cat $^ > $@

View File

@ -15,27 +15,17 @@
// "raw": ["--no-penalize-nl"]
// }
$path = __DIR__ . '/settings.json';
if (!file_exists($path)) {
if (!file_exists($argv[1])) {
// No settings file -> no extra flags
exit(0);
}
$json = json_decode(file_get_contents($path), true);
$json = json_decode(file_get_contents($argv[1]), true);
if (!is_array($json)) {
fwrite(STDERR, "settings.json is not valid JSON\n");
fwrite(STDERR, $argv[1]." 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.
@ -58,10 +48,9 @@ $map = [
];
$out = [];
// Structured flags
foreach ($flags as $key => $val) {
$k = $norm($key);
foreach ($json as $key => $val) {
$k = $key;
if (!isset($map[$k])) {
// Unknown key: ignore silently (or push to raw if you prefer)
continue;
@ -79,12 +68,6 @@ foreach ($flags as $key => $val) {
$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);