Fix libraries finding
This commit is contained in:
@@ -122,10 +122,10 @@ _kb_create() {
|
|||||||
_kb_id_by_name() {
|
_kb_id_by_name() {
|
||||||
local kb_name="$1"
|
local kb_name="$1"
|
||||||
local json; json="$(_owui_get_kb_list)"
|
local json; json="$(_owui_get_kb_list)"
|
||||||
# Normalize to a flat list and choose the most recently updated match
|
# Normalize to a flat list and choose the most recently updated match (robust name matching)
|
||||||
python3 - "$kb_name" <<'PY' || true
|
python3 - "$kb_name" <<'PY' || true
|
||||||
import sys, json
|
import sys, json
|
||||||
name = sys.argv[1]
|
want = (sys.argv[1] or "").strip()
|
||||||
raw = sys.stdin.read().strip()
|
raw = sys.stdin.read().strip()
|
||||||
if not raw:
|
if not raw:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
@@ -133,7 +133,8 @@ try:
|
|||||||
d = json.loads(raw)
|
d = json.loads(raw)
|
||||||
except Exception:
|
except Exception:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
if isinstance(d, dict) and "data" in d and isinstance(d["data"], list):
|
# Support both list and {data:[...]}
|
||||||
|
if isinstance(d, dict) and isinstance(d.get("data"), list):
|
||||||
items = d["data"]
|
items = d["data"]
|
||||||
elif isinstance(d, list):
|
elif isinstance(d, list):
|
||||||
items = d
|
items = d
|
||||||
@@ -147,15 +148,20 @@ def ts(kb):
|
|||||||
return int(v)
|
return int(v)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
exact = sorted([kb for kb in items if kb.get("name") == name], key=ts, reverse=True)
|
# Helper to normalize a KB name for comparison
|
||||||
|
norm = lambda s: (s or "").strip().casefold()
|
||||||
|
want_n = norm(want)
|
||||||
|
|
||||||
|
# Try exact match (case/space-insensitive)
|
||||||
|
exact = [kb for kb in items if norm(kb.get("name")) == want_n]
|
||||||
if exact:
|
if exact:
|
||||||
print(exact[0].get("id", ""), end=""); sys.exit(0)
|
print(sorted(exact, key=ts, reverse=True)[0].get("id", ""), end=""); sys.exit(0)
|
||||||
iexact = sorted([kb for kb in items if isinstance(kb.get("name"), str) and kb["name"].lower() == name.lower()], key=ts, reverse=True)
|
|
||||||
if iexact:
|
# Then case-insensitive substring match
|
||||||
print(iexact[0].get("id", ""), end=""); sys.exit(0)
|
subs = [kb for kb in items if want_n and want_n in norm(kb.get("name"))]
|
||||||
sub = sorted([kb for kb in items if isinstance(kb.get("name"), str) and name.lower() in kb["name"].lower()], key=ts, reverse=True)
|
if subs:
|
||||||
if sub:
|
print(sorted(subs, key=ts, reverse=True)[0].get("id", ""), end=""); sys.exit(0)
|
||||||
print(sub[0].get("id", ""), end=""); sys.exit(0)
|
|
||||||
print("", end="")
|
print("", end="")
|
||||||
PY
|
PY
|
||||||
}
|
}
|
||||||
@@ -177,6 +183,7 @@ OpenWebUI:
|
|||||||
owui-health # check API health (200)
|
owui-health # check API health (200)
|
||||||
owui-kbs # list knowledge bases
|
owui-kbs # list knowledge bases
|
||||||
owui-kb-id "<KB Name>" # print the KB UUID by exact name
|
owui-kb-id "<KB Name>" # print the KB UUID by exact name
|
||||||
|
owui-kb-resolve "<KB Name>" # debug name->id resolution with raw listing
|
||||||
owui-upload </abs/path/file> # upload a file, prints file_id
|
owui-upload </abs/path/file> # upload a file, prints file_id
|
||||||
owui-attach "<KB Name>" </abs/path/file> # upload + attach to KB
|
owui-attach "<KB Name>" </abs/path/file> # upload + attach to KB
|
||||||
owui-kb-create "<KB Name>" # create a KB (prints JSON with id)
|
owui-kb-create "<KB Name>" # create a KB (prints JSON with id)
|
||||||
@@ -299,6 +306,21 @@ print(f\"Indexed {n} document(s).\")"
|
|||||||
echo "$_id"
|
echo "$_id"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
owui-kb-resolve)
|
||||||
|
shift || true
|
||||||
|
name="${1:-}"
|
||||||
|
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")"
|
||||||
|
if [ -n "$id" ]; then
|
||||||
|
echo "[owui] resolved id for \"$name\": $id"
|
||||||
|
else
|
||||||
|
echo "[owui] could not resolve an id for \"$name\"" >&2
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
owui-upload)
|
owui-upload)
|
||||||
shift || true
|
shift || true
|
||||||
file="${1:-}"
|
file="${1:-}"
|
||||||
@@ -361,7 +383,7 @@ print(f\"Indexed {n} document(s).\")"
|
|||||||
echo "[owui] attaching to KB: $kb_name (id: $KB_ID)"
|
echo "[owui] attaching to KB: $kb_name (id: $KB_ID)"
|
||||||
if [ -z "$KB_ID" ]; then
|
if [ -z "$KB_ID" ]; then
|
||||||
echo "KB '$kb_name' not found (or ambiguous)." >&2
|
echo "KB '$kb_name' not found (or ambiguous)." >&2
|
||||||
echo "Tip: run './scripts/podx-tools.sh owui-kb-debug \"$kb_name\"' or create one:" >&2
|
echo "Tip: run './scripts/podx-tools.sh owui-kb-resolve \"$kb_name\"' to inspect and resolve, or create one:" >&2
|
||||||
echo " ./scripts/podx-tools.sh owui-kb-create \"$kb_name\"" >&2
|
echo " ./scripts/podx-tools.sh owui-kb-create \"$kb_name\"" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user