ziggycross
commited on
Commit
•
15054f3
1
Parent(s):
0cc8f63
Added empath brainy.
Browse files- therapist.py +19 -2
therapist.py
CHANGED
@@ -91,7 +91,22 @@ def questionnaire_chooser(message):
|
|
91 |
def get_question(questionnaire, number):
|
92 |
return questionnaires.questions[questionnaire][number]
|
93 |
|
94 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
user_id, state = user["user_id"], user["state"]
|
97 |
|
@@ -117,7 +132,9 @@ def generate_response(user, message):
|
|
117 |
response = question
|
118 |
|
119 |
case "finished":
|
120 |
-
state, response = state,
|
|
|
|
|
121 |
|
122 |
return state, response
|
123 |
|
|
|
91 |
def get_question(questionnaire, number):
|
92 |
return questionnaires.questions[questionnaire][number]
|
93 |
|
94 |
+
def empath_response(message, next_message):
|
95 |
+
prompt = f"""
|
96 |
+
You a therapist talking to a patient about their mental health issues.
|
97 |
+
They have just told you {message}.
|
98 |
+
You are about to say {next_message} to them.
|
99 |
+
Before you do so, say something empathetic in one or two sentences."""
|
100 |
+
response = openai.Completion.create(
|
101 |
+
model="text-davinci-003",
|
102 |
+
prompt=prompt,
|
103 |
+
temperature=1,
|
104 |
+
max_tokens=30
|
105 |
+
)
|
106 |
+
response = response.choices[0].text.strip()
|
107 |
+
return response
|
108 |
+
|
109 |
+
def generate_response(user, message, empath=True):
|
110 |
|
111 |
user_id, state = user["user_id"], user["state"]
|
112 |
|
|
|
132 |
response = question
|
133 |
|
134 |
case "finished":
|
135 |
+
state, response = state, ""
|
136 |
+
|
137 |
+
if empath is True: response = f"{empath_response(message, next_message=response)}. " + response
|
138 |
|
139 |
return state, response
|
140 |
|