Adding ability to pause transcription
This commit is contained in:
@@ -85,6 +85,9 @@ fi
|
||||
# Optional: explicit KB id to use for all KB operations (bypasses name resolution)
|
||||
: "${OPENWEBUI_KB_ID:=}"
|
||||
|
||||
# Max seconds to wait for OWUI to finish extracting file content before attach
|
||||
: "${OPENWEBUI_WAIT_SECS:=180}"
|
||||
|
||||
# Resolve a working OpenWebUI base URL (fallback from host.docker.internal -> localhost)
|
||||
_owui_url() {
|
||||
# If a host-only override is provided, prefer it unconditionally
|
||||
@@ -225,6 +228,21 @@ EOF
|
||||
done
|
||||
}
|
||||
|
||||
# --- Redis helpers (for pause/resume switches) -----------------------------
|
||||
_redis_cli() {
|
||||
# Prefer dockerized redis if available; otherwise fall back to local redis-cli
|
||||
if command -v docker >/dev/null 2>&1 && docker compose ps redis >/dev/null 2>&1; then
|
||||
docker compose exec -T redis redis-cli "$@"
|
||||
elif command -v redis-cli >/dev/null 2>&1; then
|
||||
redis-cli -h "${REDIS_HOST:-127.0.0.1}" -p "${REDIS_PORT:-6379}" "$@"
|
||||
else
|
||||
echo "redis-cli not found and no docker compose redis service available." >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
_transcribe_key="podx:transcribe:paused"
|
||||
|
||||
_help() {
|
||||
cat <<EOF
|
||||
podx-tools — Meili & OpenWebUI helpers
|
||||
@@ -252,6 +270,11 @@ OpenWebUI:
|
||||
owui-kbs-raw # raw JSON from /knowledge/list
|
||||
owui-batch-attach "<KB Name>" <glob> # attach all files matching glob
|
||||
|
||||
Transcription control:
|
||||
transcribe-status # show whether transcription workers are paused
|
||||
transcribe-pause # pause CPU-heavy transcription jobs
|
||||
transcribe-resume # resume transcription jobs
|
||||
|
||||
Examples:
|
||||
./scripts/podx-tools.sh meili-health
|
||||
./scripts/podx-tools.sh meili-search "grand canyon" 10
|
||||
@@ -451,6 +474,7 @@ PY
|
||||
_require "OPENWEBUI_URL" "$OPENWEBUI_URL"
|
||||
_require "OPENWEBUI_API_KEY" "$OPENWEBUI_API_KEY"
|
||||
|
||||
TMP_EXTRACT=""
|
||||
# Decide how to send the file (force text/plain for .txt/.md; optionally extract JSON->text)
|
||||
upload_flag=("-F" "file=@$file")
|
||||
ext="${file##*.}"
|
||||
@@ -475,6 +499,7 @@ PY
|
||||
stem="${base%.*}"
|
||||
upload_flag=("-F" "file=@$tmp_txt;type=text/plain;filename=${stem}.txt")
|
||||
echo "[owui] extracted text from JSON -> ${stem}.txt"
|
||||
TMP_EXTRACT="$tmp_txt"
|
||||
else
|
||||
echo "[owui] WARNING: JSON had no extractable text, uploading raw JSON (may be rejected)" >&2
|
||||
fi
|
||||
@@ -507,7 +532,7 @@ PY
|
||||
if [ -z "$FILE_ID" ]; then echo "Upload failed (no file id)"; exit 1; fi
|
||||
|
||||
# Wait until OWUI finishes processing/extracting text for this file (prevents "content empty" 400)
|
||||
if ! _owui_wait_file "$FILE_ID" 180; then
|
||||
if ! _owui_wait_file "$FILE_ID" "$OPENWEBUI_WAIT_SECS"; then
|
||||
echo "[owui] WARNING: timed out waiting for file content; attach may fail if OWUI hasn't extracted text yet" >&2
|
||||
fi
|
||||
|
||||
@@ -537,6 +562,7 @@ PY
|
||||
echo "$RESP" | ppjson
|
||||
|
||||
rm -f "$tmp_body" "$tmp_code" "$tmp_hdrs"
|
||||
[ -n "${TMP_EXTRACT:-}" ] && rm -f "$TMP_EXTRACT"; unset TMP_EXTRACT
|
||||
|
||||
if [ $curl_exit -ne 0 ]; then
|
||||
echo "Attach failed: curl exit $curl_exit" >&2; exit $curl_exit
|
||||
@@ -550,6 +576,10 @@ PY
|
||||
: # success
|
||||
;;
|
||||
*)
|
||||
if printf '%s' "$RESP" | grep -qi "Duplicate content"; then
|
||||
echo "[owui] duplicate content — already indexed. Treating as success."
|
||||
exit 0
|
||||
fi
|
||||
echo "Attach failed (HTTP $http_code)" >&2; exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -564,6 +594,7 @@ PY
|
||||
_require "OPENWEBUI_URL" "$OPENWEBUI_URL"
|
||||
_require "OPENWEBUI_API_KEY" "$OPENWEBUI_API_KEY"
|
||||
|
||||
TMP_EXTRACT=""
|
||||
# Decide how to send the file (force text/plain for .txt/.md; optionally extract JSON->text)
|
||||
upload_flag=("-F" "file=@$file")
|
||||
ext="${file##*.}"
|
||||
@@ -588,6 +619,7 @@ PY
|
||||
stem="${base%.*}"
|
||||
upload_flag=("-F" "file=@$tmp_txt;type=text/plain;filename=${stem}.txt")
|
||||
echo "[owui] extracted text from JSON -> ${stem}.txt"
|
||||
TMP_EXTRACT="$tmp_txt"
|
||||
else
|
||||
echo "[owui] WARNING: JSON had no extractable text, uploading raw JSON (may be rejected)" >&2
|
||||
fi
|
||||
@@ -620,7 +652,7 @@ PY
|
||||
if [ -z "$FILE_ID" ]; then echo "Upload failed (no file id)"; exit 1; fi
|
||||
|
||||
# Wait until OWUI finishes processing/extracting text for this file (prevents "content empty" 400)
|
||||
if ! _owui_wait_file "$FILE_ID" 180; then
|
||||
if ! _owui_wait_file "$FILE_ID" "$OPENWEBUI_WAIT_SECS"; then
|
||||
echo "[owui] WARNING: timed out waiting for file content; attach may fail if OWUI hasn't extracted text yet" >&2
|
||||
fi
|
||||
|
||||
@@ -640,6 +672,7 @@ PY
|
||||
echo "$RESP" | ppjson
|
||||
|
||||
rm -f "$tmp_body" "$tmp_code" "$tmp_hdrs"
|
||||
[ -n "${TMP_EXTRACT:-}" ] && rm -f "$TMP_EXTRACT"; unset TMP_EXTRACT
|
||||
|
||||
if [ $curl_exit -ne 0 ]; then
|
||||
echo "Attach failed: curl exit $curl_exit" >&2; exit $curl_exit
|
||||
@@ -649,7 +682,13 @@ PY
|
||||
fi
|
||||
case "$http_code" in
|
||||
200|201|204) : ;;
|
||||
*) echo "Attach failed (HTTP $http_code)" >&2; exit 1 ;;
|
||||
*)
|
||||
if printf '%s' "$RESP" | grep -qi "Duplicate content"; then
|
||||
echo "[owui] duplicate content — already indexed. Treating as success."
|
||||
exit 0
|
||||
fi
|
||||
echo "Attach failed (HTTP $http_code)" >&2; exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
@@ -773,6 +812,31 @@ PY
|
||||
done
|
||||
;;
|
||||
|
||||
transcribe-status)
|
||||
# Prints 'paused' if the switch key is set to a truthy value, else 'running'
|
||||
val="$(_redis_cli GET "$_transcribe_key" 2>/dev/null || true)"
|
||||
if [ -n "${val:-}" ] && [ "${val}" != "(nil)" ] && [ "${val}" != "0" ]; then
|
||||
echo "paused"
|
||||
exit 0
|
||||
fi
|
||||
echo "running"
|
||||
;;
|
||||
transcribe-pause)
|
||||
if _redis_cli SET "$_transcribe_key" 1 >/dev/null; then
|
||||
echo "Transcription: paused"
|
||||
else
|
||||
echo "Failed to talk to redis to set pause switch." >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
transcribe-resume)
|
||||
if _redis_cli DEL "$_transcribe_key" >/dev/null; then
|
||||
echo "Transcription: resumed"
|
||||
else
|
||||
echo "Failed to talk to redis to clear pause switch." >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Unknown command: $cmd" >&2
|
||||
_help
|
||||
|
Reference in New Issue
Block a user