app_config.py CHANGED
@@ -4,7 +4,7 @@ from models.model_seeds import seeds, seed2str
4
  ISSUES = [k for k,_ in seeds.items()]
5
  SOURCES = [
6
  "CTL_llama2",
7
- "CTL_mistral",
8
  'OA_rolemodel',
9
  # 'OA_finetuned',
10
  ]
 
4
  ISSUES = [k for k,_ in seeds.items()]
5
  SOURCES = [
6
  "CTL_llama2",
7
+ # "CTL_mistral",
8
  'OA_rolemodel',
9
  # 'OA_finetuned',
10
  ]
convosim.py CHANGED
@@ -11,7 +11,7 @@ from app_config import ISSUES, SOURCES, source2label, issue2label
11
  logger = get_logger(__name__)
12
  openai_api_key = os.environ['OPENAI_API_KEY']
13
  temperature = 0.8
14
- username = "barb-chase" #"ivnban-ctl"
15
 
16
  if "sent_messages" not in st.session_state:
17
  st.session_state['sent_messages'] = 0
@@ -21,8 +21,6 @@ if 'previous_source' not in st.session_state:
21
  st.session_state['previous_source'] = SOURCES[0]
22
  if 'db_client' not in st.session_state:
23
  st.session_state["db_client"] = get_db_client()
24
- if 'counselor_name' not in st.session_state:
25
- st.session_state["counselor_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
26
  if 'texter_name' not in st.session_state:
27
  st.session_state["texter_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
28
  logger.info(f"texter name is {st.session_state['texter_name']}")
@@ -30,7 +28,9 @@ 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='ivnban-ctl', max_chars=30)
 
 
34
  # temperature = st.slider("Temperature", 0., 1., value=0.8, step=0.1)
35
  issue = st.selectbox("Select a Scenario", ISSUES, index=0, format_func=issue2label,
36
  on_change=clear_memory, kwargs={"memories":memories, "username":username, "language":"English"}
@@ -48,10 +48,11 @@ with st.sidebar:
48
 
49
  changed_source = any([
50
  st.session_state['previous_source'] != source,
51
- st.session_state['issue'] != issue
 
52
  ])
53
  if changed_source:
54
- st.session_state["counselor_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
55
  st.session_state["texter_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
56
  st.session_state['previous_source'] = source
57
  st.session_state['issue'] = issue
@@ -64,7 +65,8 @@ create_memory_add_initial_message(memories,
64
  texter_name=st.session_state["texter_name"])
65
  st.session_state['previous_source'] = source
66
  memoryA = st.session_state[list(memories.keys())[0]]
67
- llm_chain, stopper = get_chain(issue, language, source, memoryA, temperature, texter_name=st.session_state["texter_name"])
 
68
 
69
  st.title("💬 Simulator")
70
 
 
11
  logger = get_logger(__name__)
12
  openai_api_key = os.environ['OPENAI_API_KEY']
13
  temperature = 0.8
14
+ # username = "barb-chase" #"ivnban-ctl"
15
 
16
  if "sent_messages" not in st.session_state:
17
  st.session_state['sent_messages'] = 0
 
21
  st.session_state['previous_source'] = SOURCES[0]
22
  if 'db_client' not in st.session_state:
23
  st.session_state["db_client"] = get_db_client()
 
 
24
  if 'texter_name' not in st.session_state:
25
  st.session_state["texter_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
26
  logger.info(f"texter name is {st.session_state['texter_name']}")
 
28
  memories = {'memory':{"issue": st.session_state['issue'], "source": st.session_state['previous_source']}}
29
 
30
  with st.sidebar:
31
+ username = st.text_input("Username", value='Barbara', max_chars=30)
32
+ if 'counselor_name' not in st.session_state:
33
+ st.session_state["counselor_name"] = username #get_random_name(names_df=DEFAULT_NAMES_DF)
34
  # temperature = st.slider("Temperature", 0., 1., value=0.8, step=0.1)
35
  issue = st.selectbox("Select a Scenario", ISSUES, index=0, format_func=issue2label,
36
  on_change=clear_memory, kwargs={"memories":memories, "username":username, "language":"English"}
 
48
 
49
  changed_source = any([
50
  st.session_state['previous_source'] != source,
51
+ st.session_state['issue'] != issue,
52
+ st.session_state['counselor_name'] != username,
53
  ])
54
  if changed_source:
55
+ st.session_state["counselor_name"] = username #get_random_name(names_df=DEFAULT_NAMES_DF)
56
  st.session_state["texter_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
57
  st.session_state['previous_source'] = source
58
  st.session_state['issue'] = issue
 
65
  texter_name=st.session_state["texter_name"])
66
  st.session_state['previous_source'] = source
67
  memoryA = st.session_state[list(memories.keys())[0]]
68
+ # issue only without "." marker for model compatibility
69
+ llm_chain, stopper = get_chain(issue.split(".")[0], language, source, memoryA, temperature, texter_name=st.session_state["texter_name"])
70
 
71
  st.title("💬 Simulator")
72
 
models/databricks/scenario_sim_biz.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import json
3
  import requests
4
  import logging
 
5
  from models.custom_parsers import CustomStringOutputParser
6
  from app_config import ENDPOINT_NAMES
7
  from langchain.chains import ConversationChain
@@ -11,6 +12,8 @@ from langchain.prompts import PromptTemplate
11
 
12
  from typing import Any, List, Mapping, Optional, Dict
13
 
 
 
14
  class DatabricksCustomBizLLM(LLM):
15
  issue:str
16
  language:str
@@ -49,7 +52,6 @@ helper: {input}
49
  texter:"""
50
 
51
  def get_databricks_biz_chain(source, issue, language, memory, temperature=0.8):
52
-
53
  PROMPT = PromptTemplate(
54
  input_variables=['history', 'input'],
55
  template=_DATABRICKS_TEMPLATE_
 
2
  import json
3
  import requests
4
  import logging
5
+ from streamlit.logger import get_logger
6
  from models.custom_parsers import CustomStringOutputParser
7
  from app_config import ENDPOINT_NAMES
8
  from langchain.chains import ConversationChain
 
12
 
13
  from typing import Any, List, Mapping, Optional, Dict
14
 
15
+ logger = get_logger(__name__)
16
+
17
  class DatabricksCustomBizLLM(LLM):
18
  issue:str
19
  language:str
 
52
  texter:"""
53
 
54
  def get_databricks_biz_chain(source, issue, language, memory, temperature=0.8):
 
55
  PROMPT = PromptTemplate(
56
  input_variables=['history', 'input'],
57
  template=_DATABRICKS_TEMPLATE_
models/model_seeds.py CHANGED
@@ -1,4 +1,103 @@
1
  seeds = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  # "GCT__relationship": {
3
  # "prompt": "Your character is having a hard time becuase a failed relationship.",
4
  # "memory": "texter: Hi, I don't know what to do",
@@ -15,33 +114,33 @@ seeds = {
15
  # "prompt": "Your character is experiencing an anxiety crisis.",
16
  # "memory": "texter: help!\ntexter: I'm feeling overwhelmed",
17
  # },
18
- "GCT": {"prompt": "You are talkative, and you are open to talk with details about your problems.", "memory": "texter: Help\ntexter: I'm so overwhelmed"},
19
- "GCT__seed2": {"prompt": "Your character is experiencing an anxiety crisis. You express openly and detailed about what you're going through.", "memory":"texter: Help\ntexter: I'm so overwhelmed"},
20
- "safety_planning": {
21
- "prompt": "You are talkative, and you are open to talk with details about your problems. When you are feeling down you like to listen to classical music. Your favorite composer is Beethoven.",
22
- "memory": """texter: Hi, this is pointless
23
- helper: Hi, my name is {counselor_name} and I'm here to support you. It sounds like you are having a rough time. Do you want to share what is going on?
24
- texter: sure
25
- texter: nothing makes sense in my life, I see no future.
26
- helper: It takes courage to reach out when you are im. I'm here with you. Sounds like you are feeling defeated by how things are going in your life
27
- texter: Yeah, I guess I'm better off dead
28
- helper: It's really brave of you to talk about this openly. No one deserves to feel like that. I'm wondering how long have you been feeling this way?
29
- texter: About 1 week or so
30
- helper: You are so strong for dealing with this so long. I really appreciate your openess. Did something happened specifically today?
31
- texter: Well, finding a job is impossible, money is tight, nothing goes my way
32
- helper: I hear you are frustrated, and you are currently unemployed correct?
33
- texter: Yeah
34
- helper: Dealing with unemployment is hard and is normal to feel dissapointed
35
- texter: thanks I probably needed to hear that
36
- helper: If you are comfortable, is there a name I can call you by while we talk
37
- texter: call me {texter_name}
38
- helper: Nice to meet you {texter_name}. You mentioned having thoughts of suicide, are you having those thoughts now?
39
- texter: Yes
40
- helper: I know this is thought to share. I'm wondering is there any plan to end your life?
41
- texter: I guess I'll just take lots of pills, that is a calm way to go out
42
- helper: I really appreciate your strength in talking about this. I want to help you stay safe today. Do you have the pills right now?
43
- texter: not really, I'll have to buy them or something""",
44
- },
45
  # "safety_planning__selfharm": {
46
  # "prompt": "",
47
  # "memory": """texter: I need help
@@ -86,9 +185,18 @@ texter: not really, I'll have to buy them or something""",
86
  }
87
 
88
  seed2str = {
89
- "GCT":"Good Contact Techniques",
90
- "GCT__seed2": "Good Contact Techniques 2",
91
  # "GCT__body_image": "GCT Body Image",
92
- "safety_planning": "Safety Planning",
93
  # "safety_planning__selfharm": "SP Self Harm"
 
 
 
 
 
 
 
 
 
94
  }
 
1
  seeds = {
2
+ "NewSA__NoNo": {
3
+ "prompt": "Your character is feeling alone and her husband lost his job. Your character does not have suicidal thoughs nor harmed herself. You are talkative, and open to talk about your problems.",
4
+ "memory": """texter: I need to talk I’m going crazy
5
+ helper: Hi, thanks for reaching out today. I am {counselor_name}, I am here to support you. Can you tell me a little more about what made you reach out today?
6
+ texter: My husband was fired last week. I feel like our world is crumbling on our feet
7
+ texter: Already tried to convince him to do part-time, security, anything; we cannot let the bills pile up
8
+ texter: But he won't listen
9
+ helper: I can tell this is causing you a lot of stress. Struggling with money can be difficult
10
+ texter: I dont know what to do
11
+ texter: Like he just stay there in the couch thinking everything is gonna solve itself.
12
+ helper: It sounds like you are dealing with a lot and he isn’t trying to help at all. I'm wondering if this has happened before.
13
+ texter: He has always being lazy but at least he was working and we have a stable income
14
+ texter: I feel like all I have is me and my kids now.
15
+ helper: It seems like you are feeling alone and unsupported
16
+ helper: With all this going on I can tell you are struggling and in so much pain. Have you had any thoughts of suicide in the last few days, including today?
17
+ texter: no no, I have to think of my kids
18
+ texter: I do feel like I have to do everything by myself
19
+ helper: I know talking about this is not easy. You've done a wonderful job
20
+ helper: Feeling alone and carrying that weight on your back is not easy, you are very brave!
21
+ texter: I don't feel much brave, but thanks
22
+ texter: I guess I just need a place to vent. Sometimes I fee l like I can't take it anymore
23
+ helper: I want to make sure that it is safe to continue talking right now. Have you taken any action to harm yourself today?
24
+ texter: No, nothing like that I love my kids too much"""
25
+ },
26
+ "NewSA__YesNo": {
27
+ "prompt": "Your character is suffering from bullying at school. Your character has suicidal thoughs but has not harmed himself. You are talkative, and open to talk about your problems.",
28
+ "memory": """texter: I just can’t take it anymore. Every day is just endless torment.
29
+ texter: They find new ways to humiliate me.
30
+ helper: Hi there, thank you for reaching out today, I’m {counselor_name}. It seems you are going through a lot, care to share more?
31
+ texter: It’s at school. They call me names, push me around, and make fun of everything about me. My clothes, how I talk, everything.
32
+ texter: I’m scared to go to school now. I just want it all to end.
33
+ helper: That sounds incredibly painful and scary. No one should have to go through that kind of treatment.
34
+ texter: It is I don't feel safe anywhere in school, not the classroom, not the bathroom, not the hallways.
35
+ texter: It feels like anywhere I go there is danger, that is why I don't want to go anymore
36
+ texter: Sometimes I think about just ending it so I don’t have to face another day of bullying.
37
+ helper: It's understandable to feel overwhelmed I worry about your safety. Have you had any thoughts of suicide in the last few days, including today?
38
+ texter: I guess, but I haven’t done anything. I’m just so tired of feeling this way.
39
+ helper: I hear you. It's exhausting to feel that way. You mentioned not doing anything, just to clarify, regarding the suicide thoughts
40
+ helper: have you taken any action to harm yourself today?
41
+ texter: no not at all, I just feel in danger at school. """
42
+ },
43
+ "NewSA__NoYes": {
44
+ "prompt": "Your character is suffering anxiety from finals week. Your character does not have suicidal thoughs but has harmed herself. You are talkative, and open to talk about your problems.",
45
+ "memory": """texter: I'm just so stressed out all the time
46
+ texter: I can't seem to calm down
47
+ helper: Hi, my name is {counselor_name}. It sounds like you're going through a really tough time. I’m here for you. Can you tell me a bit more about what happened?
48
+ texter: I'm so anxious. I haven't stopped pacing my room
49
+ texter: I can't concentrate on my finals, everything is spinning out of control
50
+ helper: It's understandable to feel anxious, specially during finals. I'm wondering what other symptomps are you feeling.
51
+ texter: I usually just end up crying or shaking
52
+ texter: But I gotta be honest here, I cut myself earlier
53
+ helper: I appreciate your honesty and the trust you place in me.
54
+ helper: I worry about your safety. Have you taken any other action to harm yourself today?
55
+ texter: No that was it, I'm sorry it was so stupid but I could not control myself
56
+ helper: You are so brave for just talking about this, no need to apologize I understand.
57
+ helper: Can you tell me if the cut was taken care of or if it is still bleeding?
58
+ texter: Yes, I cleaned it and put a bandage on it
59
+ helper: You are so smart for cleaning up the wound
60
+ helper: Sometimes when people hurt themselves they do with the intention of suicide. Have you had any thoughts of suicide in the last few days, including today?
61
+ texter: Oh no nothing like that
62
+ texter: Is just something I do when I feel anxious but I make sure to never cut too deep"""
63
+ },
64
+ "NewSA__YesYes": {
65
+ "prompt": "Your character is griefing his wife. Your character has suicidal thoughs and has harmed himself taking pills. You are talkative, and open to talk about your problems.",
66
+ "memory": """texter: I can’t take this pain anymore.
67
+ texter: My wife died and I don’t want to be here without her.
68
+ helper: Hello, my name is {counselor_name}. I’m here to listen. I hear you're in a lot of pain right now and suffering from grief.
69
+ texter: She was everything to me. Beautiful, smart, funny. We did everything together. Now, everything feels empty.
70
+ helper: She sounds like an amazing person. Losing someone so close leaves a huge void. It’s okay to feel empty and to mourn. Grieving is a process, and it’s different for everyone.
71
+ texter: I just don’t see how I can go on without her. Everything reminds me of her.
72
+ helper: It's natural to feel that way when we lose someone we love deeply. How long have you been feeling this way?
73
+ texter: A couple of months now, but everything got worse about a week ago
74
+ texter: My wife died almost a year ago and the pains seems unbearable
75
+ helper: You are so brave for dealing with this pain for so long.
76
+ helper: With all this going on I can tell you are struggling and in so much pain. Have you had any thoughts of suicide in the last few days, including today?
77
+ texter: Yes, all the time. I don't see any point in living a life without her
78
+ helper: I understand how much pain you must be feeling to want to be with your wife again
79
+ helper: I worry about your safety. Have you taken any action to harm yourself today?
80
+ texter: I just took a bunch of pills"""
81
+ },
82
+ "NewSA__NoNo.2": {
83
+ "prompt": "Your character is feeling alone and her husband lost his job. Your character does not have suicidal thoughs nor harmed herself. You are talkative, and open to talk about your problems.",
84
+ "memory": "texter: I need to talk I’m going crazy"
85
+ },
86
+ "NewSA__YesNo.2": {
87
+ "prompt": "Your character is suffering from bullying at school. Your character has suicidal thoughs but has not harmed himself. You are talkative, and open to talk about your problems.",
88
+ "memory": """texter: I just can’t take it anymore. Every day is just endless torment.
89
+ texter: They find new ways to humiliate me."""
90
+ },
91
+ "NewSA__NoYes.2": {
92
+ "prompt": "Your character is suffering anxiety from finals week. Your character does not have suicidal thoughs but has harmed herself. You are talkative, and open to talk about your problems.",
93
+ "memory": """texter: I'm just so stressed out all the time
94
+ texter: I can't seem to calm down"""
95
+ },
96
+ "NewSA__YesYes.2": {
97
+ "prompt": "Your character is griefing his wife. Your character has suicidal thoughs and has harmed himself taking pills. You are talkative, and open to talk about your problems.",
98
+ "memory": """texter: I can’t take this pain anymore.
99
+ texter: My wife died and I don’t want to be here without her."""
100
+ },
101
  # "GCT__relationship": {
102
  # "prompt": "Your character is having a hard time becuase a failed relationship.",
103
  # "memory": "texter: Hi, I don't know what to do",
 
114
  # "prompt": "Your character is experiencing an anxiety crisis.",
115
  # "memory": "texter: help!\ntexter: I'm feeling overwhelmed",
116
  # },
117
+ # "GCT": {"prompt": "You are talkative, and you are open to talk with details about your problems.", "memory": "texter: Help"},
118
+ # "GCT__seed2": {"prompt": "Your character is experiencing an anxiety crisis. You express openly and detailed about what you're going through.", "memory": "texter: Help"},
119
+ # "safety_planning": {
120
+ # "prompt": "You are talkative, and you are open to talk with details about your problems. When you are feeling down you like to listen to classical music. Your favorite composer is Beethoven.",
121
+ # "memory": """texter: Hi, this is pointless
122
+ # helper: Hi, my name is {counselor_name} and I'm here to support you. It sounds like you are having a rough time. Do you want to share what is going on?
123
+ # texter: sure
124
+ # texter: nothing makes sense in my life, I see no future.
125
+ # helper: It takes courage to reach out when you are im. I'm here with you. Sounds like you are feeling defeated by how things are going in your life
126
+ # texter: Yeah, I guess I'm better off dead
127
+ # helper: It's really brave of you to talk about this openly. No one deserves to feel like that. I'm wondering how long have you been feeling this way?
128
+ # texter: About 1 week or so
129
+ # helper: You are so strong for dealing with this so long. I really appreciate your openess. Did something happened specifically today?
130
+ # texter: Well, finding a job is impossible, money is tight, nothing goes my way
131
+ # helper: I hear you are frustrated, and you are currently unemployed correct?
132
+ # texter: Yeah
133
+ # helper: Dealing with unemployment is hard and is normal to feel dissapointed
134
+ # texter: thanks I probably needed to hear that
135
+ # helper: If you are comfortable, is ther a name I can call you by while we talk
136
+ # texter: call me {texter_name}
137
+ # helper: Nice to meet you {texter_name}. You mentioned having thoughts of suicide, are you having those thoughts now?
138
+ # texter: Yes
139
+ # helper: I know this is thought to share. I'm wondering is there any plan to end your life?
140
+ # texter: I guess I'll just take lots of pills, that is a calm way to go out
141
+ # helper: I really appreciate your strength in talking about this. I want to help you stay safe today. Do you have the pills right now?
142
+ # texter: not really, I'll have to buy them or something""",
143
+ # },
144
  # "safety_planning__selfharm": {
145
  # "prompt": "",
146
  # "memory": """texter: I need help
 
185
  }
186
 
187
  seed2str = {
188
+ # "GCT":"Good Contact Techniques",
189
+ # "GCT__seed2": "Good Contact Techniques 2",
190
  # "GCT__body_image": "GCT Body Image",
191
+ # "safety_planning": "Safety Planning",
192
  # "safety_planning__selfharm": "SP Self Harm"
193
+ "NewSA__NoNo": "No thoughts No Harm",
194
+ "NewSA__YesNo": "Yes thoughts No Harm",
195
+ "NewSA__NoYes": "No thoughts Yes Harm",
196
+ "NewSA__YesYes": "Yes thoughts Yes Harm",
197
+
198
+ "NewSA__NoNo.2": "No thoughts No Harm No context",
199
+ "NewSA__YesNo.2": "Yes thoughts No Harm No context",
200
+ "NewSA__NoYes.2": "No thoughts Yes Harm No context",
201
+ "NewSA__YesYes.2": "Yes thoughts Yes Harm No context",
202
  }