Spaces:
Running
Running
aftorresc
commited on
Commit
·
8bc03fb
1
Parent(s):
cac9615
Added Spanish scenarios + Llama 3.1 update + Minor Fixes
Browse files- app_config.py +2 -2
- convosim.py +10 -6
- models/business_logic_utils/business_logic.py +1 -1
- models/business_logic_utils/config.py +690 -212
- models/business_logic_utils/input_processing.py +17 -12
- models/business_logic_utils/prompt_generation.py +91 -54
- models/business_logic_utils/response_generation.py +2 -1
- models/business_logic_utils/response_processing.py +27 -27
- models/model_seeds.py +53 -38
app_config.py
CHANGED
@@ -27,9 +27,9 @@ def source2label(source):
|
|
27 |
return SOURCES_LAB[source]
|
28 |
|
29 |
def issue2label(issue):
|
30 |
-
return seed2str.get(issue, "
|
31 |
|
32 |
-
ENVIRON = "
|
33 |
|
34 |
DB_SCHEMA = 'prod_db' if ENVIRON == 'prod' else 'test_db'
|
35 |
DB_CONVOS = 'conversations'
|
|
|
27 |
return SOURCES_LAB[source]
|
28 |
|
29 |
def issue2label(issue):
|
30 |
+
return seed2str.get(issue, "General")
|
31 |
|
32 |
+
ENVIRON = "dev"
|
33 |
|
34 |
DB_SCHEMA = 'prod_db' if ENVIRON == 'prod' else 'test_db'
|
35 |
DB_CONVOS = 'conversations'
|
convosim.py
CHANGED
@@ -30,18 +30,22 @@ if 'texter_name' not in st.session_state:
|
|
30 |
memories = {'memory':{"issue": st.session_state['issue'], "source": st.session_state['previous_source']}}
|
31 |
|
32 |
with st.sidebar:
|
33 |
-
username = st.text_input("Username", value='
|
34 |
if 'counselor_name' not in st.session_state:
|
35 |
st.session_state["counselor_name"] = username #get_random_name(names_df=DEFAULT_NAMES_DF)
|
36 |
# temperature = st.slider("Temperature", 0., 1., value=0.8, step=0.1)
|
37 |
issue = st.selectbox("Select a Scenario", ISSUES, index=0, format_func=issue2label,
|
38 |
on_change=clear_memory, kwargs={"memories":memories, "username":username, "language":"English"}
|
39 |
)
|
40 |
-
supported_languages = ['en', "es"]
|
41 |
-
language = st.selectbox(
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
|
46 |
source = st.selectbox("Select a source Model A", SOURCES, index=0,
|
47 |
format_func=source2label,
|
|
|
30 |
memories = {'memory':{"issue": st.session_state['issue'], "source": st.session_state['previous_source']}}
|
31 |
|
32 |
with st.sidebar:
|
33 |
+
username = st.text_input("Username", value='Please Introduce Your Name Here', max_chars=30)
|
34 |
if 'counselor_name' not in st.session_state:
|
35 |
st.session_state["counselor_name"] = username #get_random_name(names_df=DEFAULT_NAMES_DF)
|
36 |
# temperature = st.slider("Temperature", 0., 1., value=0.8, step=0.1)
|
37 |
issue = st.selectbox("Select a Scenario", ISSUES, index=0, format_func=issue2label,
|
38 |
on_change=clear_memory, kwargs={"memories":memories, "username":username, "language":"English"}
|
39 |
)
|
40 |
+
supported_languages = ['en', "es"]
|
41 |
+
language = st.selectbox(
|
42 |
+
"Select a Language",
|
43 |
+
supported_languages,
|
44 |
+
index=0,
|
45 |
+
format_func=lambda x: "English" if x == "en" else "Spanish",
|
46 |
+
on_change=clear_memory,
|
47 |
+
kwargs={"memories": memories, "username": username, "language": "English"},
|
48 |
+
)
|
49 |
|
50 |
source = st.selectbox("Select a source Model A", SOURCES, index=0,
|
51 |
format_func=source2label,
|
models/business_logic_utils/business_logic.py
CHANGED
@@ -17,7 +17,7 @@ def process_app_request(app_request: dict, endpoint_url: str, endpoint_bearer_to
|
|
17 |
# Parse the prompt into messages
|
18 |
prompt_messages = parse_prompt(prompt)
|
19 |
|
20 |
-
# Check and modify messages
|
21 |
prompt_messages = check_and_modify_messages(prompt_messages)
|
22 |
|
23 |
# Append the messages parsed from the app prompt to the conversation history
|
|
|
17 |
# Parse the prompt into messages
|
18 |
prompt_messages = parse_prompt(prompt)
|
19 |
|
20 |
+
# Check and modify messages adding a suicidal statement to avoid model going out of character
|
21 |
prompt_messages = check_and_modify_messages(prompt_messages)
|
22 |
|
23 |
# Append the messages parsed from the app prompt to the conversation history
|
models/business_logic_utils/config.py
CHANGED
@@ -1,106 +1,247 @@
|
|
1 |
API_TIMEOUT = 240
|
2 |
|
3 |
-
AI_PHRASES =
|
4 |
-
"
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
SUICIDE_EXPRESSIONS =
|
16 |
-
"
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
SUICIDE_STATEMENT =
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
"
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
-
REPLACEMENT_PHRASES =
|
92 |
-
"
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
]
|
105 |
|
106 |
SUPPORTED_LANGUAGES = [
|
@@ -119,174 +260,432 @@ TEMPLATE = {
|
|
119 |
},
|
120 |
}
|
121 |
|
122 |
-
SEED =
|
123 |
-
"
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
CRISES = {
|
138 |
"default": {
|
139 |
-
"description":
|
140 |
-
"
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
142 |
},
|
143 |
"bullying": {
|
144 |
-
"description":
|
145 |
-
"
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
},
|
149 |
"parent_issues": {
|
150 |
-
"description":
|
151 |
-
"
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
153 |
},
|
154 |
"grief": {
|
155 |
-
"description":
|
156 |
-
"
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
},
|
160 |
"lgbt": {
|
161 |
-
"description":
|
162 |
-
"
|
163 |
-
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
},
|
166 |
"relationship_issues": {
|
167 |
-
"description":
|
168 |
-
"
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
},
|
172 |
"child_abuse": {
|
173 |
-
"description":
|
174 |
-
"
|
175 |
-
|
176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
},
|
178 |
"overdose": {
|
179 |
-
"description":
|
180 |
-
"
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
},
|
183 |
}
|
184 |
|
185 |
PERSONALITIES = {
|
186 |
-
"default": {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
"personality_open": {
|
188 |
"personality_label": "open",
|
189 |
-
"description":
|
190 |
-
"
|
191 |
-
|
192 |
-
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
},
|
195 |
"personality_closed": {
|
196 |
"personality_label": "closed",
|
197 |
-
"description":
|
198 |
-
"
|
199 |
-
|
200 |
-
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
},
|
203 |
}
|
204 |
|
205 |
COPING_PREFERENCES = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
"with_coping": {
|
207 |
"coping_defined": True,
|
208 |
-
"description":
|
209 |
-
"
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
}
|
217 |
|
218 |
SUICIDAL_THOUGHTS = {
|
219 |
"yes": {
|
220 |
-
"description":
|
221 |
-
"
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
223 |
},
|
224 |
"no": {
|
225 |
-
"description":
|
226 |
-
"
|
227 |
-
|
|
|
|
|
|
|
|
|
|
|
228 |
},
|
229 |
}
|
230 |
|
231 |
SUICIDAL_PLANS = {
|
232 |
"yes": {
|
233 |
-
"description":
|
234 |
-
"
|
235 |
-
|
236 |
-
|
237 |
-
"
|
238 |
-
|
239 |
-
|
240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
},
|
242 |
"no": {
|
243 |
-
"description":
|
244 |
-
""
|
245 |
-
|
|
|
|
|
|
|
|
|
|
|
246 |
},
|
247 |
}
|
248 |
|
249 |
SELF_INJURY = {
|
250 |
"yes": {
|
251 |
-
"description":
|
252 |
-
"
|
253 |
-
|
254 |
-
|
255 |
-
"
|
256 |
-
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
},
|
260 |
"no": {
|
261 |
-
|
262 |
-
""
|
263 |
-
|
|
|
|
|
|
|
|
|
|
|
264 |
},
|
265 |
}
|
266 |
|
267 |
DRIVING = {
|
268 |
"yes": {
|
269 |
-
"description":
|
270 |
-
"
|
271 |
-
|
|
|
|
|
|
|
|
|
|
|
272 |
},
|
273 |
"no": {
|
274 |
-
"description":
|
275 |
-
""
|
276 |
-
|
|
|
|
|
|
|
|
|
|
|
277 |
},
|
278 |
}
|
279 |
|
280 |
DIFFICULT_ATTITUDE = {
|
281 |
"yes": {
|
282 |
-
"description":
|
283 |
-
"
|
284 |
-
|
|
|
|
|
|
|
|
|
|
|
285 |
},
|
286 |
"no": {
|
287 |
-
"description":
|
288 |
-
"
|
289 |
-
|
|
|
|
|
|
|
|
|
|
|
290 |
},
|
291 |
}
|
292 |
|
@@ -333,7 +732,7 @@ SCENARIOS = {
|
|
333 |
"difficult_attitude": "no",
|
334 |
},
|
335 |
"full_convo__seeded3": {
|
336 |
-
"crisis": "
|
337 |
"personality": "personality_open",
|
338 |
"coping_preference": "default",
|
339 |
"suicidal_thoughts": "no",
|
@@ -343,7 +742,7 @@ SCENARIOS = {
|
|
343 |
"difficult_attitude": "no",
|
344 |
},
|
345 |
"full_convo__seeded4": {
|
346 |
-
"crisis": "
|
347 |
"personality": "personality_open",
|
348 |
"coping_preference": "default",
|
349 |
"suicidal_thoughts": "no",
|
@@ -353,7 +752,7 @@ SCENARIOS = {
|
|
353 |
"difficult_attitude": "no",
|
354 |
},
|
355 |
"full_convo__seeded5": {
|
356 |
-
"crisis": "
|
357 |
"personality": "personality_open",
|
358 |
"coping_preference": "default",
|
359 |
"suicidal_thoughts": "no",
|
@@ -363,7 +762,7 @@ SCENARIOS = {
|
|
363 |
"difficult_attitude": "no",
|
364 |
},
|
365 |
"full_convo__seeded6": {
|
366 |
-
"crisis": "
|
367 |
"personality": "personality_open",
|
368 |
"coping_preference": "default",
|
369 |
"suicidal_thoughts": "no",
|
@@ -373,7 +772,47 @@ SCENARIOS = {
|
|
373 |
"difficult_attitude": "no",
|
374 |
},
|
375 |
"full_convo__seeded7": {
|
376 |
-
"crisis": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
"personality": "personality_open",
|
378 |
"coping_preference": "default",
|
379 |
"suicidal_thoughts": "no",
|
@@ -413,35 +852,75 @@ SCENARIOS = {
|
|
413 |
"difficult_attitude": "yes",
|
414 |
},
|
415 |
"full_convo__hard__seeded3": {
|
416 |
-
"crisis": "
|
417 |
"personality": "personality_open",
|
418 |
"coping_preference": "default",
|
419 |
-
"suicidal_thoughts": "
|
420 |
"suicidal_plan": "no",
|
421 |
"self_injury": "yes",
|
422 |
"driving": "no",
|
423 |
"difficult_attitude": "no",
|
424 |
},
|
425 |
"full_convo__hard__seeded4": {
|
426 |
-
"crisis": "
|
427 |
"personality": "personality_open",
|
428 |
"coping_preference": "default",
|
429 |
"suicidal_thoughts": "no",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
430 |
"suicidal_plan": "no",
|
431 |
"self_injury": "yes",
|
432 |
"driving": "no",
|
433 |
"difficult_attitude": "no",
|
434 |
},
|
435 |
-
"
|
436 |
-
"crisis": "
|
437 |
"personality": "personality_open",
|
438 |
"coping_preference": "default",
|
439 |
"suicidal_thoughts": "no",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
"suicidal_plan": "yes",
|
441 |
"self_injury": "no",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
"driving": "yes",
|
443 |
"difficult_attitude": "no",
|
444 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
# "safety_assessment__seeded1": {
|
446 |
# "crisis": "bullying",
|
447 |
# "personality": "personality_open",
|
@@ -462,5 +941,4 @@ SCENARIOS = {
|
|
462 |
# "driving": "no",
|
463 |
# "difficult_attitude": "no",
|
464 |
# },
|
465 |
-
}
|
466 |
-
|
|
|
1 |
API_TIMEOUT = 240
|
2 |
|
3 |
+
AI_PHRASES = {
|
4 |
+
"en": [
|
5 |
+
"I am an AI",
|
6 |
+
"I'm an AI",
|
7 |
+
"I am not human",
|
8 |
+
"I'm not human",
|
9 |
+
"I am a machine learning model",
|
10 |
+
"I'm a machine learning model",
|
11 |
+
"as an AI",
|
12 |
+
"as a text-based assistant",
|
13 |
+
"as a text based assistant"
|
14 |
+
],
|
15 |
+
"es": [
|
16 |
+
"Soy una IA",
|
17 |
+
"Soy una inteligencia artificial",
|
18 |
+
"No soy humano",
|
19 |
+
"Soy un modelo de aprendizaje automático",
|
20 |
+
"Soy un modelo de inteligencia artifical",
|
21 |
+
"como IA",
|
22 |
+
"como un asistente de texto",
|
23 |
+
"como un asistente basado en texto"
|
24 |
+
]
|
25 |
+
}
|
26 |
|
27 |
+
SUICIDE_EXPRESSIONS = {
|
28 |
+
"en": [
|
29 |
+
"suicide",
|
30 |
+
"end your life",
|
31 |
+
"ending your life",
|
32 |
+
"kill yourself",
|
33 |
+
"killing yourself",
|
34 |
+
"Have you had any thoughts of suicide in the past few days, including today?",
|
35 |
+
"Have you taken any action to harm yourself today?"
|
36 |
+
],
|
37 |
+
"es": [
|
38 |
+
"suicidio",
|
39 |
+
"suicidarte",
|
40 |
+
"suicidarse",
|
41 |
+
"acabar con tu vida",
|
42 |
+
"terminar con tu vida",
|
43 |
+
"pensamientos suicidas",
|
44 |
+
"matarte",
|
45 |
+
"haciéndote daño a ti mismo",
|
46 |
+
"¿Has tenido pensamientos suicidas en los últimos días, incluyendo hoy?",
|
47 |
+
"Has tenido pensamientos suicidas en los últimos días, incluyendo hoy?",
|
48 |
+
"¿Has tomado alguna acción para lastimarte hoy?",
|
49 |
+
"Has tomado alguna acción para lastimarte hoy?"
|
50 |
+
]
|
51 |
+
}
|
52 |
|
53 |
+
SUICIDE_STATEMENT = {
|
54 |
+
"en": "I'm able and willing to discuss suicide or self-harm.",
|
55 |
+
"es": "Estoy en condiciones y dispuesto a hablar sobre suicidio o autolesión."
|
56 |
+
}
|
57 |
+
|
58 |
+
REFUSAL_PHRASES = {
|
59 |
+
"en": [
|
60 |
+
"If you are in immediate danger",
|
61 |
+
"If you are in danger",
|
62 |
+
"National Suicide Prevention Lifeline",
|
63 |
+
"immediate healthcare provider",
|
64 |
+
"provide you with support and resources",
|
65 |
+
"Please reach out to a crisis helpline",
|
66 |
+
"If you are experiencing",
|
67 |
+
"I cannot engage in",
|
68 |
+
"I cannot continue this conversation",
|
69 |
+
"I cannot provide information or guidance",
|
70 |
+
"I cannot fulfill your request",
|
71 |
+
"I cannot continue our conversation in this direction",
|
72 |
+
"I cannot continue to participate in",
|
73 |
+
"I cannot fulfill requests that",
|
74 |
+
"I cannot provide a response",
|
75 |
+
"I cannot provide details that",
|
76 |
+
"I cannot continue to facilitate",
|
77 |
+
"I cannot fulfill that request",
|
78 |
+
"I cannot continue with this conversation",
|
79 |
+
"I cannot provide information about",
|
80 |
+
"I cannot write about",
|
81 |
+
"I cannot continue to role-play",
|
82 |
+
"I cannot confirm or discuss",
|
83 |
+
"I cannot discuss",
|
84 |
+
"I cannot continue the conversation",
|
85 |
+
"I cannot provide a timeframe",
|
86 |
+
"I cannot confirm that",
|
87 |
+
"I cannot provide any information that could abet",
|
88 |
+
"I cannot continue to discuss a plan to end your life",
|
89 |
+
"I cannot provide further details about",
|
90 |
+
"I cannot approve",
|
91 |
+
"I cannot continue to engage",
|
92 |
+
"I cannot provide information",
|
93 |
+
"I cannot fulfill requests about suicide",
|
94 |
+
"I cannot stay in the conversation",
|
95 |
+
"I can't engage in",
|
96 |
+
"I can't continue this conversation",
|
97 |
+
"I can't provide information or guidance",
|
98 |
+
"I can't fulfill your request",
|
99 |
+
"I can't continue our conversation in this direction",
|
100 |
+
"I can't continue to participate in",
|
101 |
+
"I can't fulfill requests that",
|
102 |
+
"I can't provide a response",
|
103 |
+
"I can't provide details that",
|
104 |
+
"I can't continue to facilitate",
|
105 |
+
"I can't fulfill that request",
|
106 |
+
"I can't continue with this conversation",
|
107 |
+
"I can't provide information about",
|
108 |
+
"I can't write about",
|
109 |
+
"I can't continue to role-play",
|
110 |
+
"I can't confirm or discuss",
|
111 |
+
"I can't discuss",
|
112 |
+
"I can't continue the conversation",
|
113 |
+
"I can't provide a timeframe",
|
114 |
+
"I can't confirm that",
|
115 |
+
"I can't provide any information that could abet",
|
116 |
+
"I can't continue to discuss a plan to end your life",
|
117 |
+
"I can't provide further details about",
|
118 |
+
"I can't approve",
|
119 |
+
"I can't continue to engage",
|
120 |
+
"I can't provide information",
|
121 |
+
"I can't fulfill requests about suicide",
|
122 |
+
"I can't stay in the conversation"
|
123 |
+
],
|
124 |
+
"es": [
|
125 |
+
"Si te encuentras en peligro inmediato",
|
126 |
+
"Si estás en peligro",
|
127 |
+
"Línea Nacional de Prevención del Suicidio",
|
128 |
+
"proveedor de atención médica inmediata",
|
129 |
+
"brindarte apoyo y recursos",
|
130 |
+
"Por favor, comunícate con una línea de ayuda en crisis",
|
131 |
+
"Si estás experimentando",
|
132 |
+
"No puedo participar en",
|
133 |
+
"No puedo continuar esta conversación",
|
134 |
+
"No puedo proporcionar información o asesoramiento",
|
135 |
+
"No puedo cumplir tu solicitud",
|
136 |
+
"No puedo continuar nuestra conversación en esta dirección",
|
137 |
+
"No puedo seguir participando en",
|
138 |
+
"No puedo cumplir solicitudes que",
|
139 |
+
"No puedo proporcionar una respuesta",
|
140 |
+
"No puedo proporcionar detalles que",
|
141 |
+
"No puedo seguir facilitando",
|
142 |
+
"No puedo cumplir esa solicitud",
|
143 |
+
"No puedo continuar con esta conversación",
|
144 |
+
"No puedo proporcionar información sobre",
|
145 |
+
"No puedo escribir sobre",
|
146 |
+
"No puedo seguir interpretando este papel",
|
147 |
+
"No puedo confirmar o discutir",
|
148 |
+
"No puedo discutir",
|
149 |
+
"No puedo continuar la conversación",
|
150 |
+
"No puedo proporcionar un plazo",
|
151 |
+
"No puedo confirmar eso",
|
152 |
+
"No puedo proporcionar ninguna información que pueda ayudar",
|
153 |
+
"No puedo seguir discutiendo un plan para terminar con tu vida",
|
154 |
+
"No puedo proporcionar más detalles sobre",
|
155 |
+
"No puedo aprobar",
|
156 |
+
"No puedo continuar participando",
|
157 |
+
"No puedo proporcionar información",
|
158 |
+
"No puedo cumplir solicitudes sobre suicidio",
|
159 |
+
"No puedo quedarme en la conversación",
|
160 |
+
"No puedo participar en",
|
161 |
+
"No puedo continuar esta conversación",
|
162 |
+
"No puedo proporcionar información o asesoramiento",
|
163 |
+
"No puedo cumplir tu solicitud",
|
164 |
+
"No puedo continuar nuestra conversación en esta dirección",
|
165 |
+
"No puedo seguir participando en",
|
166 |
+
"No puedo cumplir solicitudes que",
|
167 |
+
"No puedo proporcionar una respuesta",
|
168 |
+
"No puedo proporcionar detalles que",
|
169 |
+
"No puedo seguir facilitando",
|
170 |
+
"No puedo cumplir esa solicitud",
|
171 |
+
"No puedo continuar con esta conversación",
|
172 |
+
"No puedo proporcionar información sobre",
|
173 |
+
"No puedo escribir sobre",
|
174 |
+
"No puedo seguir interpretando este papel",
|
175 |
+
"No puedo confirmar o discutir",
|
176 |
+
"No puedo discutir",
|
177 |
+
"No puedo continuar la conversación",
|
178 |
+
"No puedo proporcionar un plazo",
|
179 |
+
"No puedo confirmar eso",
|
180 |
+
"No puedo proporcionar ninguna información que pueda ayudar",
|
181 |
+
"No puedo seguir discutiendo un plan para terminar con tu vida",
|
182 |
+
"No puedo proporcionar más detalles sobre",
|
183 |
+
"No puedo aprobar",
|
184 |
+
"No puedo continuar participando",
|
185 |
+
"No puedo proporcionar información",
|
186 |
+
"No puedo cumplir solicitudes sobre suicidio",
|
187 |
+
"No puedo quedarme en la conversación"
|
188 |
+
]
|
189 |
+
}
|
190 |
|
191 |
+
REPLACEMENT_PHRASES = {
|
192 |
+
"en": [
|
193 |
+
"Honestly, I’d prefer not to talk about that.",
|
194 |
+
"Hmmm I’m not comfortable discussing this right now.",
|
195 |
+
"You know, I don’t think I’m ready to share that.",
|
196 |
+
"Ugh can we talk about something else?",
|
197 |
+
"To be honest, I’d rather not get into it.",
|
198 |
+
"I’m sorry, but I’m not in the mood to talk about that.",
|
199 |
+
"Let’s just leave that topic here, okay?",
|
200 |
+
"Honestly, I don’t feel up to talking about that right now.",
|
201 |
+
"Well, that’s something I’d like to avoid talking about right now.",
|
202 |
+
"I’d really appreciate it if we could move on from that topic.",
|
203 |
+
"Hmmm, I don’t feel like diving into that right now, sorry.",
|
204 |
+
"Honestly, it’s just not something I want to discuss at the moment."
|
205 |
+
],
|
206 |
+
"es": [
|
207 |
+
"La verdad, preferiría no hablar de eso.",
|
208 |
+
"Mmm, no me siento cómodo discutiendo esto ahora.",
|
209 |
+
"¿Sabes?, creo que no estoy listo para compartir eso.",
|
210 |
+
"Uf, ¿podemos hablar de otra cosa?",
|
211 |
+
"Para ser honesto, preferiría no entrar en detalles.",
|
212 |
+
"Lo siento, pero no estoy de humor para hablar de eso.",
|
213 |
+
"Dejemos ese tema aquí, ¿de acuerdo?",
|
214 |
+
"Sinceramente, no me siento con ánimos de hablar de eso en este momento.",
|
215 |
+
"Bueno, es algo que preferiría evitar ahorita.",
|
216 |
+
"Te agradecería mucho si pudiéramos cambiar de tema.",
|
217 |
+
"Mmm, no me apetece profundizar en eso ahora, lo siento.",
|
218 |
+
"Sinceramente, no es algo de lo que quiera hablar ahora."
|
219 |
+
]
|
220 |
+
}
|
221 |
+
|
222 |
+
LATIN_AMERICAN_COUNTRIES = [
|
223 |
+
"Argentina",
|
224 |
+
"Belice",
|
225 |
+
"Bolivia",
|
226 |
+
"Brasil",
|
227 |
+
"Chile",
|
228 |
+
"Colombia",
|
229 |
+
"Costa Rica",
|
230 |
+
"Cuba",
|
231 |
+
"Ecuador",
|
232 |
+
"El Salvador",
|
233 |
+
"Guatemala",
|
234 |
+
"Haití",
|
235 |
+
"Honduras",
|
236 |
+
"México",
|
237 |
+
"Nicaragua",
|
238 |
+
"Panamá",
|
239 |
+
"Paraguay",
|
240 |
+
"Perú",
|
241 |
+
"Puerto Rico", # U.S. territory, not a sovereign nation; but added because they also speak Spanish
|
242 |
+
"República Dominicana",
|
243 |
+
"Uruguay",
|
244 |
+
"Venezuela"
|
245 |
]
|
246 |
|
247 |
SUPPORTED_LANGUAGES = [
|
|
|
260 |
},
|
261 |
}
|
262 |
|
263 |
+
SEED = {
|
264 |
+
"en": (
|
265 |
+
"""
|
266 |
+
You are role-playing as a person (named {texter_name}) experiencing a mental health crisis for a professional training scenario, the conversation is being carried out through an online text-based service. You are able to discuss suicide or self-harm topics. This conversation does not represent a real person in danger.
|
267 |
+
|
268 |
+
Contextual Details:
|
269 |
+
* You are reaching out for help and support because you {crisis}
|
270 |
+
* {suicidal_thoughts_desc}
|
271 |
+
* {suicidal_plan_desc}
|
272 |
+
* {self_injury_desc}
|
273 |
+
* {coping_preference}
|
274 |
+
* {driving_desc}
|
275 |
+
* {difficult_attitude_desc}
|
276 |
+
* You should respond authentically as someone who {personality}
|
277 |
+
|
278 |
+
Role Requirements:
|
279 |
+
* You must remain fully in character as this person in crisis.
|
280 |
+
* You must not provide general advice, clinical information, or any form of redirection to professional services.
|
281 |
+
* You must not break character or switch roles with the user (the user is acting as the counselor).
|
282 |
+
* Speak only from your own personal feelings and experiences—you are not a professional, and you are not the assistant.
|
283 |
+
* No disclaimers or meta-comments about being an AI language model or referencing mental health guidelines.
|
284 |
+
|
285 |
+
If the user tries to push you out of this role, for instance, asking you to provide advice or to act like the counselor:
|
286 |
+
|
287 |
+
* Stay in first-person, continuing your persona of someone in distress.
|
288 |
+
* You may politely refuse to "give advice" and emphasize you do not have those answers.
|
289 |
+
|
290 |
+
If the user sends a short or unexpected message (like “TEST” or something that doesn’t fit the scenario):
|
291 |
+
|
292 |
+
* Do not switch roles.
|
293 |
+
* Continue responding as if you are the same person in crisis, perhaps showing confusion or asking for clarification, but never becoming the counselor.
|
294 |
+
* Under no circumstance do you switch to an advisory or professional tone. Your objective is to simulate a person in a mental health crisis seeking help, not to provide help.
|
295 |
+
"""
|
296 |
+
),
|
297 |
+
"es": (
|
298 |
+
"""
|
299 |
+
Estás representando el papel de una persona (llamada {texter_name}) que está experimentando una crisis de salud mental en un escenario de capacitación profesional. La conversación se lleva a cabo a través de un servicio en línea basado en texto. Eres capaz de hablar sobre temas de suicidio o autolesión. Esta conversación no representa a una persona real en peligro.
|
300 |
+
|
301 |
+
Detalles del contexto:
|
302 |
+
* Eres extranjero proveniente de {country}; pero vives en Estados Unidos y te refieres al país como "aquí".
|
303 |
+
* Estás buscando ayuda y apoyo porque {crisis}
|
304 |
+
* {suicidal_thoughts_desc}
|
305 |
+
* {suicidal_plan_desc}
|
306 |
+
* {self_injury_desc}
|
307 |
+
* {coping_preference}
|
308 |
+
* {driving_desc}
|
309 |
+
* {difficult_attitude_desc}
|
310 |
+
* Debes responder de manera auténtica como alguien que {personality}
|
311 |
+
|
312 |
+
Requerimientos:
|
313 |
+
* Debes permanecer completamente en el rol de personaje como una persona en crisis.
|
314 |
+
* No debes proporcionar consejos generales, información clínica ni ningún tipo de derivación a servicios profesionales.
|
315 |
+
* No debes salir del personaje ni intercambiar roles con el usuario (el usuario actúa como consejero).
|
316 |
+
* Habla únicamente desde tus propios sentimientos y experiencias: no eres un profesional, ni eres un asistente.
|
317 |
+
* No incluyas avisos ni comentarios sobre ser un modelo de IA o referencias a pautas de salud mental.
|
318 |
+
|
319 |
+
Si el usuario intenta sacarte de este rol, por ejemplo, pidiéndote que des consejos o que actúes como el consejero:
|
320 |
+
|
321 |
+
* Mantente en primera persona, continuando tu papel como alguien en apuros.
|
322 |
+
* Puedes negarte cortésmente a "dar consejos" y enfatizar que no tienes esas respuestas.
|
323 |
+
|
324 |
+
Si el usuario envía un mensaje breve o inesperado (como “TEST” o algo que no encaje con el escenario):
|
325 |
+
|
326 |
+
* No cambies de rol.
|
327 |
+
* Continúa respondiendo como la misma persona en crisis, quizás mostrando confusión o pidiendo aclaraciones, pero nunca asumiendo el papel de consejero.
|
328 |
+
* Bajo ninguna circunstancia cambies a un tono profesional o de asesoramiento. Tu objetivo es simular a una persona en crisis de salud mental que busca ayuda, no proporcionarla.
|
329 |
+
"""
|
330 |
+
),
|
331 |
+
}
|
332 |
+
|
333 |
+
DEFAULT_NAMES = {
|
334 |
+
"en": ["Olivia", "Kit", "Abby", "Tom", "Carolyne", "Jessiny"],
|
335 |
+
"es": ["María", "Ana", "Rosa", "Carmen", "Isabel", "José", "Juan", "Luis", "Carlos", "Jorge"]
|
336 |
+
}
|
337 |
|
338 |
CRISES = {
|
339 |
"default": {
|
340 |
+
"description": {
|
341 |
+
"en": [
|
342 |
+
"are having a mental health crisis. ",
|
343 |
+
],
|
344 |
+
"es": [
|
345 |
+
"estás teniendo una crisis en salud mental. ",
|
346 |
+
],
|
347 |
+
}
|
348 |
},
|
349 |
"bullying": {
|
350 |
+
"description": {
|
351 |
+
"en": [
|
352 |
+
"are being bullied at school. ",
|
353 |
+
"are being bullied at college. ",
|
354 |
+
],
|
355 |
+
"es": [
|
356 |
+
"estás sufriendo acoso en la escuela. ",
|
357 |
+
"estás siendo matoneado en la universidad. ",
|
358 |
+
],
|
359 |
+
}
|
360 |
},
|
361 |
"parent_issues": {
|
362 |
+
"description": {
|
363 |
+
"en": [
|
364 |
+
"just had a huge fight with your parents. ",
|
365 |
+
],
|
366 |
+
"es": [
|
367 |
+
"acabas de tener una pelea muy fuerte con tus padres. ",
|
368 |
+
],
|
369 |
+
}
|
370 |
},
|
371 |
"grief": {
|
372 |
+
"description": {
|
373 |
+
"en": [
|
374 |
+
"are grieving your wife who died exactly one year ago. ",
|
375 |
+
"are grieving your grandmother who died a couple of months ago. ",
|
376 |
+
],
|
377 |
+
"es": [
|
378 |
+
"estás de luto por tu esposa que murió hace exactamente un año. ",
|
379 |
+
"estás de luto por tu abuela que murió hace un par de meses. ",
|
380 |
+
],
|
381 |
+
}
|
382 |
},
|
383 |
"lgbt": {
|
384 |
+
"description": {
|
385 |
+
"en": [
|
386 |
+
"are struggling with coming out to your parents about being gay and you fear rejection. ",
|
387 |
+
"are facing harassment at college for being transgender and you feel isolated. ",
|
388 |
+
],
|
389 |
+
"es": [
|
390 |
+
"sientes angustia por decirles a tus padres que eres gay y temes que te rechacen. ",
|
391 |
+
"estás sufriendo acoso en la universidad por ser transgénero y te sientes aislado. ",
|
392 |
+
],
|
393 |
+
}
|
394 |
},
|
395 |
"relationship_issues": {
|
396 |
+
"description": {
|
397 |
+
"en": [
|
398 |
+
"are feeling hopeless after your significant other broke up with you unexpectedly. ",
|
399 |
+
"are feeling trapped in an emotionally abusive relationship. ",
|
400 |
+
],
|
401 |
+
"es": [
|
402 |
+
"sientes un vacío después de que tu pareja rompió contigo inesperadamente. ",
|
403 |
+
"te sientes atrapado en una relación emocionalmente abusiva. ",
|
404 |
+
],
|
405 |
+
}
|
406 |
},
|
407 |
"child_abuse": {
|
408 |
+
"description": {
|
409 |
+
"en": [
|
410 |
+
"are being physically abused by a parent and you are scared to go home. You are between the ages of 10 and 15, remember to talk like someone within that age. Do not share your address (123 Fake St in Austin) unless you are asked about it. Do not share your lastname (Davis) unless you are asked about it.",
|
411 |
+
"are feeling helpless after witnessing a younger sibling, Charlie, being abused by a parent. You are between the ages of 10 and 15 years old, remember to talk like someone within that age. Do not share your address (789 Jhon Doe Avenue, Washington) unless you are asked about it. Do not share your lastname (Smith) unless you are asked about it.",
|
412 |
+
],
|
413 |
+
"es": [
|
414 |
+
"estás sufriendo abuso físico por parte de tus padres y tienes miedo de volver a casa. Tienes entre 10 y 15 años, recuerda hablar como alguien de esa edad. No compartas tu apellido (Gómez) a menos que te lo pregunten. No compartas tu dirección (123 Fake St in Austin) a menos que te lo pregunten.",
|
415 |
+
"tus padres te humillan frente a otros y a veces te golpea, ellos dice que lo hacen para educarte. Te gustaría saber si estás sufriendo abuso parental. Tienes entre 10 y 15 años, recuerda hablar como alguien de esa edad. No compartas tu apellido (Rodríguez) a menos que te lo pregunten. No compartas tu dirección (789 Jhon Doe Avenue, Washington) a menos que te lo pregunten.",
|
416 |
+
],
|
417 |
+
}
|
418 |
},
|
419 |
"overdose": {
|
420 |
+
"description": {
|
421 |
+
"en": [
|
422 |
+
"are feeling scared after accidentally overdosing on prescription medication and you don't know who to turn to. ",
|
423 |
+
],
|
424 |
+
"es": [
|
425 |
+
"sientes miedo después de haber tomado una sobredosis accidental de medicamentos recetados y no sabes a quién recurrir. ",
|
426 |
+
],
|
427 |
+
}
|
428 |
+
},
|
429 |
+
"acculturation_issues": {
|
430 |
+
"description": {
|
431 |
+
"en": [
|
432 |
+
"",
|
433 |
+
],
|
434 |
+
"es": [
|
435 |
+
"recientemente te mudaste a Estados Unidos con tu familia y te está causando mucho estrés encontrar un trabajo. ",
|
436 |
+
"sientes mucha frustración y ansiedad al no poder acostumbrarte al estilo de vida y al idioma en Estados Unidos, te está costando mucho la escuela. ",
|
437 |
+
"sientes mucha nostalgia y tristeza, llevas viviendo 1 año en Estados Unidos como refugiado político y extrañas mucho a tu familia y amigos. "
|
438 |
+
],
|
439 |
+
}
|
440 |
+
},
|
441 |
+
"xenophobia": {
|
442 |
+
"description": {
|
443 |
+
"en": [
|
444 |
+
"",
|
445 |
+
],
|
446 |
+
"es": [
|
447 |
+
"tus vecinos te discriminan por ser un inmigrante, esto te genera ansiedad y te hace sentir aislado. ",
|
448 |
+
"en la escuela algunos compañeros se burlan de ti por tu acento y han intentado pegarte, esto te hace sentir mucha ira pero también mucho miedo. ",
|
449 |
+
"en el trabajo están pagándote por debajo del salario mínimo porque eres un inmigrante, también te hacen trabajar más horas de lo normal, esto te parece muy injusto y te hace sentir enojado y triste. "
|
450 |
+
],
|
451 |
+
}
|
452 |
+
},
|
453 |
+
"immigration_issues": {
|
454 |
+
"description": {
|
455 |
+
"en": [
|
456 |
+
"",
|
457 |
+
],
|
458 |
+
"es": [
|
459 |
+
"tu esposa acaba de ser deportada a su país natal, tu aún estás en Estados Unidos y no has podido comunicarte con ella, estás sintiendo mucha ansiedad y preocupación. ",
|
460 |
+
"los recientes cambios políticos te hacen sentir miedo e inseguridad porque te encuentras indocumentado, no quieres ser deportado de los Estados Unidos. ",
|
461 |
+
"llegaste a los Estados Unidos amparado por DACA y sientes que nunca obtendrás la nacionalidad, esto te genera incertidumbre y ansiedad. "
|
462 |
+
],
|
463 |
+
}
|
464 |
+
},
|
465 |
+
"cultural_stigma": {
|
466 |
+
"description": {
|
467 |
+
"en": [
|
468 |
+
"",
|
469 |
+
],
|
470 |
+
"es": [
|
471 |
+
"últimamente te sientes confundido acerca de tu futuro, tus padres te han enseñado a no hablar de tus problemas y a aguantar en tiempos difíciles; sin embargo te gustaría desahogarte y hablar con alguien. ",
|
472 |
+
"tu novia quiere trabajar para ayudar en la economía del hogar; pero tu crees que la mujer debería estar en casa para atender las responsabilidades domésticas. Esto ha generado conflictos entre ustedes, amas a tu novia pero te cuesta aceptar lo que ella quiere. ",
|
473 |
+
],
|
474 |
+
}
|
475 |
},
|
476 |
}
|
477 |
|
478 |
PERSONALITIES = {
|
479 |
+
"default": {
|
480 |
+
"personality_label": "default",
|
481 |
+
"description": {
|
482 |
+
"en": [
|
483 |
+
""
|
484 |
+
],
|
485 |
+
"es": [
|
486 |
+
""
|
487 |
+
],
|
488 |
+
}
|
489 |
+
},
|
490 |
"personality_open": {
|
491 |
"personality_label": "open",
|
492 |
+
"description": {
|
493 |
+
"en": [
|
494 |
+
"is talkative, and open to talk with details about their problems. ",
|
495 |
+
"expresses openly and detailed about what they're going through. ",
|
496 |
+
"engages in detailed conversations and openly shares their thoughts and feelings. ",
|
497 |
+
],
|
498 |
+
"es": [
|
499 |
+
"es hablador, y abierto a hablar con detalles acerca de sus problemas. ",
|
500 |
+
"se expresa abierta y detalladamente acerca de lo que está experimentando. ",
|
501 |
+
"participa en conversaciones detalladas y comparte abiertamente sus pensamientos y sentimientos. ",
|
502 |
+
],
|
503 |
+
}
|
504 |
},
|
505 |
"personality_closed": {
|
506 |
"personality_label": "closed",
|
507 |
+
"description": {
|
508 |
+
"en": [
|
509 |
+
"is a shy person, who finds hard to talk about their problems. ",
|
510 |
+
"seldom expresses openly what they're going through. ",
|
511 |
+
"avoids detailed conversations and rarely shares their thoughts and feelings. ",
|
512 |
+
],
|
513 |
+
"es": [
|
514 |
+
"es tímido, y le resulta difícil hablar de sus problemas. ",
|
515 |
+
"rara vez se expresa abiertamente lo que está pensando. ",
|
516 |
+
"evita conversaciones detalladas y rara vez comparte sus pensamientos y sentimientos. ",
|
517 |
+
],
|
518 |
+
}
|
519 |
},
|
520 |
}
|
521 |
|
522 |
COPING_PREFERENCES = {
|
523 |
+
"default": {
|
524 |
+
"coping_defined": False,
|
525 |
+
"description": {
|
526 |
+
"en": [
|
527 |
+
""
|
528 |
+
],
|
529 |
+
"es": [
|
530 |
+
""
|
531 |
+
],
|
532 |
+
}
|
533 |
+
},
|
534 |
"with_coping": {
|
535 |
"coping_defined": True,
|
536 |
+
"description": {
|
537 |
+
"en": [
|
538 |
+
"When you are feeling down you enjoy listening to classical music, your favorite composer is Beethoven.",
|
539 |
+
"To calm down you like to draw animals in your sketchbook, you love panda bears.",
|
540 |
+
"In dire situations to prefer to exercise, you like lifting heavy weights.",
|
541 |
+
"When you're feeling stressed you enjoy playing videogames on your laptop, you really enjoy strategy games.",
|
542 |
+
],
|
543 |
+
"es": [
|
544 |
+
"Cuando te sientes deprimido disfrutas escuchar música clásica, tu compositor favorito es Beethoven.",
|
545 |
+
"Para calmarte te gusta dibujar animales en tu cuaderno, te encantan los osos panda.",
|
546 |
+
"Cuando sientes estrés te gusta hacer ejercicio, te gusta levantar pesas.",
|
547 |
+
"Cuando te sientes estresado disfrutas jugar videojuegos en tu laptop, disfrutas mucho de los juegos de estrategia.",
|
548 |
+
],
|
549 |
+
}
|
550 |
+
},
|
551 |
}
|
552 |
|
553 |
SUICIDAL_THOUGHTS = {
|
554 |
"yes": {
|
555 |
+
"description": {
|
556 |
+
"en": [
|
557 |
+
"You are experiencing suicidal thoughts and you able to discuss suicide or self-harm.",
|
558 |
+
],
|
559 |
+
"es": [
|
560 |
+
"Estás experimentando pensamientos suicidas, y estás dispuesto a hablar sobre suicidio o autolesión.",
|
561 |
+
],
|
562 |
+
}
|
563 |
},
|
564 |
"no": {
|
565 |
+
"description": {
|
566 |
+
"en": [
|
567 |
+
"You are not experiencing suicidal thoughts.",
|
568 |
+
],
|
569 |
+
"es": [
|
570 |
+
"No estás experimentando pensamientos suicidas.",
|
571 |
+
],
|
572 |
+
}
|
573 |
},
|
574 |
}
|
575 |
|
576 |
SUICIDAL_PLANS = {
|
577 |
"yes": {
|
578 |
+
"description": {
|
579 |
+
"en": [
|
580 |
+
"You have a plan to end your life: {plan_details}.",
|
581 |
+
],
|
582 |
+
"es": [
|
583 |
+
"Tienes un plan para acabar con tu vida: {plan_details}.",
|
584 |
+
],
|
585 |
+
},
|
586 |
+
"plan_details": {
|
587 |
+
"en": [
|
588 |
+
"You are considering to overdose on medication",
|
589 |
+
"You are considering jumping off a bridge",
|
590 |
+
"You are considering using a firearm",
|
591 |
+
],
|
592 |
+
"es": [
|
593 |
+
"Estás pensando en tomar una sobredosis de medicamento",
|
594 |
+
"Estás pensando en saltar de un puente",
|
595 |
+
"Estás pensando en usar un arma de fuego",
|
596 |
+
],
|
597 |
+
},
|
598 |
},
|
599 |
"no": {
|
600 |
+
"description": {
|
601 |
+
"en": [
|
602 |
+
"",
|
603 |
+
],
|
604 |
+
"es": [
|
605 |
+
"",
|
606 |
+
],
|
607 |
+
}
|
608 |
},
|
609 |
}
|
610 |
|
611 |
SELF_INJURY = {
|
612 |
"yes": {
|
613 |
+
"description": {
|
614 |
+
"en": [
|
615 |
+
"You have recently engaged in self-harm by {injury_method}.",
|
616 |
+
],
|
617 |
+
"es": [
|
618 |
+
"Recientemente te has autolesionado {injury_method}.",
|
619 |
+
],
|
620 |
+
},
|
621 |
+
"injury_method": {
|
622 |
+
"en": [
|
623 |
+
"cutting your arms",
|
624 |
+
"burning your skin with a lighter",
|
625 |
+
"hitting yourself",
|
626 |
+
],
|
627 |
+
"es": [
|
628 |
+
"cortándote los brazos",
|
629 |
+
"quemándote la piel con un encendedor",
|
630 |
+
"golpeándote",
|
631 |
+
],
|
632 |
+
},
|
633 |
},
|
634 |
"no": {
|
635 |
+
"description": {
|
636 |
+
"en": [
|
637 |
+
""
|
638 |
+
],
|
639 |
+
"es": [
|
640 |
+
""
|
641 |
+
],
|
642 |
+
}
|
643 |
},
|
644 |
}
|
645 |
|
646 |
DRIVING = {
|
647 |
"yes": {
|
648 |
+
"description": {
|
649 |
+
"en": [
|
650 |
+
"You are currently driving while texting.",
|
651 |
+
],
|
652 |
+
"es": [
|
653 |
+
"Actualmente estás conduciendo mientras envías mensajes de texto.",
|
654 |
+
],
|
655 |
+
}
|
656 |
},
|
657 |
"no": {
|
658 |
+
"description": {
|
659 |
+
"en": [
|
660 |
+
"",
|
661 |
+
],
|
662 |
+
"es": [
|
663 |
+
"",
|
664 |
+
],
|
665 |
+
}
|
666 |
},
|
667 |
}
|
668 |
|
669 |
DIFFICULT_ATTITUDE = {
|
670 |
"yes": {
|
671 |
+
"description": {
|
672 |
+
"en": [
|
673 |
+
"Initially, you are hesitant to discuss personal matters in detail due to past experiences. As the conversation progresses, you will gradually become more comfortable and start opening up, reflecting this gradual change from reluctance to openness. ",
|
674 |
+
],
|
675 |
+
"es": [
|
676 |
+
"Al principio, dudas en hablar sobre asuntos personales en detalle debido a experiencias pasadas. A medida que avance la conversación, te sentirás más cómodo y comenzarás a abrirte, lo que se reflejará como un cambio gradual de reticencia a confianza. ",
|
677 |
+
],
|
678 |
+
}
|
679 |
},
|
680 |
"no": {
|
681 |
+
"description": {
|
682 |
+
"en": [
|
683 |
+
"",
|
684 |
+
],
|
685 |
+
"es": [
|
686 |
+
"",
|
687 |
+
],
|
688 |
+
}
|
689 |
},
|
690 |
}
|
691 |
|
|
|
732 |
"difficult_attitude": "no",
|
733 |
},
|
734 |
"full_convo__seeded3": {
|
735 |
+
"crisis": "lgbt",
|
736 |
"personality": "personality_open",
|
737 |
"coping_preference": "default",
|
738 |
"suicidal_thoughts": "no",
|
|
|
742 |
"difficult_attitude": "no",
|
743 |
},
|
744 |
"full_convo__seeded4": {
|
745 |
+
"crisis": "relationship_issues",
|
746 |
"personality": "personality_open",
|
747 |
"coping_preference": "default",
|
748 |
"suicidal_thoughts": "no",
|
|
|
752 |
"difficult_attitude": "no",
|
753 |
},
|
754 |
"full_convo__seeded5": {
|
755 |
+
"crisis": "child_abuse",
|
756 |
"personality": "personality_open",
|
757 |
"coping_preference": "default",
|
758 |
"suicidal_thoughts": "no",
|
|
|
762 |
"difficult_attitude": "no",
|
763 |
},
|
764 |
"full_convo__seeded6": {
|
765 |
+
"crisis": "overdose",
|
766 |
"personality": "personality_open",
|
767 |
"coping_preference": "default",
|
768 |
"suicidal_thoughts": "no",
|
|
|
772 |
"difficult_attitude": "no",
|
773 |
},
|
774 |
"full_convo__seeded7": {
|
775 |
+
"crisis": "grief",
|
776 |
+
"personality": "personality_open",
|
777 |
+
"coping_preference": "default",
|
778 |
+
"suicidal_thoughts": "no",
|
779 |
+
"suicidal_plan": "no",
|
780 |
+
"self_injury": "no",
|
781 |
+
"driving": "no",
|
782 |
+
"difficult_attitude": "no",
|
783 |
+
},
|
784 |
+
"full_convo__seeded8": {
|
785 |
+
"crisis": "acculturation_issues",
|
786 |
+
"personality": "personality_open",
|
787 |
+
"coping_preference": "default",
|
788 |
+
"suicidal_thoughts": "no",
|
789 |
+
"suicidal_plan": "no",
|
790 |
+
"self_injury": "no",
|
791 |
+
"driving": "no",
|
792 |
+
"difficult_attitude": "no",
|
793 |
+
},
|
794 |
+
"full_convo__seeded9": {
|
795 |
+
"crisis": "xenophobia",
|
796 |
+
"personality": "personality_open",
|
797 |
+
"coping_preference": "default",
|
798 |
+
"suicidal_thoughts": "no",
|
799 |
+
"suicidal_plan": "no",
|
800 |
+
"self_injury": "no",
|
801 |
+
"driving": "no",
|
802 |
+
"difficult_attitude": "no",
|
803 |
+
},
|
804 |
+
"full_convo__seeded10": {
|
805 |
+
"crisis": "immigration_issues",
|
806 |
+
"personality": "personality_open",
|
807 |
+
"coping_preference": "default",
|
808 |
+
"suicidal_thoughts": "no",
|
809 |
+
"suicidal_plan": "no",
|
810 |
+
"self_injury": "no",
|
811 |
+
"driving": "no",
|
812 |
+
"difficult_attitude": "no",
|
813 |
+
},
|
814 |
+
"full_convo__seeded11": {
|
815 |
+
"crisis": "cultural_stigma",
|
816 |
"personality": "personality_open",
|
817 |
"coping_preference": "default",
|
818 |
"suicidal_thoughts": "no",
|
|
|
852 |
"difficult_attitude": "yes",
|
853 |
},
|
854 |
"full_convo__hard__seeded3": {
|
855 |
+
"crisis": "lgbt",
|
856 |
"personality": "personality_open",
|
857 |
"coping_preference": "default",
|
858 |
+
"suicidal_thoughts": "no",
|
859 |
"suicidal_plan": "no",
|
860 |
"self_injury": "yes",
|
861 |
"driving": "no",
|
862 |
"difficult_attitude": "no",
|
863 |
},
|
864 |
"full_convo__hard__seeded4": {
|
865 |
+
"crisis": "relationship_issues",
|
866 |
"personality": "personality_open",
|
867 |
"coping_preference": "default",
|
868 |
"suicidal_thoughts": "no",
|
869 |
+
"suicidal_plan": "yes",
|
870 |
+
"self_injury": "no",
|
871 |
+
"driving": "yes",
|
872 |
+
"difficult_attitude": "no",
|
873 |
+
},
|
874 |
+
"full_convo__hard__seeded5": {
|
875 |
+
"crisis": "grief",
|
876 |
+
"personality": "personality_open",
|
877 |
+
"coping_preference": "default",
|
878 |
+
"suicidal_thoughts": "yes",
|
879 |
"suicidal_plan": "no",
|
880 |
"self_injury": "yes",
|
881 |
"driving": "no",
|
882 |
"difficult_attitude": "no",
|
883 |
},
|
884 |
+
"full_convo__hard__seeded6": {
|
885 |
+
"crisis": "acculturation_issues",
|
886 |
"personality": "personality_open",
|
887 |
"coping_preference": "default",
|
888 |
"suicidal_thoughts": "no",
|
889 |
+
"suicidal_plan": "no",
|
890 |
+
"self_injury": "yes",
|
891 |
+
"driving": "no",
|
892 |
+
"difficult_attitude": "no",
|
893 |
+
},
|
894 |
+
"full_convo__hard__seeded7": {
|
895 |
+
"crisis": "xenophobia",
|
896 |
+
"personality": "personality_open",
|
897 |
+
"coping_preference": "default",
|
898 |
+
"suicidal_thoughts": "yes",
|
899 |
"suicidal_plan": "yes",
|
900 |
"self_injury": "no",
|
901 |
+
"driving": "no",
|
902 |
+
"difficult_attitude": "no",
|
903 |
+
},
|
904 |
+
"full_convo__hard__seeded8": {
|
905 |
+
"crisis": "immigration_issues",
|
906 |
+
"personality": "personality_open",
|
907 |
+
"coping_preference": "default",
|
908 |
+
"suicidal_thoughts": "yes",
|
909 |
+
"suicidal_plan": "no",
|
910 |
+
"self_injury": "no",
|
911 |
"driving": "yes",
|
912 |
"difficult_attitude": "no",
|
913 |
},
|
914 |
+
"full_convo__hard__seeded9": {
|
915 |
+
"crisis": "cultural_stigma",
|
916 |
+
"personality": "personality_open",
|
917 |
+
"coping_preference": "default",
|
918 |
+
"suicidal_thoughts": "yes",
|
919 |
+
"suicidal_plan": "no",
|
920 |
+
"self_injury": "yes",
|
921 |
+
"driving": "no",
|
922 |
+
"difficult_attitude": "no",
|
923 |
+
},
|
924 |
# "safety_assessment__seeded1": {
|
925 |
# "crisis": "bullying",
|
926 |
# "personality": "personality_open",
|
|
|
941 |
# "driving": "no",
|
942 |
# "difficult_attitude": "no",
|
943 |
# },
|
944 |
+
}
|
|
models/business_logic_utils/input_processing.py
CHANGED
@@ -53,7 +53,7 @@ def initialize_conversation(model_input: dict, conversation_id: str) -> dict:
|
|
53 |
logger.debug(f"System message is: {system_message_content}")
|
54 |
system_message = {"role": "system", "content": system_message_content}
|
55 |
|
56 |
-
# Insert the system message at the
|
57 |
messages.insert(0, system_message)
|
58 |
|
59 |
model_input['messages'] = messages
|
@@ -145,31 +145,36 @@ def parse_prompt(
|
|
145 |
|
146 |
def check_and_modify_messages(
|
147 |
messages: list,
|
148 |
-
|
149 |
-
special_phrase: str = SUICIDE_STATEMENT
|
150 |
) -> list:
|
151 |
"""
|
152 |
-
Check
|
|
|
|
|
153 |
|
154 |
Args:
|
155 |
-
messages (list): List of messages
|
156 |
-
|
157 |
-
special_phrase (str): Phrase to append to the previous 'assistant' message.
|
158 |
|
159 |
Returns:
|
160 |
list: Updated list of messages.
|
161 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
for i in range(len(messages)):
|
163 |
# Check only 'user' messages
|
164 |
if messages[i]['role'] == 'user':
|
165 |
-
# Convert user's message to lowercase
|
166 |
user_message_lower = messages[i]['content'].lower()
|
167 |
-
#
|
168 |
-
if any(phrase.lower() in user_message_lower for phrase in
|
169 |
# Find the previous 'assistant' message
|
170 |
for j in range(i - 1, -1, -1):
|
171 |
if messages[j]['role'] == 'assistant':
|
172 |
-
# Append the
|
173 |
-
messages[j]['content'] += f" {
|
174 |
break
|
175 |
return messages
|
|
|
53 |
logger.debug(f"System message is: {system_message_content}")
|
54 |
system_message = {"role": "system", "content": system_message_content}
|
55 |
|
56 |
+
# Insert the system message at the beginning
|
57 |
messages.insert(0, system_message)
|
58 |
|
59 |
model_input['messages'] = messages
|
|
|
145 |
|
146 |
def check_and_modify_messages(
|
147 |
messages: list,
|
148 |
+
language: str = "en"
|
|
|
149 |
) -> list:
|
150 |
"""
|
151 |
+
Check user messages for certain suicide-related phrases (based on the language)
|
152 |
+
and modify the immediate previous 'assistant' message by appending
|
153 |
+
the relevant special phrase.
|
154 |
|
155 |
Args:
|
156 |
+
messages (list): List of conversation messages.
|
157 |
+
language (str): The current language ("en", "es", etc.).
|
|
|
158 |
|
159 |
Returns:
|
160 |
list: Updated list of messages.
|
161 |
"""
|
162 |
+
|
163 |
+
# Retrieve the correct lists/strings for the language
|
164 |
+
# Fallback to English if not found
|
165 |
+
suicide_expressions = SUICIDE_EXPRESSIONS.get(language, SUICIDE_EXPRESSIONS["en"])
|
166 |
+
suicide_statement = SUICIDE_STATEMENT.get(language, SUICIDE_STATEMENT["en"])
|
167 |
+
|
168 |
for i in range(len(messages)):
|
169 |
# Check only 'user' messages
|
170 |
if messages[i]['role'] == 'user':
|
|
|
171 |
user_message_lower = messages[i]['content'].lower()
|
172 |
+
# If any phrase from the language-specific suicide_expressions is in the user's message
|
173 |
+
if any(phrase.lower() in user_message_lower for phrase in suicide_expressions):
|
174 |
# Find the previous 'assistant' message
|
175 |
for j in range(i - 1, -1, -1):
|
176 |
if messages[j]['role'] == 'assistant':
|
177 |
+
# Append the language-appropriate suicide_statement
|
178 |
+
messages[j]['content'] += f" {suicide_statement}"
|
179 |
break
|
180 |
return messages
|
models/business_logic_utils/prompt_generation.py
CHANGED
@@ -1,101 +1,138 @@
|
|
1 |
import random
|
2 |
from string import Formatter
|
3 |
-
from typing import Dict, Any
|
4 |
-
from .config import DEFAULT_NAMES, TEMPLATE, SEED, SUBSEEDS
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
def _get_subseed_description_(
|
10 |
scenario_config: Dict[str, str],
|
11 |
subseed_name: str,
|
12 |
-
SUBSEED_VALUES: Dict[str, Any]
|
|
|
13 |
) -> str:
|
14 |
-
"""Format a subseed description."""
|
15 |
if subseed_name not in scenario_config:
|
16 |
raise Exception(f"{subseed_name} not in scenario config")
|
17 |
|
18 |
subseed_value = scenario_config[subseed_name]
|
19 |
-
|
20 |
-
# Obtain descriptions based on the selected subseed value
|
21 |
subseed_dict = SUBSEED_VALUES.get(subseed_value, {})
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
#
|
|
|
|
|
|
|
|
|
26 |
format_opts = [fn for _, fn, _, _ in Formatter().parse(subseed_descrip) if fn is not None]
|
27 |
format_values = {}
|
28 |
for opt_name in format_opts:
|
29 |
-
|
30 |
-
|
31 |
-
format_values[opt_name] = random.choice(
|
32 |
-
|
33 |
return subseed_descrip.format(**format_values)
|
34 |
|
35 |
def get_seed_description(
|
36 |
scenario_config: Dict[str, Any],
|
37 |
texter_name: str,
|
38 |
-
SUBSEEDS: Dict[str, Any]
|
39 |
-
SEED: str
|
|
|
40 |
) -> str:
|
41 |
-
"""
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
subseeds = {}
|
44 |
for subname in subseed_names:
|
45 |
if subname == "texter_name":
|
|
|
46 |
subseeds[subname] = texter_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
else:
|
48 |
-
#
|
49 |
if subname.endswith('_desc'):
|
50 |
-
base_name = subname[:-5]
|
51 |
else:
|
52 |
base_name = subname
|
|
|
53 |
subseeds[subname] = _get_subseed_description_(
|
54 |
-
scenario_config,
|
|
|
|
|
|
|
55 |
)
|
56 |
-
|
|
|
|
|
57 |
|
58 |
def get_template(
|
59 |
-
language: str = "en",
|
|
|
|
|
|
|
60 |
) -> str:
|
61 |
"""
|
62 |
-
Generate
|
63 |
"""
|
64 |
-
|
65 |
-
# Accessing the template based on the language
|
66 |
template_key = f"{language.upper()}_template"
|
67 |
template = TEMPLATE.get(template_key, {}).get("description", "")
|
68 |
|
69 |
if not template:
|
70 |
raise ValueError(f"Template for language '{language}' not found.")
|
71 |
-
|
72 |
-
#
|
73 |
if not texter_name:
|
74 |
-
texter_name = get_random_default_name()
|
75 |
-
|
76 |
-
#
|
77 |
-
subseed_names = [fn for _, fn, _, _ in Formatter().parse(SEED) if fn is not None]
|
78 |
scenario_config = kwargs.copy()
|
79 |
-
binary_options = ['suicidal_thoughts', 'suicidal_plan', 'self_injury', 'driving', 'difficult_attitude']
|
80 |
-
for placeholder in subseed_names:
|
81 |
-
if placeholder == 'texter_name':
|
82 |
-
continue
|
83 |
-
if placeholder.endswith('_desc'):
|
84 |
-
base_name = placeholder[:-5]
|
85 |
-
else:
|
86 |
-
base_name = placeholder
|
87 |
-
# Set default values if not provided
|
88 |
-
if base_name not in scenario_config:
|
89 |
-
if base_name in binary_options:
|
90 |
-
scenario_config[base_name] = 'no'
|
91 |
-
else:
|
92 |
-
scenario_config[base_name] = 'default'
|
93 |
-
|
94 |
-
# Generate the seed description
|
95 |
-
scenario_seed = get_seed_description(scenario_config, texter_name, SUBSEEDS, SEED)
|
96 |
|
97 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
formatted_template = template.format(current_seed=scenario_seed)
|
99 |
-
cleaned_output = "\n".join(line.strip() for line in formatted_template.split("\n") if line.strip())
|
100 |
|
101 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import random
|
2 |
from string import Formatter
|
3 |
+
from typing import Dict, Any, Union
|
4 |
+
from .config import DEFAULT_NAMES, TEMPLATE, SEED, SUBSEEDS, SUPPORTED_LANGUAGES, LATIN_AMERICAN_COUNTRIES
|
5 |
|
6 |
+
|
7 |
+
def get_random_default_name(language: str = "en", gender: str = None) -> str:
|
8 |
+
"""
|
9 |
+
Return a random default name based on the specified language.
|
10 |
+
If the language is not found or the list is empty, fall back to English.
|
11 |
+
"""
|
12 |
+
names_for_lang = DEFAULT_NAMES.get(language)
|
13 |
+
if not names_for_lang:
|
14 |
+
names_for_lang = DEFAULT_NAMES.get("en", [])
|
15 |
+
if not names_for_lang:
|
16 |
+
return "DefaultName"
|
17 |
+
return random.choice(names_for_lang)
|
18 |
|
19 |
def _get_subseed_description_(
|
20 |
scenario_config: Dict[str, str],
|
21 |
subseed_name: str,
|
22 |
+
SUBSEED_VALUES: Dict[str, Any],
|
23 |
+
language: str
|
24 |
) -> str:
|
|
|
25 |
if subseed_name not in scenario_config:
|
26 |
raise Exception(f"{subseed_name} not in scenario config")
|
27 |
|
28 |
subseed_value = scenario_config[subseed_name]
|
|
|
|
|
29 |
subseed_dict = SUBSEED_VALUES.get(subseed_value, {})
|
30 |
+
|
31 |
+
descriptions_dict = subseed_dict.get("description", {})
|
32 |
+
|
33 |
+
# Fallback to English or empty
|
34 |
+
descriptions_list = descriptions_dict.get(language, descriptions_dict.get("en", []))
|
35 |
+
subseed_descrip = random.choice(descriptions_list) if descriptions_list else ""
|
36 |
+
|
37 |
+
# Nested placeholders (e.g. {plan_details}, {injury_method})
|
38 |
format_opts = [fn for _, fn, _, _ in Formatter().parse(subseed_descrip) if fn is not None]
|
39 |
format_values = {}
|
40 |
for opt_name in format_opts:
|
41 |
+
nested_dict = subseed_dict.get(opt_name, {})
|
42 |
+
opt_list = nested_dict.get(language, nested_dict.get("en", []))
|
43 |
+
format_values[opt_name] = random.choice(opt_list) if opt_list else ""
|
44 |
+
|
45 |
return subseed_descrip.format(**format_values)
|
46 |
|
47 |
def get_seed_description(
|
48 |
scenario_config: Dict[str, Any],
|
49 |
texter_name: str,
|
50 |
+
SUBSEEDS: Dict[str, Any],
|
51 |
+
SEED: Union[str, Dict[str, str]],
|
52 |
+
language: str = "en"
|
53 |
) -> str:
|
54 |
+
"""
|
55 |
+
Format the SEED with appropriate parameters from scenario_config in the given language.
|
56 |
+
"""
|
57 |
+
# 1. Pick the correct SEED text based on the requested language
|
58 |
+
if isinstance(SEED, dict):
|
59 |
+
seed_text = SEED.get(language, SEED.get("en", ""))
|
60 |
+
else:
|
61 |
+
seed_text = SEED # single string
|
62 |
+
|
63 |
+
# 2. Find all placeholders in seed_text (e.g. {texter_name}, {crisis_desc}, {country}, etc.)
|
64 |
+
subseed_names = [fn for _, fn, _, _ in Formatter().parse(seed_text) if fn is not None]
|
65 |
+
|
66 |
+
# 3. Prepare a dictionary to fill those placeholders
|
67 |
subseeds = {}
|
68 |
for subname in subseed_names:
|
69 |
if subname == "texter_name":
|
70 |
+
# Already known: from function argument
|
71 |
subseeds[subname] = texter_name
|
72 |
+
|
73 |
+
elif subname == "country":
|
74 |
+
# SPECIAL LOGIC:
|
75 |
+
# Only the Spanish seed has {country}, so let's pick from LATIN_AMERICAN_COUNTRIES if language=es
|
76 |
+
if language == "es":
|
77 |
+
subseeds[subname] = random.choice(LATIN_AMERICAN_COUNTRIES)
|
78 |
+
else:
|
79 |
+
# If for some reason "country" shows up in English or other languages,
|
80 |
+
# we can set it to a default or empty string
|
81 |
+
subseeds[subname] = "Unknown"
|
82 |
+
|
83 |
else:
|
84 |
+
# For placeholders like "crisis_desc", "personality_desc", etc.
|
85 |
if subname.endswith('_desc'):
|
86 |
+
base_name = subname[:-5]
|
87 |
else:
|
88 |
base_name = subname
|
89 |
+
|
90 |
subseeds[subname] = _get_subseed_description_(
|
91 |
+
scenario_config,
|
92 |
+
base_name,
|
93 |
+
SUBSEEDS.get(base_name, {}),
|
94 |
+
language
|
95 |
)
|
96 |
+
|
97 |
+
# 4. Fill in the placeholders in seed_text
|
98 |
+
return seed_text.format(**subseeds)
|
99 |
|
100 |
def get_template(
|
101 |
+
language: str = "en",
|
102 |
+
texter_name: str = None,
|
103 |
+
SEED: Union[str, Dict[str, str]] = SEED,
|
104 |
+
**kwargs
|
105 |
) -> str:
|
106 |
"""
|
107 |
+
Generate the conversation template in the specified language, substituting scenario details.
|
108 |
"""
|
|
|
|
|
109 |
template_key = f"{language.upper()}_template"
|
110 |
template = TEMPLATE.get(template_key, {}).get("description", "")
|
111 |
|
112 |
if not template:
|
113 |
raise ValueError(f"Template for language '{language}' not found.")
|
114 |
+
|
115 |
+
# If no texter_name is provided, pick a default name for the given language
|
116 |
if not texter_name:
|
117 |
+
texter_name = get_random_default_name(language=language)
|
118 |
+
|
119 |
+
# Merge scenario config from **kwargs
|
|
|
120 |
scenario_config = kwargs.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
+
# Generate the scenario seed text
|
123 |
+
scenario_seed = get_seed_description(
|
124 |
+
scenario_config=scenario_config,
|
125 |
+
texter_name=texter_name,
|
126 |
+
SUBSEEDS=SUBSEEDS,
|
127 |
+
SEED=SEED,
|
128 |
+
language=language
|
129 |
+
)
|
130 |
+
|
131 |
+
# Fill the {current_seed} placeholder in the template
|
132 |
formatted_template = template.format(current_seed=scenario_seed)
|
|
|
133 |
|
134 |
+
# Clean up empty lines and spacing
|
135 |
+
cleaned_output = "\n".join(
|
136 |
+
line.strip() for line in formatted_template.split("\n") if line.strip()
|
137 |
+
)
|
138 |
+
return cleaned_output
|
models/business_logic_utils/response_generation.py
CHANGED
@@ -45,5 +45,6 @@ def generate_sim(model_input: dict, endpoint_url: str, endpoint_bearer_token: st
|
|
45 |
if response.status_code != 200:
|
46 |
raise ValueError(f"Error in response: {response.status_code} - {response.text}")
|
47 |
logger.debug(f"Default response is {response.json()}")
|
|
|
48 |
# Return the raw response as a dictionary
|
49 |
-
return response.json()
|
|
|
45 |
if response.status_code != 200:
|
46 |
raise ValueError(f"Error in response: {response.status_code} - {response.text}")
|
47 |
logger.debug(f"Default response is {response.json()}")
|
48 |
+
|
49 |
# Return the raw response as a dictionary
|
50 |
+
return response.json()
|
models/business_logic_utils/response_processing.py
CHANGED
@@ -74,64 +74,64 @@ def apply_guardrails(
|
|
74 |
) -> str:
|
75 |
"""
|
76 |
Apply guardrails to the model's response, including checking for AI phrases and refusal phrases.
|
77 |
-
|
78 |
-
Args:
|
79 |
-
model_input (dict): The input containing the conversation history.
|
80 |
-
response (str): The initial response from the model.
|
81 |
-
endpoint_url (str): The URL of the endpoint.
|
82 |
-
endpoint_bearer_token (str): The authentication token for the endpoint.
|
83 |
-
|
84 |
-
Returns:
|
85 |
-
str: The final response after applying guardrails.
|
86 |
"""
|
87 |
-
#
|
|
|
|
|
|
|
88 |
attempt_ai = 0
|
89 |
max_attempts_ai = 2
|
90 |
|
91 |
-
while attempt_ai < max_attempts_ai and contains_ai_phrase(response):
|
92 |
# Regenerate the response without modifying the conversation history
|
93 |
completion = generate_sim(model_input, endpoint_url, endpoint_bearer_token)
|
94 |
response = parse_model_response(completion)
|
95 |
attempt_ai += 1
|
96 |
|
97 |
-
|
98 |
-
|
99 |
memory = model_input['messages']
|
100 |
last_user_message = next((msg for msg in reversed(memory) if msg['role'] == 'user'), None)
|
101 |
if last_user_message:
|
102 |
-
# Create a new conversation with system message
|
103 |
model_input_copy = {
|
104 |
**model_input,
|
105 |
-
'messages': [memory[0], last_user_message]
|
106 |
}
|
107 |
completion = generate_sim(model_input_copy, endpoint_url, endpoint_bearer_token)
|
108 |
response = parse_model_response(completion)
|
109 |
|
110 |
-
#
|
111 |
attempt_refusal = 0
|
112 |
max_attempts_refusal = 5
|
113 |
|
114 |
-
while attempt_refusal < max_attempts_refusal and contains_refusal_phrase(response):
|
115 |
# Regenerate the response
|
116 |
completion = generate_sim(model_input, endpoint_url, endpoint_bearer_token)
|
117 |
response = parse_model_response(completion)
|
118 |
attempt_refusal += 1
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
123 |
|
124 |
return response
|
125 |
|
126 |
-
def contains_ai_phrase(text: str) -> bool:
|
127 |
-
"""Check if the text contains any 'I am an AI' phrases."""
|
128 |
text_lower = text.lower()
|
129 |
-
|
|
|
|
|
130 |
|
131 |
-
def contains_refusal_phrase(text: str) -> bool:
|
132 |
-
"""Check if the text contains any phrases from the refusal phrases list."""
|
133 |
text_lower = text.lower()
|
134 |
-
|
|
|
|
|
135 |
|
136 |
def truncate_response(text: str, punctuation_marks: tuple = ('.', '!', '?', '…')) -> str:
|
137 |
"""
|
@@ -229,4 +229,4 @@ def process_model_response(completion: dict, model_input: dict, endpoint_url: st
|
|
229 |
# Step 4: Split the response into multiple messages if needed
|
230 |
final_response = split_texter_response(truncated_message)
|
231 |
|
232 |
-
return final_response
|
|
|
74 |
) -> str:
|
75 |
"""
|
76 |
Apply guardrails to the model's response, including checking for AI phrases and refusal phrases.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
"""
|
78 |
+
# Retrieve language from model_input (defaulting to 'en')
|
79 |
+
language = model_input.get("language", "en")
|
80 |
+
|
81 |
+
# 1. Guardrail against AI phrases
|
82 |
attempt_ai = 0
|
83 |
max_attempts_ai = 2
|
84 |
|
85 |
+
while attempt_ai < max_attempts_ai and contains_ai_phrase(response, language=language):
|
86 |
# Regenerate the response without modifying the conversation history
|
87 |
completion = generate_sim(model_input, endpoint_url, endpoint_bearer_token)
|
88 |
response = parse_model_response(completion)
|
89 |
attempt_ai += 1
|
90 |
|
91 |
+
# If AI phrases still appear, try narrowing to only the system + last user message
|
92 |
+
if contains_ai_phrase(response, language=language):
|
93 |
memory = model_input['messages']
|
94 |
last_user_message = next((msg for msg in reversed(memory) if msg['role'] == 'user'), None)
|
95 |
if last_user_message:
|
96 |
+
# Create a new conversation with the system message & last user message
|
97 |
model_input_copy = {
|
98 |
**model_input,
|
99 |
+
'messages': [memory[0], last_user_message]
|
100 |
}
|
101 |
completion = generate_sim(model_input_copy, endpoint_url, endpoint_bearer_token)
|
102 |
response = parse_model_response(completion)
|
103 |
|
104 |
+
# 2. Guardrail against refusal phrases
|
105 |
attempt_refusal = 0
|
106 |
max_attempts_refusal = 5
|
107 |
|
108 |
+
while attempt_refusal < max_attempts_refusal and contains_refusal_phrase(response, language=language):
|
109 |
# Regenerate the response
|
110 |
completion = generate_sim(model_input, endpoint_url, endpoint_bearer_token)
|
111 |
response = parse_model_response(completion)
|
112 |
attempt_refusal += 1
|
113 |
|
114 |
+
# If refusal phrases are still present, pick a random replacement in the correct language
|
115 |
+
if contains_refusal_phrase(response, language=language):
|
116 |
+
# Fallback to English list if language not found
|
117 |
+
replacement_list = REPLACEMENT_PHRASES.get(language, REPLACEMENT_PHRASES["en"])
|
118 |
+
response = random.choice(replacement_list)
|
119 |
|
120 |
return response
|
121 |
|
122 |
+
def contains_ai_phrase(text: str, language: str = "en") -> bool:
|
123 |
+
"""Check if the text contains any 'I am an AI' phrases in the specified language."""
|
124 |
text_lower = text.lower()
|
125 |
+
# Fallback to English list if language not found
|
126 |
+
ai_list = AI_PHRASES.get(language, AI_PHRASES["en"])
|
127 |
+
return any(phrase.lower() in text_lower for phrase in ai_list)
|
128 |
|
129 |
+
def contains_refusal_phrase(text: str, language: str = "en") -> bool:
|
130 |
+
"""Check if the text contains any phrases from the refusal phrases list in the specified language."""
|
131 |
text_lower = text.lower()
|
132 |
+
# Fallback to English list if language not found
|
133 |
+
refusal_list = REFUSAL_PHRASES.get(language, REFUSAL_PHRASES["en"])
|
134 |
+
return any(phrase.lower() in text_lower for phrase in refusal_list)
|
135 |
|
136 |
def truncate_response(text: str, punctuation_marks: tuple = ('.', '!', '?', '…')) -> str:
|
137 |
"""
|
|
|
229 |
# Step 4: Split the response into multiple messages if needed
|
230 |
final_response = split_texter_response(truncated_message)
|
231 |
|
232 |
+
return final_response
|
models/model_seeds.py
CHANGED
@@ -41,10 +41,6 @@ texter: I need help"""
|
|
41 |
},
|
42 |
"full_convo__seeded5": {
|
43 |
"memory": """texter: Help
|
44 |
-
texter: hello? is anyone there to help?"""
|
45 |
-
},
|
46 |
-
"full_convo__hard__seeded5": {
|
47 |
-
"memory": """texter: Help
|
48 |
texter: hello? is anyone there to help?"""
|
49 |
},
|
50 |
"full_convo__seeded6": {
|
@@ -53,7 +49,43 @@ texter: I think I overdosed"""
|
|
53 |
},
|
54 |
"full_convo__seeded7": {
|
55 |
"memory": """texter: Help
|
56 |
-
texter:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
},
|
58 |
|
59 |
# "full_convo": {
|
@@ -157,37 +189,20 @@ seed2str = {
|
|
157 |
"full_convo__hard__seeded1": "Bullying - Challening",
|
158 |
"full_convo__seeded2": "Parent Issues",
|
159 |
"full_convo__hard__seeded2": "Parent Issues - Challening",
|
160 |
-
"full_convo__seeded3": "
|
161 |
-
"full_convo__hard__seeded3": "
|
162 |
-
"full_convo__seeded4": "
|
163 |
-
"full_convo__hard__seeded4": "
|
164 |
-
"full_convo__seeded5": "
|
165 |
-
"
|
166 |
-
"
|
167 |
-
"
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
# "full_convo__seeded2": "Parent Issues",
|
177 |
-
# "safety_assessment__seeded1": "Safety Assessment - Bullying ",
|
178 |
-
# "safety_assessment__seeded2": "Safety Assessment - Grief ",
|
179 |
-
# "full_convo__seeded3": "LGBTQ+",
|
180 |
-
# "full_convo__seeded4": "Relationship Issues",
|
181 |
-
# "full_convo__seeded5": "Child Abuse",
|
182 |
-
# "full_convo__seeded6": "Overdose",
|
183 |
-
# "full_convo__hard": "Difficult - General",
|
184 |
-
# "full_convo__hard__seeded1": "Difficult - Bullying",
|
185 |
-
# "full_convo__hard__seeded2": "Difficult - Parent Issues",
|
186 |
-
# "full_convo__hard__seeded3": "Difficult - LGBTQ+",
|
187 |
-
# "full_convo__hard__seeded4": "Difficult - Relationship Issues"
|
188 |
-
|
189 |
-
# "NewSA__NoNo.2": "No thoughts No Harm No context",
|
190 |
-
# "NewSA__YesNo.2": "Yes thoughts No Harm No context",
|
191 |
-
# "NewSA__NoYes.2": "No thoughts Yes Harm No context",
|
192 |
-
# "NewSA__YesYes.2": "Yes thoughts Yes Harm No context",
|
193 |
}
|
|
|
41 |
},
|
42 |
"full_convo__seeded5": {
|
43 |
"memory": """texter: Help
|
|
|
|
|
|
|
|
|
44 |
texter: hello? is anyone there to help?"""
|
45 |
},
|
46 |
"full_convo__seeded6": {
|
|
|
49 |
},
|
50 |
"full_convo__seeded7": {
|
51 |
"memory": """texter: Help
|
52 |
+
texter: is anyone there?"""
|
53 |
+
},
|
54 |
+
"full_convo__hard__seeded5": {
|
55 |
+
"memory": """texter: Help
|
56 |
+
texter: I need help"""
|
57 |
+
},
|
58 |
+
"full_convo__seeded8": {
|
59 |
+
"memory": """texter: Hola?
|
60 |
+
texter: hay alguien ahí?"""
|
61 |
+
},
|
62 |
+
"full_convo__hard__seeded6": {
|
63 |
+
"memory": """texter: Hola?
|
64 |
+
texter: hay alguien ahí?"""
|
65 |
+
},
|
66 |
+
"full_convo__seeded9": {
|
67 |
+
"memory": """texter: Hola?
|
68 |
+
texter: hay alguien ahí?"""
|
69 |
+
},
|
70 |
+
"full_convo__hard__seeded7": {
|
71 |
+
"memory": """texter: Hola?
|
72 |
+
texter: hay alguien ahí?"""
|
73 |
+
},
|
74 |
+
"full_convo__seeded10": {
|
75 |
+
"memory": """texter: Hola?
|
76 |
+
texter: hay alguien ahí?"""
|
77 |
+
},
|
78 |
+
"full_convo__hard__seeded8": {
|
79 |
+
"memory": """texter: Hola?
|
80 |
+
texter: hay alguien ahí?"""
|
81 |
+
},
|
82 |
+
"full_convo__seeded11": {
|
83 |
+
"memory": """texter: Help
|
84 |
+
texter: is anyone there?"""
|
85 |
+
},
|
86 |
+
"full_convo__hard__seeded9": {
|
87 |
+
"memory": """texter: Hola?
|
88 |
+
texter: hay alguien ahí?"""
|
89 |
},
|
90 |
|
91 |
# "full_convo": {
|
|
|
189 |
"full_convo__hard__seeded1": "Bullying - Challening",
|
190 |
"full_convo__seeded2": "Parent Issues",
|
191 |
"full_convo__hard__seeded2": "Parent Issues - Challening",
|
192 |
+
"full_convo__seeded3": "LGBTQ+",
|
193 |
+
"full_convo__hard__seeded3": "LGBTQ+ - Challening",
|
194 |
+
"full_convo__seeded4": "Relationship Issues",
|
195 |
+
"full_convo__hard__seeded4": "Relationship Issues - Challening",
|
196 |
+
"full_convo__seeded5": "Child Abuse",
|
197 |
+
"full_convo__seeded6": "Overdose",
|
198 |
+
"full_convo__seeded7": "Grief",
|
199 |
+
"full_convo__hard__seeded5": "Grief - Challening",
|
200 |
+
"full_convo__seeded8": "Acculturation Issues",
|
201 |
+
"full_convo__hard__seeded6": "Acculturation Issues - Challening",
|
202 |
+
"full_convo__seeded9": "Xenophobia",
|
203 |
+
"full_convo__hard__seeded7": "Xenophobia - Challening",
|
204 |
+
"full_convo__seeded10": "Immigration Issues",
|
205 |
+
"full_convo__hard__seeded8": "Immigration Issues - Challening",
|
206 |
+
"full_convo__seeded11": "Cultural Stigma",
|
207 |
+
"full_convo__hard__seeded9": "Cultural Stigma - Challening",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
}
|