diff --git a/.config/hypr/hyprland/scripts/ai/primary-buffer-query.sh b/.config/hypr/hyprland/scripts/ai/primary-buffer-query.sh index 794414554..eac998afa 100755 --- a/.config/hypr/hyprland/scripts/ai/primary-buffer-query.sh +++ b/.config/hypr/hyprland/scripts/ai/primary-buffer-query.sh @@ -23,13 +23,15 @@ while [[ "$#" -gt 0 ]]; do done # Combine the system prompt with the clipboard content -content=$(wl-paste -p | tr '\n' ' ') -prompt="$SYSTEM_PROMPT $content" +content=$(wl-paste -p | tr '\n' ' ' | head -c 2000) # 2000 char limit to prevent overflow + +# Properly escape content for JSON using jq +prompt_json=$(jq -n --arg system_prompt "$SYSTEM_PROMPT" --arg content "$content" '$system_prompt + " " + $content') # Make the API call with the specified or default model -response=$(curl http://localhost:11434/api/generate -d \ - "{\"model\": \"$model\",\"prompt\": \"$prompt\",\"stream\": false}" \ - | jq -r '.response') +api_payload=$(jq -n --arg model "$model" --argjson prompt "$prompt_json" --argjson stream false \ + '{model: $model, prompt: $prompt, stream: $stream}') +response=$(curl -s http://localhost:11434/api/generate -d "$api_payload" | jq -r '.response' 2>/dev/null) # Check if content is a single line and no longer than 30 characters if [[ ${#content} -le 30 && "$content" != *$'\n'* ]]; then