import requests
import sys

# 📌 Konfiguration
API_URL = "http://localhost:8000/embed"

def import_text(text, collection="default"):
    """
    Sendet einen einzelnen Textabschnitt an die Embed-API zur Indexierung.
    """
    response = requests.post(API_URL, json={
        "texts": [text],
        "collection": collection
    })
    response.raise_for_status()
    return response.json()

if __name__ == "__main__":
    if len(sys.argv) < 3:
        print("❌ Nutzung: python import_texts.py <collection> \"<text>\"")
        sys.exit(1)

    collection = sys.argv[1]
    text = sys.argv[2]

    print(f"📤 Sende an Collection '{collection}': {text}")
    try:
        result = import_text(text, collection)
        print(f"✅ Antwort: {result}")
    except Exception as e:
        print(f"❌ Fehler beim Importieren: {e}")
