This commit is contained in:
Frederico @ VilaRosa02 2025-08-26 09:43:48 +00:00
commit a8d61e51b2
5 changed files with 73 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
agent_message.txt
consolidated_system_message.txt
*.sys

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
LLM_BIN=~/llama.cpp/build/bin/llama-cli
LLM_MODEL=~/llama.cpp/models/llama-3.1-8b/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf
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 $@
consolidated_system_message.txt: $(wildcard *.sys)
cat $^ > $@
clean:
rm *.sys *.txt || echo "No files to be removed."

33
keybd_loop.sh Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env bash
usage () {
echo "<space> or <enter>: next step; [q] - quit; [b] - make bash_response; [l] - make llm_response"
}
usage
make clean
while true; do
# Read one character silently
read -rsn1 key
case "$key" in
$'') # llm + bash
make llm_response && make bash_response
;;
l) # bash
make llm_response
;;
b) # bash
make bash_response
;;
q) # Quit
echo "Goodbye."
break
;;
*)
# Show the raw character in a visible way
printf "You pressed: %q\n" "$key"
;;
esac
usage
done

9
llama_chat_template.php Normal file
View File

@ -0,0 +1,9 @@
<|start_header_id|>system<|end_header_id|>
<?=$system_root_message?><|eot_id|>
<?php foreach($messages as $i => $message) : ?>
<|start_header_id|><?=($i%2==0?"user":"assistant")?><|end_header_id|>
<?=$message?>
<|eot_id|>
<?php endforeach;?>
<|start_header_id|>assistant<|end_header_id|>

11
llm_chat.php Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/php
<?php
$exec_name = array_shift($argv);
$system_root_message = file_get_contents(array_shift($argv));
foreach($argv as $filename)
$messages[] = file_get_contents($filename);
require __DIR__."/llama_chat_template.php";