typo fix
This commit is contained in:
24
finish.sh
24
finish.sh
@@ -10,7 +10,7 @@ error_exit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo_error() {
|
echo_error() {
|
||||||
echo -e "\e[finish.sh - $1\e[0m" >&2
|
echo -e "\e[31mfinish.sh - $1\e[0m" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
echo_green() {
|
echo_green() {
|
||||||
@@ -250,10 +250,13 @@ log_request() {
|
|||||||
|
|
||||||
openai_completion() {
|
openai_completion() {
|
||||||
local content status_code response_body default_user_input user_input api_key payload endpoint timeout attempt max_attempts
|
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"}
|
endpoint=${ACSH_ENDPOINT:-"http://plato.lan:1234/v1/chat/completions"}
|
||||||
timeout=${ACSH_TIMEOUT:-30}
|
timeout=${ACSH_TIMEOUT:-30}
|
||||||
default_user_input="Write two to six most likely commands given the provided information"
|
default_user_input="Write two to six most likely commands given the provided information"
|
||||||
user_input=${*:-$default_user_input}
|
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
|
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=<your-api-key>"
|
echo_error "ACSH_ACTIVE_API_KEY not set. Please set it with: export ${ACSH_PROVIDER^^}_API_KEY=<your-api-key>"
|
||||||
@@ -262,6 +265,15 @@ openai_completion() {
|
|||||||
api_key="${ACSH_ACTIVE_API_KEY}"
|
api_key="${ACSH_ACTIVE_API_KEY}"
|
||||||
payload=$(_build_payload "$user_input")
|
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
|
max_attempts=2
|
||||||
attempt=1
|
attempt=1
|
||||||
while [ $attempt -le $max_attempts ]; do
|
while [ $attempt -le $max_attempts ]; do
|
||||||
@@ -274,10 +286,18 @@ openai_completion() {
|
|||||||
fi
|
fi
|
||||||
status_code=$(echo "$response" | tail -n1)
|
status_code=$(echo "$response" | tail -n1)
|
||||||
response_body=$(echo "$response" | sed '$d')
|
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
|
if [[ $status_code -eq 200 ]]; then
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo_error "API call failed with status $status_code. Retrying... (Attempt $attempt of $max_attempts)"
|
echo_error "API call failed with status $status_code. Retrying... (Attempt $attempt of $max_attempts)"
|
||||||
|
echo "Error response: $response_body" >> "$debug_log"
|
||||||
sleep 1
|
sleep 1
|
||||||
attempt=$((attempt+1))
|
attempt=$((attempt+1))
|
||||||
fi
|
fi
|
||||||
@@ -285,7 +305,7 @@ openai_completion() {
|
|||||||
|
|
||||||
if [[ $status_code -ne 200 ]]; then
|
if [[ $status_code -ne 200 ]]; then
|
||||||
case $status_code in
|
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." ;;
|
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." ;;
|
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." ;;
|
500) echo_error "Internal Server Error: An unexpected error occurred on the API server." ;;
|
||||||
|
|||||||
Reference in New Issue
Block a user