From 5268b292ea5e94a856cbd79134403c6d23c66a89 Mon Sep 17 00:00:00 2001 From: michael1986 Date: Tue, 2 Dec 2025 10:57:38 +0100 Subject: [PATCH] typo fix --- finish.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/finish.sh b/finish.sh index 7647ad7..df13f82 100644 --- a/finish.sh +++ b/finish.sh @@ -10,7 +10,7 @@ error_exit() { } echo_error() { - echo -e "\e[finish.sh - $1\e[0m" >&2 + echo -e "\e[31mfinish.sh - $1\e[0m" >&2 } echo_green() { @@ -250,10 +250,13 @@ log_request() { openai_completion() { local content status_code response_body default_user_input user_input api_key payload endpoint timeout attempt max_attempts + local log_file debug_log endpoint=${ACSH_ENDPOINT:-"http://plato.lan:1234/v1/chat/completions"} timeout=${ACSH_TIMEOUT:-30} default_user_input="Write two to six most likely commands given the provided information" user_input=${*:-$default_user_input} + log_file=${ACSH_LOG_FILE:-"$HOME/.finish/finish.log"} + debug_log="$HOME/.finish/debug.log" if [[ -z "$ACSH_ACTIVE_API_KEY" && ${ACSH_PROVIDER^^} != "OLLAMA" && ${ACSH_PROVIDER^^} != "LMSTUDIO" ]]; then echo_error "ACSH_ACTIVE_API_KEY not set. Please set it with: export ${ACSH_PROVIDER^^}_API_KEY=" @@ -262,6 +265,15 @@ openai_completion() { api_key="${ACSH_ACTIVE_API_KEY}" payload=$(_build_payload "$user_input") + # Debug logging + echo "=== DEBUG LOG $(date) ===" >> "$debug_log" + echo "Provider: ${ACSH_PROVIDER}" >> "$debug_log" + echo "Endpoint: $endpoint" >> "$debug_log" + echo "User input: $user_input" >> "$debug_log" + echo "Payload:" >> "$debug_log" + echo "$payload" >> "$debug_log" + echo "" >> "$debug_log" + max_attempts=2 attempt=1 while [ $attempt -le $max_attempts ]; do @@ -274,10 +286,18 @@ openai_completion() { fi status_code=$(echo "$response" | tail -n1) response_body=$(echo "$response" | sed '$d') + + # Debug logging + echo "Response status: $status_code" >> "$debug_log" + echo "Response body:" >> "$debug_log" + echo "$response_body" >> "$debug_log" + echo "" >> "$debug_log" + if [[ $status_code -eq 200 ]]; then break else echo_error "API call failed with status $status_code. Retrying... (Attempt $attempt of $max_attempts)" + echo "Error response: $response_body" >> "$debug_log" sleep 1 attempt=$((attempt+1)) fi @@ -285,7 +305,7 @@ openai_completion() { if [[ $status_code -ne 200 ]]; then case $status_code in - 400) echo_error "Bad Request: The API request was invalid or malformed." ;; + 400) echo_error "Bad Request: The API request was invalid or malformed. Check $debug_log for details." ;; 401) echo_error "Unauthorized: The provided API key is invalid or missing." ;; 429) echo_error "Too Many Requests: The API rate limit has been exceeded." ;; 500) echo_error "Internal Server Error: An unexpected error occurred on the API server." ;;