Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions please.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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>.*<\/think>//g' | sed '/<think>/,/<\/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}\\\"."
Expand All @@ -199,6 +204,7 @@ get_command() {
debug "Sending request to OpenAI API: ${payload}"

perform_openai_request
message=$(strip_reasoning "$message")
command="${message}"
}

Expand Down
19 changes: 19 additions & 0 deletions test/strip_reasoning.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bats

load $BATS_TEST_DIRNAME/../please.sh

@test "strip inline reasoning block" {
input="<think>thinking here</think>echo 'hello world'"
result=$(strip_reasoning "$input")
[ "$result" == "echo 'hello world'" ]
}

@test "strip multiline reasoning block" {
input="<think>
thinking here
more thinking
</think>
ls -la"
result=$(strip_reasoning "$input")
[ "$result" == "ls -la" ]
}