mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-12-15 22:58:49 +00:00
refactor: simplify JSON payload construction in update_changelog.sh
- Improved the construction of the JSON request body for the OpenRouter API by using a here-document for better readability and maintainability. - Ensured proper escaping of the prompt content to prevent issues with special characters in the API request.
This commit is contained in:
parent
6abe43ddc6
commit
4ec47fa7ef
@ -132,22 +132,27 @@ Rules:
|
|||||||
# Call OpenRouter API
|
# Call OpenRouter API
|
||||||
log "Calling OpenRouter API to generate changelog..."
|
log "Calling OpenRouter API to generate changelog..."
|
||||||
|
|
||||||
set +e # Temporarily disable exit on error to check curl response
|
# Prepare the JSON payload properly
|
||||||
RESPONSE=$(curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
|
PROMPT_ESCAPED=$(echo "$PROMPT" | jq -Rs .)
|
||||||
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
|
REQUEST_BODY=$(cat <<EOF
|
||||||
-H "Content-Type: application/json" \
|
{
|
||||||
-H "HTTP-Referer: https://github.com/DeBrosOfficial/network" \
|
"model": "google/gemini-2.5-flash-preview-09-2025",
|
||||||
-H "X-Title: DeBros Network Changelog Generator" \
|
"messages": [
|
||||||
-d "{
|
|
||||||
\"model\": \"google/gemini-2.5-flash-preview-09-2025\",
|
|
||||||
\"messages\": [
|
|
||||||
{
|
{
|
||||||
\"role\": \"user\",
|
"role": "user",
|
||||||
\"content\": $(echo "$PROMPT" | jq -Rs .)
|
"content": $PROMPT_ESCAPED
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
\"temperature\": 0.3
|
"temperature": 0.3
|
||||||
}")
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
set +e # Temporarily disable exit on error to check curl response
|
||||||
|
RESPONSE=$(curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
|
||||||
|
-d "$REQUEST_BODY")
|
||||||
CURL_EXIT_CODE=$?
|
CURL_EXIT_CODE=$?
|
||||||
set -e # Re-enable exit on error
|
set -e # Re-enable exit on error
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user