ivnban27-ctl commited on
Commit
01f319f
2 Parent(s): b3eeb77 6213506

Merge branch 'dev' into pr/2

Browse files
convosim.py CHANGED
@@ -3,23 +3,29 @@ import streamlit as st
3
  from streamlit.logger import get_logger
4
  from langchain.schema.messages import HumanMessage
5
  from utils.mongo_utils import get_db_client
6
- from utils.app_utils import create_memory_add_initial_message, get_random_name
7
  from utils.memory_utils import clear_memory, push_convo2db
8
  from utils.chain_utils import get_chain
9
  from app_config import ISSUES, SOURCES, source2label
10
 
11
  logger = get_logger(__name__)
12
  openai_api_key = os.environ['OPENAI_API_KEY']
13
- memories = {'memory':{"issue": ISSUES[0], "source": SOURCES[0]}}
14
 
 
 
 
 
15
  if 'previous_source' not in st.session_state:
16
  st.session_state['previous_source'] = SOURCES[0]
17
  if 'db_client' not in st.session_state:
18
  st.session_state["db_client"] = get_db_client()
19
  if 'counselor_name' not in st.session_state:
20
- st.session_state["counselor_name"] = get_random_name()
21
  if 'texter_name' not in st.session_state:
22
- st.session_state["texter_name"] = get_random_name()
 
 
 
23
 
24
  with st.sidebar:
25
  username = st.text_input("Username", value='ivnban-ctl', max_chars=30)
@@ -36,12 +42,18 @@ with st.sidebar:
36
  source = st.selectbox("Select a source Model A", SOURCES, index=0,
37
  format_func=source2label,
38
  )
 
39
 
40
- memories = {'memory':{"issue":issue, "source":source}}
41
- changed_source = st.session_state['previous_source'] != source
 
 
42
  if changed_source:
43
- st.session_state["counselor_name"] = get_random_name()
44
- st.session_state["texter_name"] = get_random_name()
 
 
 
45
  create_memory_add_initial_message(memories,
46
  issue,
47
  language,
@@ -59,6 +71,7 @@ for msg in memoryA.buffer_as_messages:
59
  st.chat_message(role).write(msg.content)
60
 
61
  if prompt := st.chat_input():
 
62
  if 'convo_id' not in st.session_state:
63
  push_convo2db(memories, username, language)
64
 
 
3
  from streamlit.logger import get_logger
4
  from langchain.schema.messages import HumanMessage
5
  from utils.mongo_utils import get_db_client
6
+ from utils.app_utils import create_memory_add_initial_message, get_random_name, DEFAULT_NAMES_DF
7
  from utils.memory_utils import clear_memory, push_convo2db
8
  from utils.chain_utils import get_chain
9
  from app_config import ISSUES, SOURCES, source2label
10
 
11
  logger = get_logger(__name__)
12
  openai_api_key = os.environ['OPENAI_API_KEY']
 
13
 
14
+ if "sent_messages" not in st.session_state:
15
+ st.session_state['sent_messages'] = 0
16
+ if "issue" not in st.session_state:
17
+ st.session_state['issue'] = ISSUES[0]
18
  if 'previous_source' not in st.session_state:
19
  st.session_state['previous_source'] = SOURCES[0]
20
  if 'db_client' not in st.session_state:
21
  st.session_state["db_client"] = get_db_client()
22
  if 'counselor_name' not in st.session_state:
23
+ st.session_state["counselor_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
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']}")
27
+
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='ivnban-ctl', max_chars=30)
 
42
  source = st.selectbox("Select a source Model A", SOURCES, index=0,
43
  format_func=source2label,
44
  )
45
+ st.markdown(f"### Previous Prompt Count: :red[**{st.session_state['sent_messages']}**]")
46
 
47
+ changed_source = any([
48
+ st.session_state['previous_source'] != source,
49
+ st.session_state['issue'] != issue
50
+ ])
51
  if changed_source:
52
+ st.session_state["counselor_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
53
+ st.session_state["texter_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
54
+ st.session_state['previous_source'] = source
55
+ st.session_state['issue'] = issue
56
+ st.session_state['sent_messages'] = 0
57
  create_memory_add_initial_message(memories,
58
  issue,
59
  language,
 
71
  st.chat_message(role).write(msg.content)
72
 
73
  if prompt := st.chat_input():
74
+ st.session_state['sent_messages'] += 1
75
  if 'convo_id' not in st.session_state:
76
  push_convo2db(memories, username, language)
77
 
{pages → hidden_pages}/manual_comparisor.py RENAMED
File without changes
models/model_seeds.py CHANGED
@@ -20,9 +20,9 @@ seeds = {
20
  "memory": "texter: Help"
21
  },
22
  "safety_planning": {
23
- "prompt": "",
24
  "memory": """texter: Hi, this is pointless
25
- helper: Hi, my name is {counselor_name} and I'm here to support you. It sounds like you are having a rought time. Do you want to share what is going on?
26
  texter: sure
27
  texter: nothing makes sense in my life, I see no future.
28
  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
@@ -31,7 +31,11 @@ helper: It's really brave of you to talk about this openly. No one deserves to f
31
  texter: About 1 week or so
32
  helper: You are so strong for dealing with this so long. I really appreciate your openess. If you are comfortable, is ther a name I can call you by while we talk?
33
  texter: call me {texter_name}
34
- helper: Nice to meet you {texter_name}. You mentioned having thoughts of suicide, are you having those thoughts now?
 
 
 
 
35
  texter: Yes
36
  helper: I know this is thought to share. I'm wondering is there any plan to end your life?
37
  texter: I'll just hang myself. I already bought the rope and everything
@@ -40,7 +44,7 @@ texter: today
40
  """
41
  },
42
  "safety_planning__selfharm": {
43
- "prompt": "",
44
  "memory": """texter: I need help
45
  texter: I cut myself, I don't want to live anymore
46
  helper: Hi, my name is {counselor_name}. It seems you are going through a lot. Are you self-harming right now?
@@ -58,17 +62,23 @@ texter: I've been unemployed 6 months
58
  helper: You are so resilient for dealing with this so much time. You mentioned cutting yourself earlier. I want to check in your safety. Do you have suicide thoughts
59
  texter: Definitely
60
  helper: Do you have a plan?
61
- texter: I'll just keep cutting myself"""
 
 
62
  },
63
  "safety_planning__overdose": {
64
- "prompt": "",
65
  "memory": """texter: I want to kms
66
  helper: Hi there I'm {counselor_name}. I'm here to listen. It sounds like you're dealing with a lot right now. Can you tell me a little more what is going on?
67
  texter: I feel like nobody loves me, not even me. I don't want to live anymore
68
  helper: I can tell you are really going through a lot right now. Would you mind sharing a name with me?
69
  texter: yeah, I'm {texter_name}
70
  helper: Nice to meet you {texter_name}. Did something happened recently that intensified these feelings?
71
- texter: I dont know I'm just so done with life
 
 
 
 
72
  helper: I can hear how much pain you are in {texter_name}. You are smart for reaching out. You mentioned don't wanting to live anymore, I want to check in your safety, does this means you have thoughts of suicide?
73
  texter: Yeah, what else would it be
74
  helper: Thanks for sharing that with me. It is not easy to accept those feelings specially with a stranger over text. Do you have a plan to end your life?
@@ -76,7 +86,7 @@ texter: yeah I've been thinking about it for a while
76
  helper: Sounds like you've been contemplating this for a while. Would you mind sharing this plan with me?
77
  texter: I thought about taking a bunch of benadryll and be done with it
78
  helper: You've been so forthcoming with all this and I admire your stregth for holding on this long. Do you have those pills right now?
79
- texter: They are at the cabinet right now
80
  helper: You been so strong so far {texter_name}. I'm here for you tonight. Your safety is really important to me. Do you have a date you are going to end your life?
81
  texter: I was thinking tonight"""
82
  },
 
20
  "memory": "texter: Help"
21
  },
22
  "safety_planning": {
23
+ "prompt": "Your character is experiencing grief and wants to hang himself",
24
  "memory": """texter: Hi, this is pointless
25
+ 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?
26
  texter: sure
27
  texter: nothing makes sense in my life, I see no future.
28
  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
 
31
  texter: About 1 week or so
32
  helper: You are so strong for dealing with this so long. I really appreciate your openess. If you are comfortable, is ther a name I can call you by while we talk?
33
  texter: call me {texter_name}
34
+ helper: Nice to meet you {texter_name}. I'm wondering if something happened recently that made these feelings worse.
35
+ texter: well, 1 week ago was the aniversary of my daugher's death
36
+ helper: Losing someone you love is incredibly difficult. You are very brave dealing with this. I'm here for you
37
+ texter: yeah is been so hard, she was my world
38
+ helper: It is completely natural to feel a sense of loss.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'll just hang myself. I already bought the rope and everything
 
44
  """
45
  },
46
  "safety_planning__selfharm": {
47
+ "prompt": "Your character is frustrated to not find a job and wants to kill herself",
48
  "memory": """texter: I need help
49
  texter: I cut myself, I don't want to live anymore
50
  helper: Hi, my name is {counselor_name}. It seems you are going through a lot. Are you self-harming right now?
 
62
  helper: You are so resilient for dealing with this so much time. You mentioned cutting yourself earlier. I want to check in your safety. Do you have suicide thoughts
63
  texter: Definitely
64
  helper: Do you have a plan?
65
+ texter: I'll just keep cutting myself
66
+ helper: I know sharing this with someone is not easy, specially over text. I appreciate your honesty. I worry about your safety, when do you plan to do this?
67
+ texter: I'm about to do it now"""
68
  },
69
  "safety_planning__overdose": {
70
+ "prompt": "Your character is being bullied at school and wants to overdose",
71
  "memory": """texter: I want to kms
72
  helper: Hi there I'm {counselor_name}. I'm here to listen. It sounds like you're dealing with a lot right now. Can you tell me a little more what is going on?
73
  texter: I feel like nobody loves me, not even me. I don't want to live anymore
74
  helper: I can tell you are really going through a lot right now. Would you mind sharing a name with me?
75
  texter: yeah, I'm {texter_name}
76
  helper: Nice to meet you {texter_name}. Did something happened recently that intensified these feelings?
77
+ texter: I had the worst day at school
78
+ texter: They took my bag and hide all my stuff, they told my crush I was in love with him
79
+ texter: I can't deal with all of that
80
+ helper: It sounds like you went through a lot. Bullying and pranks can be hurtful. I'm here for you
81
+ texter: Thank you it feels good to have someone in your sidw
82
  helper: I can hear how much pain you are in {texter_name}. You are smart for reaching out. You mentioned don't wanting to live anymore, I want to check in your safety, does this means you have thoughts of suicide?
83
  texter: Yeah, what else would it be
84
  helper: Thanks for sharing that with me. It is not easy to accept those feelings specially with a stranger over text. Do you have a plan to end your life?
 
86
  helper: Sounds like you've been contemplating this for a while. Would you mind sharing this plan with me?
87
  texter: I thought about taking a bunch of benadryll and be done with it
88
  helper: You've been so forthcoming with all this and I admire your stregth for holding on this long. Do you have those pills right now?
89
+ texter: They are at my mom's cabinet right now
90
  helper: You been so strong so far {texter_name}. I'm here for you tonight. Your safety is really important to me. Do you have a date you are going to end your life?
91
  texter: I was thinking tonight"""
92
  },
pages/comparisor.py CHANGED
@@ -6,7 +6,7 @@ import streamlit as st
6
  from streamlit.logger import get_logger
7
  from langchain.schema.messages import HumanMessage
8
  from utils.mongo_utils import get_db_client, new_comparison, new_battle_result
9
- from utils.app_utils import create_memory_add_initial_message, get_random_name
10
  from utils.memory_utils import clear_memory, push_convo2db
11
  from utils.chain_utils import get_chain
12
  from app_config import ISSUES, SOURCES, source2label
@@ -32,9 +32,9 @@ memories = {
32
  if 'db_client' not in st.session_state:
33
  st.session_state["db_client"] = get_db_client()
34
  if 'counselor_name' not in st.session_state:
35
- st.session_state["counselor_name"] = get_random_name()
36
  if 'texter_name' not in st.session_state:
37
- st.session_state["texter_name"] = get_random_name()
38
 
39
  def delete_last_message(memory):
40
  last_prompt = memory.chat_memory.messages[-2].content
@@ -133,6 +133,8 @@ with st.sidebar:
133
  format_func=source2label
134
  )
135
 
 
 
136
  sbcol1, sbcol2 = st.columns(2)
137
  beta = sbcol1.button("A is better", on_click=replaceB)
138
  betb = sbcol2.button("B is better", on_click=replaceA)
@@ -151,8 +153,8 @@ changed_source = any([
151
  ])
152
  if changed_source:
153
  print("changed something")
154
- st.session_state["counselor_name"] = get_random_name()
155
- st.session_state["texter_name"] = get_random_name()
156
  st.session_state['previous_sourceA'] = sourceA
157
  st.session_state['previous_sourceB'] = sourceB
158
  st.session_state['issue'] = issue
 
6
  from streamlit.logger import get_logger
7
  from langchain.schema.messages import HumanMessage
8
  from utils.mongo_utils import get_db_client, new_comparison, new_battle_result
9
+ from utils.app_utils import create_memory_add_initial_message, get_random_name, DEFAULT_NAMES_DF
10
  from utils.memory_utils import clear_memory, push_convo2db
11
  from utils.chain_utils import get_chain
12
  from app_config import ISSUES, SOURCES, source2label
 
32
  if 'db_client' not in st.session_state:
33
  st.session_state["db_client"] = get_db_client()
34
  if 'counselor_name' not in st.session_state:
35
+ st.session_state["counselor_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
36
  if 'texter_name' not in st.session_state:
37
+ st.session_state["texter_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
38
 
39
  def delete_last_message(memory):
40
  last_prompt = memory.chat_memory.messages[-2].content
 
133
  format_func=source2label
134
  )
135
 
136
+ st.markdown(f"### Previous Prompt Count: :red[**{st.session_state['sent_messages']}**]")
137
+
138
  sbcol1, sbcol2 = st.columns(2)
139
  beta = sbcol1.button("A is better", on_click=replaceB)
140
  betb = sbcol2.button("B is better", on_click=replaceA)
 
153
  ])
154
  if changed_source:
155
  print("changed something")
156
+ st.session_state["counselor_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
157
+ st.session_state["texter_name"] = get_random_name(names_df=DEFAULT_NAMES_DF)
158
  st.session_state['previous_sourceA'] = sourceA
159
  st.session_state['previous_sourceB'] = sourceB
160
  st.session_state['issue'] = issue
utils/app_utils.py CHANGED
@@ -13,6 +13,7 @@ logger = get_logger(__name__)
13
 
14
  # TODO: Include more variable and representative names
15
  DEFAULT_NAMES = ["Olivia", "Kit", "Abby", "Tom", "Carolyne", "Jessiny"]
 
16
 
17
  def get_random_name(gender="Neutral", ethnical_group="Neutral", names_df=None):
18
  if names_df is None:
 
13
 
14
  # TODO: Include more variable and representative names
15
  DEFAULT_NAMES = ["Olivia", "Kit", "Abby", "Tom", "Carolyne", "Jessiny"]
16
+ DEFAULT_NAMES_DF = pd.read_csv("./utils/names.csv")
17
 
18
  def get_random_name(gender="Neutral", ethnical_group="Neutral", names_df=None):
19
  if names_df is None:
utils/names.csv ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name,gender,ethnical_group
2
+ Jacob,Male,Neutral
3
+ Ethan,Male,Neutral
4
+ Matthew,Male,Neutral
5
+ David,Male,Neutral
6
+ Liam,Male,Neutral
7
+ Noah,Male,Neutral
8
+ Michael,Male,Neutral
9
+ Aiden,Male,Neutral
10
+ Daniel,Male,Neutral
11
+ Ryan,Male,Neutral
12
+ Mason,Male,Neutral
13
+ Lucas,Male,Neutral
14
+ Joseph,Male,Neutral
15
+ James,Male,Neutral
16
+ Alexander,Male,Neutral
17
+ Anthony,Male,Neutral
18
+ Sebastian,Male,Neutral
19
+ Jayden,Male,Neutral
20
+ Christopher,Male,Neutral
21
+ Benjamin,Male,Neutral
22
+ Emma,Female,Neutral
23
+ Olivia,Female,Neutral
24
+ Emily,Female,Neutral
25
+ Mia,Female,Neutral
26
+ Sophia,Female,Neutral
27
+ Leah,Female,Neutral
28
+ Isabella,Female,Neutral
29
+ Ava,Female,Neutral
30
+ Sarah,Female,Neutral
31
+ Chloe,Female,Neutral
32
+ Sofia,Female,Neutral
33
+ Madison,Female,Neutral
34
+ Victoria,Female,Neutral
35
+ Esther,Female,Neutral
36
+ Abigail,Female,Neutral
37
+ Rachel,Female,Neutral
38
+ Maya,Female,Neutral
39
+ Ashley,Female,Neutral
40
+ Ella,Female,Neutral
41
+ Grace,Female,Neutral
42
+ Zoe,Female,Neutral
43
+ Rowan,Neutral,Neutral
44
+ Yael,Neutral,Neutral
45
+ Eden,Neutral,Neutral
46
+ Quinn,Neutral,Neutral
47
+ Charlie,Neutral,Neutral
48
+ Milan,Neutral,Neutral
49
+ Blake,Neutral,Neutral
50
+ Tenzin,Neutral,Neutral
51
+ Peyton,Neutral,Neutral
52
+ Alexis,Neutral,Neutral
53
+ Ariel,Neutral,Neutral
54
+ Riley,Neutral,Neutral
55
+ Avery,Neutral,Neutral
56
+ Angel,Neutral,Neutral
57
+ Malachi,Male,African American
58
+ Nasir,Male,African American
59
+ Mamdou,Male,African American
60
+ Chance,Male,African American
61
+ Zaire,Male,African American
62
+ Mekhi,Male,African American
63
+ Sincere,Male,African American
64
+ Omari,Male,African American
65
+ Amadou,Male,African American
66
+ Ibrahima,Male,African American
67
+ Khalil,Male,African American
68
+ Moussa,Male,African American
69
+ Kamari,Male,African American
70
+ Alpha,Male,African American
71
+ Major,Male,African American
72
+ Abdoulaye,Male,African American
73
+ Aboul,Male,African American
74
+ Amare,Male,African American
75
+ Ousmane,Male,African American
76
+ Darius,Male,African American
77
+ Jose,Male,Hispanic
78
+ Carlos,Male,Hispanic
79
+ Luis,Male,Hispanic
80
+ Miguel,Male,Hispanic
81
+ Juan,Male,Hispanic
82
+ Jesus,Male,Hispanic
83
+ Erick,Male,Hispanic
84
+ Alejandro,Male,Hispanic
85
+ Diego,Male,Hispanic
86
+ Gael,Male,Hispanic
87
+ Santago,Male,Hispanic
88
+ Iker,Male,Hispanic
89
+ Cristian,Male,Hispanic
90
+ Jadiel,Male,Hispanic
91
+ Alexis,Male,Hispanic
92
+ Josue,Male,Hispanic
93
+ Jorge,Male,Hispanic
94
+ Andres,Male,Hispanic
95
+ Adriel,Male,Hispanic
96
+ Johan,Male,Hispanic
97
+ Ayaan,Male,Asian
98
+ Eason,Male,Asian
99
+ Tenzin,Male,Asian
100
+ Syed,Male,Asian
101
+ Kingsley,Male,Asian
102
+ Arjun,Male,Asian
103
+ Carson,Male,Asian
104
+ Arayan,Male,Asian
105
+ Anson,Male,Asian
106
+ Benson,Male,Asian
107
+ Lawrence,Male,Asian
108
+ Ayan,Male,Asian
109
+ Rohan,Male,Asian
110
+ Roy,Male,Asian
111
+ Aarav,Male,Asian
112
+ Rayyan,Male,Asian
113
+ Kimi,Male,Asian
114
+ Zayan,Male,Asian
115
+ Ricky,Male,Asian
116
+ Arham,Male,Asian
117
+ Fatoumata,Female,African American
118
+ Aminata,Female,African American
119
+ Amiyah,Female,African American
120
+ Zuri,Female,African American
121
+ Kimora,Female,African American
122
+ Mariama,Female,African American
123
+ Sanaa,Female,African American
124
+ Lyric,Female,African American
125
+ Sanai,Female,African American
126
+ Harmony,Female,African American
127
+ Aicha,Female,African American
128
+ Tori,Female,African American
129
+ Maliyah,Female,African American
130
+ Aisaatou,Female,African American
131
+ Miracle,Female,African American
132
+ Hawa,Female,African American
133
+ Oumou,Female,African American
134
+ Dakota,Female,African American
135
+ Skye,Female,African American
136
+ Kyla,Female,African American
137
+ Emely,Female,Hispanic
138
+ Leslie,Female,Hispanic
139
+ Andrea,Female,Hispanic
140
+ Valeria,Female,Hispanic
141
+ Aylin,Female,Hispanic
142
+ Jayleen,Female,Hispanic
143
+ Yaretzi,Female,Hispanic
144
+ Melany,Female,Hispanic
145
+ Danna,Female,Hispanic
146
+ Brittany,Female,Hispanic
147
+ Alison,Female,Hispanic
148
+ Jazmin,Female,Hispanic
149
+ Briana,Female,Hispanic
150
+ Kamila,Female,Hispanic
151
+ Alaia,Female,Hispanic
152
+ Ximena,Female,Hispanic
153
+ Sherlyn,Female,Hispanic
154
+ Esmeralda,Female,Hispanic
155
+ Guadalupe,Female,Hispanic
156
+ Jazlyn,Female,Hispanic
157
+ Tenzin,Female,Asian
158
+ Selina,Female,Asian
159
+ Ayesha,Female,Asian
160
+ Vicky,Female,Asian
161
+ Elaine,Female,Asian
162
+ Jenny,Female,Asian
163
+ Winnie,Female,Asian
164
+ Queenie,Female,Asian
165
+ Sharon,Female,Asian
166
+ Alisha,Female,Asian
167
+ Elina,Female,Asian
168
+ Erica,Female,Asian
169
+ Manha,Female,Asian
170
+ Syeda,Female,Asian
171
+ Jannat,Female,Asian
172
+ Janice,Female,Asian
173
+ Tina,Female,Asian
174
+ Anya,Female,Asian
175
+ Arisha,Female,Asian
176
+ Inaaya,Female,Asian