web_chat.py

Code Hygiene Score: 100

Keine Issues gefunden.

Dependencies 4

Funktionen 1

Code

#!/usr/bin/env python3
"""
Web Chat Interface for KI-System
Called from PHP with question file as argument.
"""

import json
import os
import sys

# Change to pipeline directory and add to path
PIPELINE_PATH = "/var/www/scripts/pipeline"
os.chdir(PIPELINE_PATH)
sys.path.insert(0, PIPELINE_PATH)

from chat import chat


def main():
    """Process chat question from file and return JSON response."""
    if len(sys.argv) < 2:
        print(json.dumps({"error": "No question file provided"}))
        return

    question_file = sys.argv[1]

    try:
        with open(question_file, encoding="utf-8") as f:
            question = f.read().strip()

        if not question:
            print(json.dumps({"error": "Empty question"}))
            return

        result = chat(question)
        print(json.dumps(result, ensure_ascii=False))

    except Exception as e:
        print(json.dumps({"error": str(e)}))


if __name__ == "__main__":
    main()
← Übersicht