File size: 2,280 Bytes
d59f70d 2068f20 d59f70d 2068f20 d59f70d 2068f20 d59f70d 2068f20 d59f70d 2068f20 d59f70d 2068f20 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | import requests
import json
import os
from dotenv import load_dotenv
load_dotenv()
BASE_URL = os.getenv("WEBUI_URL", "http://localhost:7860").rstrip("/")
API_KEY = os.getenv("WEBUI_API_KEY", "")
ENDPOINTS = {
"config": "/api/config",
"models": "/api/models",
"tools": "/api/v1/tools/",
"functions": "/api/v1/functions/",
"prompts": "/api/v1/prompts/",
"knowledge": "/api/v1/knowledge/",
}
os.makedirs("samples", exist_ok=True)
def test_endpoint(name, path):
url = f"{BASE_URL}{path}"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Accept": "application/json",
}
print(f"\nTesting {name}: {url}")
try:
response = requests.get(url, headers=headers, timeout=10)
print(f" Status: {response.status_code}")
if response.status_code == 200:
try:
data = response.json()
count = len(data) if isinstance(data, list) else "N/A (object)"
print(f" β
Success! Items: {count}")
with open(f"samples/{name}.json", "w") as f:
json.dump(data, f, indent=2)
print(f" πΎ Saved to samples/{name}.json")
return data
except Exception:
print(f" β οΈ Response is not JSON. Body: {response.text[:200]}")
else:
print(f" β Failed: {response.text[:200]}")
except Exception as e:
print(f" β οΈ Error: {e}")
return None
if __name__ == "__main__":
print("=" * 50)
print("Open WebUI API Probe β Step 1D")
print(f"Instance: {BASE_URL}")
print(f"Auth: {'β
Key loaded' if API_KEY else 'β No WEBUI_API_KEY in .env'}")
print("=" * 50)
results = {}
for name, path in ENDPOINTS.items():
results[name] = test_endpoint(name, path)
print("\n" + "=" * 50)
print("SUMMARY")
print("=" * 50)
for name, data in results.items():
if data is None:
print(f" β {name}: failed")
elif isinstance(data, list):
print(f" β
{name}: {len(data)} items")
else:
print(f" β
{name}: returned object")
print("\nSample JSON files saved to: ./samples/")
|