Fixing the fixes
This commit is contained in:
@@ -11,8 +11,14 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
# Writable temp dir (override with PODX_TMP or TMPDIR); default to repo tmp/
|
||||
: "${PODX_TMP:=${TMPDIR:-$ROOT_DIR/tmp}}"
|
||||
|
||||
mkdir -p "$PODX_TMP"
|
||||
|
||||
# Curl timeouts used for OWUI/Meili requests (override via env if needed)
|
||||
: "${PODX_CURL_CONNECT_TIMEOUT:=5}"
|
||||
: "${PODX_CURL_MAX_TIME:=20}"
|
||||
CURL_TMO="--connect-timeout $PODX_CURL_CONNECT_TIMEOUT --max-time $PODX_CURL_MAX_TIME"
|
||||
|
||||
# Portable mktemp helper that always writes inside $PODX_TMP (macOS/GNU compatible)
|
||||
_mktemp() {
|
||||
# mktemp on macOS doesn't support -p; use path template instead
|
||||
@@ -105,7 +111,7 @@ _owui_get_kb_list() {
|
||||
_require "OPENWEBUI_API_KEY" "$OPENWEBUI_API_KEY"
|
||||
_require "OPENWEBUI_URL" "$OPENWEBUI_URL"
|
||||
local url; url="$(_owui_url)/api/v1/knowledge/list"
|
||||
curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" "$url"
|
||||
curl -sS $CURL_TMO -H "Authorization: Bearer $OPENWEBUI_API_KEY" "$url"
|
||||
}
|
||||
|
||||
_kb_create() {
|
||||
@@ -276,13 +282,13 @@ print(f\"Indexed {n} document(s).\")"
|
||||
|
||||
owui-health)
|
||||
_require "OPENWEBUI_URL" "$OPENWEBUI_URL"
|
||||
curl -sS -o /dev/null -w "%{http_code}\n" "$(_owui_url)/api/health"
|
||||
curl -sS $CURL_TMO -o /dev/null -w "%{http_code}\n" "$(_owui_url)/api/health"
|
||||
;;
|
||||
|
||||
owui-kbs)
|
||||
_require "OPENWEBUI_URL" "$OPENWEBUI_URL"
|
||||
_require "OPENWEBUI_API_KEY" "$OPENWEBUI_API_KEY"
|
||||
curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" \
|
||||
curl -sS $CURL_TMO -H "Authorization: Bearer $OPENWEBUI_API_KEY" \
|
||||
"$(_owui_url)/api/v1/knowledge/list" | ppjson
|
||||
;;
|
||||
|
||||
@@ -312,8 +318,37 @@ print(f\"Indexed {n} document(s).\")"
|
||||
if [ -z "$name" ]; then echo "Usage: owui-kb-resolve \"<KB Name>\"" >&2; exit 1; fi
|
||||
echo "[owui] base URL: $(_owui_url)"
|
||||
echo "[owui] KBs returned:"
|
||||
_owui_get_kb_list | ppjson
|
||||
id="$(_kb_id_by_name "$name")"
|
||||
tmp_body="$(_mktemp)"; tmp_code="$(_mktemp)"
|
||||
curl -sS $CURL_TMO -H "Authorization: Bearer $OPENWEBUI_API_KEY" \
|
||||
-w "%{http_code}" --output "$tmp_body" \
|
||||
"$(_owui_url)/api/v1/knowledge/list" >"$tmp_code" || true
|
||||
http_code="$(cat "$tmp_code" 2>/dev/null || echo 0)"; rm -f "$tmp_code"
|
||||
bytes="$(wc -c <"$tmp_body" 2>/dev/null || echo 0)"
|
||||
cat "$tmp_body" | ppjson
|
||||
echo "[owui] http_code=$http_code bytes=$bytes"
|
||||
json="$(cat "$tmp_body")"; rm -f "$tmp_body"
|
||||
id="$(python3 - "$name" <<'PY'
|
||||
import sys, json
|
||||
want = (sys.argv[1] or "").strip()
|
||||
raw = sys.stdin.read()
|
||||
try:
|
||||
d = json.loads(raw)
|
||||
except Exception:
|
||||
print("", end=""); sys.exit(0)
|
||||
items = d.get("data") if isinstance(d, dict) and isinstance(d.get("data"), list) else (d if isinstance(d, list) else [])
|
||||
norm = lambda s: (s or "").strip().casefold()
|
||||
want_n = norm(want)
|
||||
def ts(kb):
|
||||
for k in ("updated_at","created_at"):
|
||||
v = kb.get(k)
|
||||
if isinstance(v,(int,float)): return int(v)
|
||||
return 0
|
||||
exact = [kb for kb in items if norm(kb.get("name")) == want_n]
|
||||
subs = [kb for kb in items if want_n and want_n in norm(kb.get("name"))]
|
||||
cands = exact or subs
|
||||
print((sorted(cands, key=ts, reverse=True)[0].get("id","")) if cands else "", end="")
|
||||
PY
|
||||
<<<"$json")"
|
||||
if [ -n "$id" ]; then
|
||||
echo "[owui] resolved id for \"$name\": $id"
|
||||
else
|
||||
|
Reference in New Issue
Block a user