Datei hochladen
curl -X POST 'https://IHRE-NOVA-DOMAIN/api/v1/files/' -H 'Authorization: Bearer IHR_API_SCHLUESSEL' -F 'file=@handbuch.pdf'
Die Antwort enthält die Datei-ID für die folgenden Aufrufe.
Verarbeitung prüfen
curl 'https://IHRE-NOVA-DOMAIN/api/v1/files/DATEI_ID/process/status' -H 'Authorization: Bearer IHR_API_SCHLUESSEL'
Warten Sie auf den Status completed.
Wissenssammlung zuordnen
curl -X POST 'https://IHRE-NOVA-DOMAIN/api/v1/knowledge/WISSENS_ID/file/add' -H 'Authorization: Bearer IHR_API_SCHLUESSEL' -H 'Content-Type: application/json' -d '{"file_id":"DATEI_ID"}'
Vollständiges Python-Beispiel
import os
import time
from pathlib import Path
import requests
NOVA_URL = os.environ["NOVA_URL"].rstrip("/")
API_KEY = os.environ["NOVA_API_KEY"]
KNOWLEDGE_ID = os.environ["NOVA_KNOWLEDGE_ID"]
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
def ingest_document(file_path, timeout=600):
path = Path(file_path)
with path.open("rb") as handle:
response = requests.post(
f"{NOVA_URL}/api/v1/files/",
headers=HEADERS,
files={"file": (path.name, handle)},
timeout=120,
)
response.raise_for_status()
file_id = response.json()["id"]
deadline = time.monotonic() + timeout
while time.monotonic() deadline:
response = requests.get(
f"{NOVA_URL}/api/v1/files/{file_id}/process/status",
headers=HEADERS, timeout=30,
)
response.raise_for_status()
status = response.json().get("status")
if status == "completed":
break
if status in ("failed", "error"):
raise RuntimeError("Die Dateiverarbeitung ist fehlgeschlagen.")
time.sleep(2)
else:
raise TimeoutError("Die Dateiverarbeitung dauert zu lange.")
response = requests.post(
f"{NOVA_URL}/api/v1/knowledge/{KNOWLEDGE_ID}/file/add",
headers=HEADERS, json={"file_id": file_id}, timeout=30,
)
response.raise_for_status()
return response.json()
# Beispiel: ingest_document("handbuch.pdf")
Das Beispiel benötigt Python und das Paket requests. Die Konfiguration wird aus Umgebungsvariablen gelesen.