Skip to content

Commit bcf4775

Browse files
fix: pass prompt via temp file to avoid jq argument limit
The previous fix moved the issue from curl to jq - the large PROMPT variable still exceeded the argument size limit when passed via --arg. Now writing PROMPT to a temp file and using --rawfile to read it, completely avoiding command-line argument size limits.
1 parent d03e896 commit bcf4775

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

ai-reviewer.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,13 @@ rm -f "$DIFF_FILE"
259259
REFERER_URL="https://github.com/${REPO_FULL_NAME:-unknown/repo}"
260260

261261
# Build JSON payload and pipe to curl to avoid "Argument list too long" error
262+
# Write prompt to temp file to avoid passing large content as command-line argument
263+
PROMPT_FILE=$(mktemp)
264+
echo "$PROMPT" > "$PROMPT_FILE"
265+
262266
JSON_PAYLOAD=$(jq -n \
263267
--arg model "$AI_MODEL" \
264-
--arg content "$PROMPT" \
268+
--rawfile content "$PROMPT_FILE" \
265269
--argjson temperature "$AI_TEMPERATURE" \
266270
--argjson max_tokens "$AI_MAX_TOKENS" \
267271
'{
@@ -276,6 +280,9 @@ JSON_PAYLOAD=$(jq -n \
276280
"max_tokens": $max_tokens
277281
}')
278282

283+
# Clean up prompt file
284+
rm -f "$PROMPT_FILE"
285+
279286
RESPONSE=$(echo "$JSON_PAYLOAD" | curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
280287
-H "Content-Type: application/json" \
281288
-H "Authorization: Bearer $API_KEY" \

0 commit comments

Comments
 (0)