import sys
import requests

API_URL = "http://localhost:8000/prompt"

if len(sys.argv) < 3:
    print("❌ Verwendung: python prompt_documents.py <collection> <frage>")
    sys.exit(1)

collection = sys.argv[1]
query = " ".join(sys.argv[2:])

data = {
    "query": query,
    "collection": collection,
    "context_limit": 3
}

print(f"🤖 Anfrage an LLM aus Collection '{collection}': {query}")
try:
    response = requests.post(API_URL, json=data)
    response.raise_for_status()
    result = response.json()
except Exception as e:
    print(f"❌ Fehler bei der Anfrage: {e}")
    sys.exit(1)

print("\n📄 Kontext:")
print(result["context"])

print("\n💡 Antwort:")
print(result["answer"])
