chatbot-web-app / response_handler.py
salomonsky's picture
Upload response_handler.py with huggingface_hub
9f8b4ae verified
class ResponseHandler:
# Palabras de activaci贸n
ACTIVATION_WORDS = [
"hola", "bueno", "d铆ga", "mande", "buenas"
]
# Palabras de aceptaci贸n
ACCEPTANCE_WORDS = [
"me interesa",
"quiero",
"acepto",
"suena bien",
"claro",
"de acuerdo",
"okey",
"adelante",
"perfecto",
"hag谩moslo"
]
# Palabras de negaci贸n
NEGATIVE_WORDS = [
"no",
"no me interesa",
"no quiero",
"no gracias",
"negativo",
"en otro momento",
"despu茅s",
"ahora no",
"lo pensar茅"
]
# Palabras de desactivaci贸n
DEACTIVATION_WORDS = [
"alto",
"detente",
"adi贸s",
"terminar",
"finalizar"
]
STOP_COMMANDS = [
"para",
"detente",
"silencio",
"c谩llate",
"espera",
"stop",
"alto",
"basta",
"suficiente",
"ya",
"shh",
"sh"
]
ACTIVATION_PHRASES = [
"hola asistente",
"oye asistente",
"hey asistente",
"asistente",
"bot",
"chatbot",
"hola bot",
"oye bot",
"hey bot"
]
@classmethod
def is_stop_command(cls, text):
"""Verifica si el texto es un comando de interrupci贸n"""
text = text.lower().strip()
return any(cmd in text for cmd in cls.STOP_COMMANDS)
@classmethod
def is_activation_phrase(cls, text):
"""Verifica si el texto es una frase de activaci贸n"""
text = text.lower().strip()
return any(phrase in text for phrase in cls.ACTIVATION_PHRASES)
@classmethod
def get_response_type(cls, text):
"""Determina el tipo de respuesta basado en el texto"""
text = text.lower().strip()
if cls.is_stop_command(text):
return "stop"
elif cls.is_activation_phrase(text):
return "activation"
else:
return "normal"
@classmethod
def is_acceptance_phrase(cls, text):
"""Verificar si el texto indica aceptaci贸n"""
return any(word in text.lower() for word in cls.ACCEPTANCE_WORDS)
@classmethod
def is_negative_phrase(cls, text):
"""Verificar si el texto indica negativa"""
return any(word in text.lower() for word in cls.NEGATIVE_WORDS)
@classmethod
def is_deactivation_phrase(cls, text):
"""Verificar si el texto indica desactivaci贸n"""
return any(word in text.lower() for word in cls.DEACTIVATION_WORDS)
@classmethod
def handle_response(cls, text, flow_bot, mode, data_manager):
"""Manejar la respuesta del usuario"""
# Primero verificar si es una orden de desactivaci贸n
if cls.is_deactivation_phrase(text):
return "DEACTIVATE" # Se帽al especial para desactivar
if cls.is_negative_phrase(text):
response = flow_bot.get_negative_response(mode)
data_manager.start_data_collection()
return response
if cls.is_acceptance_phrase(text):
data_manager.start_data_collection()
return flow_bot.get_success_message(mode)
return None # Indica que no es una respuesta especial