mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-13 11:40:53 +08:00
Bot: quote the response_format JSON for --argjson
--argjson requires strict JSON; the unquoted-key object made jq fail, sent an empty request body, and the triage died with 'model returned nothing'. Also log the raw API response when choices is missing so the next failure shows its cause immediately.
This commit is contained in:
+10
-4
@@ -25,17 +25,23 @@ repo="$GITHUB_REPOSITORY"
|
||||
|
||||
ask_model() { # $1 = system prompt, $2 = user payload, $3 = "json" for JSON mode; prints the answer
|
||||
local body="${2:0:$MAX_CHARS}" extra
|
||||
local req
|
||||
local req resp
|
||||
extra='{}'
|
||||
[ "${3:-}" = "json" ] && extra='{response_format: {type: "json_object"}}'
|
||||
[ "${3:-}" = "json" ] && extra='{ "response_format": { "type": "json_object" } }'
|
||||
req=$(jq -n --arg sys "$1" --arg body "$body" --argjson extra "$extra" \
|
||||
'{model: "deepseek-flash",
|
||||
messages: [{role: "system", content: $sys}, {role: "user", content: $body}],
|
||||
max_tokens: 900, temperature: 0} * $extra')
|
||||
curl -sS --max-time 120 https://api.deepseek.com/chat/completions \
|
||||
resp=$(curl -sS --max-time 120 https://api.deepseek.com/chat/completions \
|
||||
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "$req" | jq -r '.choices[0].message.content // empty'
|
||||
-d "$req")
|
||||
if ! jq -e '.choices[0].message.content' <<<"$resp" >/dev/null 2>&1; then
|
||||
log "api call failed, raw response: ${resp:0:300}"
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
jq -r '.choices[0].message.content' <<<"$resp"
|
||||
}
|
||||
|
||||
repo_context() { git ls-files | head -120; }
|
||||
|
||||
Reference in New Issue
Block a user