typo fix
This commit is contained in:
35
finish.sh
35
finish.sh
@@ -85,7 +85,13 @@ _get_system_message_prompt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_get_output_instructions() {
|
_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() {
|
_get_command_history() {
|
||||||
@@ -315,14 +321,35 @@ openai_completion() {
|
|||||||
|
|
||||||
if [[ "${ACSH_PROVIDER^^}" == "OLLAMA" ]]; then
|
if [[ "${ACSH_PROVIDER^^}" == "OLLAMA" ]]; then
|
||||||
content=$(echo "$response_body" | jq -r '.message.content')
|
content=$(echo "$response_body" | jq -r '.message.content')
|
||||||
content=$(echo "$content" | jq -r '.completions')
|
|
||||||
else
|
else
|
||||||
content=$(echo "$response_body" | jq -r '.choices[0].message.content')
|
content=$(echo "$response_body" | jq -r '.choices[0].message.content')
|
||||||
content=$(echo "$content" | jq -r '.completions')
|
|
||||||
fi
|
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
|
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"
|
echo -n "$completions"
|
||||||
log_request "$user_input" "$response_body"
|
log_request "$user_input" "$response_body"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user