Prompt update
This commit is contained in:
parent
7a17716711
commit
1a6ed5be36
1 changed files with 59 additions and 65 deletions
|
|
@ -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,76 +324,61 @@ 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
|
||||||
|
echo "DEBUG_MAX_TOKENS=$OPENROUTER_MAX_TOKENS" >&2
|
||||||
|
echo "DEBUG_PERSONALITY_INDEX=$idx" >&2
|
||||||
|
|
||||||
|
if ! curl -sS \
|
||||||
|
"https://openrouter.ai/api/v1/chat/completions" \
|
||||||
|
-H "Authorization: Bearer ${OPENROUTER_API_KEY}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "HTTP-Referer: ${OPENROUTER_SITE_URL}" \
|
||||||
|
-H "X-Title: ${OPENROUTER_SITE_NAME}" \
|
||||||
|
-X POST \
|
||||||
|
-d @"$REQUEST_FILE" \
|
||||||
|
> "$RESPONSE_FILE"; then
|
||||||
|
echo "OpenRouter curl request failed" >&2
|
||||||
|
cp "$RESPONSE_FILE" "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
attempt=1
|
cp "$RESPONSE_FILE" "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
|
||||||
while [ "$attempt" -le "$OPENROUTER_MAX_RETRIES" ]; do
|
chown www-data:www-data "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
|
||||||
echo "Calling OpenRouter API (attempt $attempt/$OPENROUTER_MAX_RETRIES)..." >&2
|
chmod 664 "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
|
||||||
echo "DEBUG_MODEL=$MODEL" >&2
|
|
||||||
echo "DEBUG_PERSONALITY_INDEX=$idx" >&2
|
|
||||||
|
|
||||||
if ! curl -sS \
|
TEXT=$(jq -r '.choices[0].message.content // empty' "$RESPONSE_FILE" 2>/dev/null || true)
|
||||||
"https://openrouter.ai/api/v1/chat/completions" \
|
|
||||||
-H "Authorization: Bearer ${OPENROUTER_API_KEY}" \
|
if [ -z "$TEXT" ]; then
|
||||||
-H "Content-Type: application/json" \
|
api_error=$(jq -r '.error.message // empty' "$RESPONSE_FILE" 2>/dev/null || true)
|
||||||
-H "HTTP-Referer: ${OPENROUTER_SITE_URL}" \
|
if [ -n "$api_error" ]; then
|
||||||
-H "X-Title: ${OPENROUTER_SITE_NAME}" \
|
echo "OpenRouter returned no text: $api_error" >&2
|
||||||
-X POST \
|
else
|
||||||
-d @"$REQUEST_FILE" \
|
echo "OpenRouter returned no text. Full response:" >&2
|
||||||
> "$RESPONSE_FILE"; then
|
cat "$RESPONSE_FILE" >&2
|
||||||
echo "OpenRouter curl request failed on attempt $attempt" >&2
|
|
||||||
cp "$RESPONSE_FILE" "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
|
|
||||||
attempt=$((attempt + 1))
|
|
||||||
sleep 2
|
|
||||||
continue
|
|
||||||
fi
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
cp "$RESPONSE_FILE" "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
|
printf '%s\n' "$TEXT" > "$DEBUG_TEXT_FILE" 2>/dev/null || true
|
||||||
chown www-data:www-data "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
|
chown www-data:www-data "$DEBUG_TEXT_FILE" 2>/dev/null || true
|
||||||
chmod 664 "$DEBUG_RESPONSE_FILE" 2>/dev/null || true
|
chmod 664 "$DEBUG_TEXT_FILE" 2>/dev/null || true
|
||||||
|
|
||||||
TEXT=$(jq -r '.choices[0].message.content // empty' "$RESPONSE_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 \
|
||||||
|
&& printf '%s' "$TEXT" | jq . > "$OUT_TMP"; then
|
||||||
if [ -z "$TEXT" ]; then
|
mv "$OUT_TMP" "$OUT_JSON"
|
||||||
api_error=$(jq -r '.error.message // empty' "$RESPONSE_FILE" 2>/dev/null || true)
|
chown www-data:www-data "$OUT_JSON" 2>/dev/null || true
|
||||||
if [ -n "$api_error" ]; then
|
chmod 664 "$OUT_JSON" 2>/dev/null || true
|
||||||
echo "OpenRouter returned no text on attempt $attempt: $api_error" >&2
|
if [ "$FORCED_PERSONALITY" != "1" ]; then
|
||||||
else
|
printf '%s\n' "$idx" > "$STATE_FILE"
|
||||||
echo "OpenRouter returned no text on attempt $attempt. Full response:" >&2
|
chown www-data:www-data "$STATE_FILE" 2>/dev/null || true
|
||||||
cat "$RESPONSE_FILE" >&2
|
chmod 664 "$STATE_FILE" 2>/dev/null || true
|
||||||
fi
|
|
||||||
attempt=$((attempt + 1))
|
|
||||||
sleep 2
|
|
||||||
continue
|
|
||||||
fi
|
fi
|
||||||
|
echo "OpenRouter JSON saved: $OUT_JSON" >&2
|
||||||
printf '%s\n' "$TEXT" > "$DEBUG_TEXT_FILE" 2>/dev/null || true
|
exit 0
|
||||||
chown www-data:www-data "$DEBUG_TEXT_FILE" 2>/dev/null || true
|
fi
|
||||||
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 \
|
|
||||||
&& printf '%s' "$TEXT" | jq . > "$OUT_TMP"; then
|
|
||||||
mv "$OUT_TMP" "$OUT_JSON"
|
|
||||||
chown www-data:www-data "$OUT_JSON" 2>/dev/null || true
|
|
||||||
chmod 664 "$OUT_JSON" 2>/dev/null || true
|
|
||||||
if [ "$FORCED_PERSONALITY" != "1" ]; then
|
|
||||||
printf '%s\n' "$idx" > "$STATE_FILE"
|
|
||||||
chown www-data:www-data "$STATE_FILE" 2>/dev/null || true
|
|
||||||
chmod 664 "$STATE_FILE" 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
echo "OpenRouter JSON saved: $OUT_JSON" >&2
|
|
||||||
exit 0
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue