typo fix
Some checks failed
Docker Build and Push / build-and-push (push) Failing after 1m59s
Tests / test (bash) (push) Failing after 16s
Tests / test (zsh) (push) Failing after 16s
Tests / lint (push) Successful in 9s
Tests / docker (push) Successful in 24s

This commit is contained in:
2025-12-02 11:02:52 +01:00
parent 3ae5f5ac45
commit 7100c0fb2a

View File

@@ -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"
}