salomonsky commited on
Commit
9f8b4ae
verified
1 Parent(s): 0e5a555

Upload response_handler.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. response_handler.py +125 -0
response_handler.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class ResponseHandler:
2
+ # Palabras de activaci贸n
3
+ ACTIVATION_WORDS = [
4
+ "hola", "bueno", "d铆ga", "mande", "buenas"
5
+ ]
6
+
7
+ # Palabras de aceptaci贸n
8
+ ACCEPTANCE_WORDS = [
9
+ "me interesa",
10
+ "quiero",
11
+ "acepto",
12
+ "suena bien",
13
+ "claro",
14
+ "de acuerdo",
15
+ "okey",
16
+ "adelante",
17
+ "perfecto",
18
+ "hag谩moslo"
19
+ ]
20
+
21
+ # Palabras de negaci贸n
22
+ NEGATIVE_WORDS = [
23
+ "no",
24
+ "no me interesa",
25
+ "no quiero",
26
+ "no gracias",
27
+ "negativo",
28
+ "en otro momento",
29
+ "despu茅s",
30
+ "ahora no",
31
+ "lo pensar茅"
32
+ ]
33
+
34
+ # Palabras de desactivaci贸n
35
+ DEACTIVATION_WORDS = [
36
+ "alto",
37
+ "detente",
38
+ "adi贸s",
39
+ "terminar",
40
+ "finalizar"
41
+ ]
42
+
43
+ STOP_COMMANDS = [
44
+ "para",
45
+ "detente",
46
+ "silencio",
47
+ "c谩llate",
48
+ "espera",
49
+ "stop",
50
+ "alto",
51
+ "basta",
52
+ "suficiente",
53
+ "ya",
54
+ "shh",
55
+ "sh"
56
+ ]
57
+
58
+ ACTIVATION_PHRASES = [
59
+ "hola asistente",
60
+ "oye asistente",
61
+ "hey asistente",
62
+ "asistente",
63
+ "bot",
64
+ "chatbot",
65
+ "hola bot",
66
+ "oye bot",
67
+ "hey bot"
68
+ ]
69
+
70
+ @classmethod
71
+ def is_stop_command(cls, text):
72
+ """Verifica si el texto es un comando de interrupci贸n"""
73
+ text = text.lower().strip()
74
+ return any(cmd in text for cmd in cls.STOP_COMMANDS)
75
+
76
+ @classmethod
77
+ def is_activation_phrase(cls, text):
78
+ """Verifica si el texto es una frase de activaci贸n"""
79
+ text = text.lower().strip()
80
+ return any(phrase in text for phrase in cls.ACTIVATION_PHRASES)
81
+
82
+ @classmethod
83
+ def get_response_type(cls, text):
84
+ """Determina el tipo de respuesta basado en el texto"""
85
+ text = text.lower().strip()
86
+
87
+ if cls.is_stop_command(text):
88
+ return "stop"
89
+ elif cls.is_activation_phrase(text):
90
+ return "activation"
91
+ else:
92
+ return "normal"
93
+
94
+ @classmethod
95
+ def is_acceptance_phrase(cls, text):
96
+ """Verificar si el texto indica aceptaci贸n"""
97
+ return any(word in text.lower() for word in cls.ACCEPTANCE_WORDS)
98
+
99
+ @classmethod
100
+ def is_negative_phrase(cls, text):
101
+ """Verificar si el texto indica negativa"""
102
+ return any(word in text.lower() for word in cls.NEGATIVE_WORDS)
103
+
104
+ @classmethod
105
+ def is_deactivation_phrase(cls, text):
106
+ """Verificar si el texto indica desactivaci贸n"""
107
+ return any(word in text.lower() for word in cls.DEACTIVATION_WORDS)
108
+
109
+ @classmethod
110
+ def handle_response(cls, text, flow_bot, mode, data_manager):
111
+ """Manejar la respuesta del usuario"""
112
+ # Primero verificar si es una orden de desactivaci贸n
113
+ if cls.is_deactivation_phrase(text):
114
+ return "DEACTIVATE" # Se帽al especial para desactivar
115
+
116
+ if cls.is_negative_phrase(text):
117
+ response = flow_bot.get_negative_response(mode)
118
+ data_manager.start_data_collection()
119
+ return response
120
+
121
+ if cls.is_acceptance_phrase(text):
122
+ data_manager.start_data_collection()
123
+ return flow_bot.get_success_message(mode)
124
+
125
+ return None # Indica que no es una respuesta especial