Bot_batutoBAD / utils.py
BATUTO-ART's picture
Create utils.py
bfdc0fb verified
raw
history blame
552 Bytes
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 []