import json import os from datetime import datetime def detect_language(text: str) -> str: if any(char in 'áéíóúñÁÉÍÓÚÑ¿¡' for char in text): return "es" return "en" def save_history(history, filename="chat_history.json"): with open(filename, "w", encoding="utf-8") as f: json.dump(history, f, ensure_ascii=False, indent=2) def load_history(filename="chat_history.json"): if os.path.exists(filename): with open(filename, "r", encoding="utf-8") as f: return json.load(f) return []