Simplifying ending a chat from the LLM side in the tests

This commit is contained in:
2026-05-09 09:53:59 -05:00
parent 059fe11bf1
commit 048752c5a4
2 changed files with 12 additions and 2 deletions
+11 -1
View File
@@ -20,15 +20,25 @@ function check_tool_call() {
diff -u $expected_out tool_result --color=always
}
function sanitize_json() {
echo "$1" | jq -R | sed -r 's/^.//g' | sed -r 's/.$//g'
}
function tool_call() {
name="$1"
args="$2"
args_string="$(echo ""$args"" | jq -R | sed -r 's/^.//g' | sed -r 's/.$//g')"
args_string=`sanitize_json "$2"`
echo '{"choices":[{"message":{"role":"assistant","tool_calls":[{"id":"call_1","type":"function","function":{"name":"'$name'","arguments":"'"$args_string"'"}}],"content":null},"finish_reason":"tool_calls"}]}'
}
function be_done() {
content=`sanitize_json "$1"`
echo '{"choices":[{"message":{"role":"assistant","content":"'"$content"'"},"finish_reason":"stop"}]}'
}
export -f check_tool_call
export -f tool_call
export -f sanitize_json
export -f be_done
# Resolve paths relative to this script
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
+1 -1
View File
@@ -8,7 +8,7 @@ This is only a test
EOF
tool_call read_file '{"path":"test_file.txt"}' >> mock_responses.txt
echo '{"choices":[{"message":{"role":"assistant","content":"Done reading"},"finish_reason":"stop"}]}' >> mock_responses.txt
be_done 'Done reading' >> mock_responses.txt
OUTPUT=$("${DRHARNESS}" -F chat.json -n -m "Read the file" -t read_file -d < "mock_responses.txt")