Prompt update

This commit is contained in:
hbrain 2026-07-01 05:02:45 +02:00
parent 7a17716711
commit 1a6ed5be36

View file

@ -26,7 +26,7 @@ if [ "$MODEL" = "openrouter/auto" ] && [ "${OPENROUTER_ALLOW_AUTO:-}" != "1" ];
echo "WARN: openrouter/auto is unreliable for strict JSON; using openai/gpt-4o-mini. Set OPENROUTER_MODEL to a specific vision model, or OPENROUTER_ALLOW_AUTO=1 to force auto." >&2 echo "WARN: openrouter/auto is unreliable for strict JSON; using openai/gpt-4o-mini. Set OPENROUTER_MODEL to a specific vision model, or OPENROUTER_ALLOW_AUTO=1 to force auto." >&2
MODEL="openai/gpt-4o-mini" MODEL="openai/gpt-4o-mini"
fi fi
OPENROUTER_MAX_RETRIES="${OPENROUTER_MAX_RETRIES:-3}" OPENROUTER_MAX_TOKENS="${OPENROUTER_MAX_TOKENS:-1024}"
OPENROUTER_SITE_URL="${OPENROUTER_SITE_URL:-https://bubulescu.org}" OPENROUTER_SITE_URL="${OPENROUTER_SITE_URL:-https://bubulescu.org}"
OPENROUTER_SITE_NAME="${OPENROUTER_SITE_NAME:-MVLog}" OPENROUTER_SITE_NAME="${OPENROUTER_SITE_NAME:-MVLog}"
@ -218,11 +218,13 @@ Content rules:
- Do not be subtle. - Do not be subtle.
- The voice MUST BE provocative, opinionated, funny, and slightly over the top. - The voice MUST BE provocative, opinionated, funny, and slightly over the top.
- Highlight the funniest, strangest, most beautiful, or most ridiculous visible aspect you see on the captured frames. - Highlight the funniest, strangest, most beautiful, or most ridiculous visible aspect you see on the captured frames.
- The story may be strange, surreal, ridiculous, darkly funny, or chaotic, but avoid using the words "absurd", "absurdity", or "absurdities" in the teaser or description. Show it through concrete details instead of naming it.
- Be challenging, provocative, witty, and playful. - Be challenging, provocative, witty, and playful.
- Roasting is allowed. - Roasting is allowed.
- Profanity is allowed only if it fits the selected personality. - Profanity is allowed only if it fits the selected personality.
- Do not invent specific facts that are not visible or provided. - Do not invent specific facts that are not visible or provided.
- Description MUST contain at least one of the following words: subscribe, contact. - Description MUST contain at least one of the following words: subscribe, contact.
- Funny references to ice hockey and pizza napoletana are allways welcome
JSON rules: JSON rules:
- Output JSON only. - Output JSON only.
@ -260,7 +262,7 @@ RESPONSE_FILE="$WORKDIR/response.json"
printf '%s' "$PROMPT" > "$PROMPT_FILE" printf '%s' "$PROMPT" > "$PROMPT_FILE"
printf '%s\n' "${FRAMES[@]}" > "$FRAMES_LIST" printf '%s\n' "${FRAMES[@]}" > "$FRAMES_LIST"
python3 - "$PROMPT_FILE" "$REQUEST_FILE" "$FRAMES_LIST" "$MODEL" <<'PY' python3 - "$PROMPT_FILE" "$REQUEST_FILE" "$FRAMES_LIST" "$MODEL" "$OPENROUTER_MAX_TOKENS" <<'PY'
import sys import sys
import json import json
import base64 import base64
@ -269,6 +271,12 @@ prompt_file = sys.argv[1]
request_file = sys.argv[2] request_file = sys.argv[2]
frames_list = sys.argv[3] frames_list = sys.argv[3]
model = sys.argv[4] model = sys.argv[4]
try:
max_tokens = int(sys.argv[5])
except Exception:
max_tokens = 1024
if max_tokens < 1:
max_tokens = 1024
with open(prompt_file, "r", encoding="utf-8") as f: with open(prompt_file, "r", encoding="utf-8") as f:
prompt = f.read() prompt = f.read()
@ -300,6 +308,7 @@ req = {
} }
], ],
"temperature": 0.7, "temperature": 0.7,
"max_tokens": max_tokens,
"response_format": { "response_format": {
"type": "json_object" "type": "json_object"
} }
@ -315,17 +324,12 @@ OUT_TMP="$OUT_JSON.tmp.$$"
DEBUG_RESPONSE_FILE="$IN_DIR/.mvlog-last-openrouter-response.json" DEBUG_RESPONSE_FILE="$IN_DIR/.mvlog-last-openrouter-response.json"
DEBUG_TEXT_FILE="$IN_DIR/.mvlog-last-openrouter-text.txt" DEBUG_TEXT_FILE="$IN_DIR/.mvlog-last-openrouter-text.txt"
if [[ ! "$OPENROUTER_MAX_RETRIES" =~ ^[0-9]+$ ]] || [ "$OPENROUTER_MAX_RETRIES" -lt 1 ]; then echo "Calling OpenRouter API..." >&2
OPENROUTER_MAX_RETRIES=3 echo "DEBUG_MODEL=$MODEL" >&2
fi echo "DEBUG_MAX_TOKENS=$OPENROUTER_MAX_TOKENS" >&2
echo "DEBUG_PERSONALITY_INDEX=$idx" >&2
attempt=1 if ! curl -sS \
while [ "$attempt" -le "$OPENROUTER_MAX_RETRIES" ]; do
echo "Calling OpenRouter API (attempt $attempt/$OPENROUTER_MAX_RETRIES)..." >&2
echo "DEBUG_MODEL=$MODEL" >&2
echo "DEBUG_PERSONALITY_INDEX=$idx" >&2
if ! curl -sS \
"https://openrouter.ai/api/v1/chat/completions" \ "https://openrouter.ai/api/v1/chat/completions" \
-H "Authorization: Bearer ${OPENROUTER_API_KEY}" \ -H "Authorization: Bearer ${OPENROUTER_API_KEY}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
@ -334,37 +338,33 @@ while [ "$attempt" -le "$OPENROUTER_MAX_RETRIES" ]; do
-X POST \ -X POST \
-d @"$REQUEST_FILE" \ -d @"$REQUEST_FILE" \
> "$RESPONSE_FILE"; then > "$RESPONSE_FILE"; then
echo "OpenRouter curl request failed on attempt $attempt" >&2 echo "OpenRouter curl request failed" >&2
cp "$RESPONSE_FILE" "$DEBUG_RESPONSE_FILE" 2>/dev/null || true cp "$RESPONSE_FILE" "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
attempt=$((attempt + 1)) exit 1
sleep 2 fi
continue
fi
cp "$RESPONSE_FILE" "$DEBUG_RESPONSE_FILE" 2>/dev/null || true cp "$RESPONSE_FILE" "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
chown www-data:www-data "$DEBUG_RESPONSE_FILE" 2>/dev/null || true chown www-data:www-data "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
chmod 664 "$DEBUG_RESPONSE_FILE" 2>/dev/null || true chmod 664 "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
TEXT=$(jq -r '.choices[0].message.content // empty' "$RESPONSE_FILE" 2>/dev/null || true) TEXT=$(jq -r '.choices[0].message.content // empty' "$RESPONSE_FILE" 2>/dev/null || true)
if [ -z "$TEXT" ]; then if [ -z "$TEXT" ]; then
api_error=$(jq -r '.error.message // empty' "$RESPONSE_FILE" 2>/dev/null || true) api_error=$(jq -r '.error.message // empty' "$RESPONSE_FILE" 2>/dev/null || true)
if [ -n "$api_error" ]; then if [ -n "$api_error" ]; then
echo "OpenRouter returned no text on attempt $attempt: $api_error" >&2 echo "OpenRouter returned no text: $api_error" >&2
else else
echo "OpenRouter returned no text on attempt $attempt. Full response:" >&2 echo "OpenRouter returned no text. Full response:" >&2
cat "$RESPONSE_FILE" >&2 cat "$RESPONSE_FILE" >&2
fi fi
attempt=$((attempt + 1)) exit 1
sleep 2 fi
continue
fi
printf '%s\n' "$TEXT" > "$DEBUG_TEXT_FILE" 2>/dev/null || true printf '%s\n' "$TEXT" > "$DEBUG_TEXT_FILE" 2>/dev/null || true
chown www-data:www-data "$DEBUG_TEXT_FILE" 2>/dev/null || true chown www-data:www-data "$DEBUG_TEXT_FILE" 2>/dev/null || true
chmod 664 "$DEBUG_TEXT_FILE" 2>/dev/null || true chmod 664 "$DEBUG_TEXT_FILE" 2>/dev/null || true
if printf '%s' "$TEXT" | jq -e 'type == "object" and (.personality | type == "string") and (.quote_da | type == "string") and (.teaser | type == "string") and (.description | type == "string") and (.tags | type == "array")' >/dev/null \ if printf '%s' "$TEXT" | jq -e 'type == "object" and (.personality | type == "string") and (.quote_da | type == "string") and (.teaser | type == "string") and (.description | type == "string") and (.tags | type == "array")' >/dev/null \
&& printf '%s' "$TEXT" | jq . > "$OUT_TMP"; then && printf '%s' "$TEXT" | jq . > "$OUT_TMP"; then
mv "$OUT_TMP" "$OUT_JSON" mv "$OUT_TMP" "$OUT_JSON"
chown www-data:www-data "$OUT_JSON" 2>/dev/null || true chown www-data:www-data "$OUT_JSON" 2>/dev/null || true
@ -376,15 +376,9 @@ while [ "$attempt" -le "$OPENROUTER_MAX_RETRIES" ]; do
fi fi
echo "OpenRouter JSON saved: $OUT_JSON" >&2 echo "OpenRouter JSON saved: $OUT_JSON" >&2
exit 0 exit 0
fi fi
rm -f "$OUT_TMP"
echo "OpenRouter returned invalid JSON on attempt $attempt. Raw text saved to $DEBUG_TEXT_FILE" >&2
printf '%s\n' "$TEXT" >&2
attempt=$((attempt + 1))
sleep 2
done
rm -f "$OUT_TMP" rm -f "$OUT_TMP"
echo "OpenRouter did not return valid JSON after $OPENROUTER_MAX_RETRIES attempt(s). Last raw response: $DEBUG_RESPONSE_FILE; last text: $DEBUG_TEXT_FILE" >&2 echo "OpenRouter returned invalid JSON. Raw text saved to $DEBUG_TEXT_FILE" >&2
printf '%s\n' "$TEXT" >&2
exit 1 exit 1