From 7100c0fb2a300c997463ad90a7b1b44950327940 Mon Sep 17 00:00:00 2001 From: michael1986 Date: Tue, 2 Dec 2025 11:02:52 +0100 Subject: [PATCH] typo fix --- finish.sh | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/finish.sh b/finish.sh index 2342cf3..df5bcf4 100644 --- a/finish.sh +++ b/finish.sh @@ -85,7 +85,13 @@ _get_system_message_prompt() { } _get_output_instructions() { - echo "Provide a list of suggested completions or commands that could be run in the terminal. YOU MUST provide a list of two to five possible completions or rewritten commands. DO NOT wrap the commands in backticks or quotes. Each must be a valid command or chain of commands. Focus on the user's intent, recent commands, and the current environment. RETURN A JSON OBJECT WITH THE COMPLETIONS." + echo "Provide a list of suggested completions or commands that could be run in the terminal. YOU MUST provide a list of two to five possible completions or rewritten commands. DO NOT wrap the commands in backticks or quotes. Each must be a valid command or chain of commands. Focus on the user's intent, recent commands, and the current environment. + +CRITICAL: You MUST respond with ONLY a valid JSON object in this EXACT format with no additional text before or after: +{\"completions\": [\"command1\", \"command2\", \"command3\"]} + +Example response: +{\"completions\": [\"ls -la\", \"ls -lh\", \"find . -type f\"]}" } _get_command_history() { @@ -315,14 +321,35 @@ openai_completion() { if [[ "${ACSH_PROVIDER^^}" == "OLLAMA" ]]; then content=$(echo "$response_body" | jq -r '.message.content') - content=$(echo "$content" | jq -r '.completions') else content=$(echo "$response_body" | jq -r '.choices[0].message.content') - content=$(echo "$content" | jq -r '.completions') fi + # Log the raw content for debugging + echo "Raw content from API:" >> "$debug_log" + echo "$content" >> "$debug_log" + echo "" >> "$debug_log" + + # Try to parse as JSON first local completions - completions=$(echo "$content" | jq -r '.[]' | grep -v '^$') + if echo "$content" | jq -e '.completions' > /dev/null 2>&1; then + completions=$(echo "$content" | jq -r '.completions[]' | grep -v '^$') + else + # Fallback: try to extract JSON object from text + json_match=$(echo "$content" | grep -oP '\{[^}]*"completions"[^}]*\}' | head -1) + if [[ -n "$json_match" ]]; then + completions=$(echo "$json_match" | jq -r '.completions[]' 2>/dev/null | grep -v '^$') + else + # Last resort: parse line by line (skip explanatory text) + completions=$(echo "$content" | grep -v "^Here\|^These\|^The\|^Based" | grep -E "^(ls|cd|find|cat|grep|echo|mkdir|rm|cp|mv|pwd|chmod|chown)" | head -5) + fi + fi + + if [[ -z "$completions" ]]; then + echo_error "Failed to parse completions from API response. Check $debug_log for details." + return + fi + echo -n "$completions" log_request "$user_input" "$response_body" }