diff --git a/please.sh b/please.sh index 0fa091e..7fa297c 100755 --- a/please.sh +++ b/please.sh @@ -187,6 +187,11 @@ get_key_from_keychain() { PLEASE_OPENAI_API_KEY="${key}" } +strip_reasoning() { + # Strip think blocks (both inline and multiline) + echo "$1" | sed 's/.*<\/think>//g' | sed '//,/<\/think>/d' +} + get_command() { role="You translate the given input into a Linux command. You may not use natural language, but only a Linux shell command as an answer. Do not use markdown. Do not quote the whole output. If you do not know the answer, answer with \\\"${fail_msg}\\\"." @@ -199,6 +204,7 @@ get_command() { debug "Sending request to OpenAI API: ${payload}" perform_openai_request + message=$(strip_reasoning "$message") command="${message}" } diff --git a/test/strip_reasoning.bats b/test/strip_reasoning.bats new file mode 100644 index 0000000..4218b85 --- /dev/null +++ b/test/strip_reasoning.bats @@ -0,0 +1,19 @@ +#!/usr/bin/env bats + +load $BATS_TEST_DIRNAME/../please.sh + +@test "strip inline reasoning block" { + input="thinking hereecho 'hello world'" + result=$(strip_reasoning "$input") + [ "$result" == "echo 'hello world'" ] +} + +@test "strip multiline reasoning block" { + input=" +thinking here +more thinking + +ls -la" + result=$(strip_reasoning "$input") + [ "$result" == "ls -la" ] +} \ No newline at end of file