ziggycross
commited on
Commit
•
6f97851
1
Parent(s):
caeec0f
Fixed listify bug.
Browse files- therapist.py +9 -5
therapist.py
CHANGED
@@ -9,9 +9,11 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
9 |
|
10 |
available_questionnaires = list(questionnaires.topics)
|
11 |
|
12 |
-
def listify(options: list, lower=True):
|
13 |
-
|
|
|
14 |
if lower is True: options = list(map(str.lower, options))
|
|
|
15 |
return ", ".join(options) if len(options) > 2 else " ".join(options)
|
16 |
|
17 |
def content_summarizer():
|
@@ -21,12 +23,12 @@ def assess_response(question: str, response:str, options: list, uses_scale=True,
|
|
21 |
context_prompt = "" if context=="" else f"The context of this discussion is {context}. "
|
22 |
if uses_scale is True:
|
23 |
prompt = context_prompt + f"""
|
24 |
-
Given the question '{question}' and this response to the question '{response}', rate the response on the following scale: {
|
25 |
Return only the corresponding scale item and nothing else.
|
26 |
"""
|
27 |
else:
|
28 |
prompt = context_prompt + f"""
|
29 |
-
Given the question '{question}' and this response to the question '{response}', which of the following is the response most similar to? {
|
30 |
Return only the most similar item and nothing else.
|
31 |
"""
|
32 |
response = openai.Completion.create(
|
@@ -41,10 +43,12 @@ def yes_no(message):
|
|
41 |
return assess_response(question="Yes or No?", response=message, options=["Yes", "No"], context="", uses_scale=False)
|
42 |
|
43 |
def questionnaire_chooser(message):
|
|
|
|
|
44 |
topic = assess_response(
|
45 |
question = initial_message,
|
46 |
response = message,
|
47 |
-
options =
|
48 |
uses_scale = False
|
49 |
)
|
50 |
|
|
|
9 |
|
10 |
available_questionnaires = list(questionnaires.topics)
|
11 |
|
12 |
+
def listify(options: list, end_and=True, lower=True, use_format=None):
|
13 |
+
options = options.copy()
|
14 |
+
if end_and is True and len(options) > 1: options[-1] = "and " + options[-1]
|
15 |
if lower is True: options = list(map(str.lower, options))
|
16 |
+
if use_format: list(map(use_format.format, options))
|
17 |
return ", ".join(options) if len(options) > 2 else " ".join(options)
|
18 |
|
19 |
def content_summarizer():
|
|
|
23 |
context_prompt = "" if context=="" else f"The context of this discussion is {context}. "
|
24 |
if uses_scale is True:
|
25 |
prompt = context_prompt + f"""
|
26 |
+
Given the question '{question}' and this response to the question '{response}', rate the response on the following scale: {listify(options, end_and=False, lower=False, use_format="'{}'")}.
|
27 |
Return only the corresponding scale item and nothing else.
|
28 |
"""
|
29 |
else:
|
30 |
prompt = context_prompt + f"""
|
31 |
+
Given the question '{question}' and this response to the question '{response}', which of the following is the response most similar to? {listify(options, end_and=False, lower=False, use_format="'{}'")}.
|
32 |
Return only the most similar item and nothing else.
|
33 |
"""
|
34 |
response = openai.Completion.create(
|
|
|
43 |
return assess_response(question="Yes or No?", response=message, options=["Yes", "No"], context="", uses_scale=False)
|
44 |
|
45 |
def questionnaire_chooser(message):
|
46 |
+
options = available_questionnaires + ["Suicidal", "None of the previously mentioned options"]
|
47 |
+
|
48 |
topic = assess_response(
|
49 |
question = initial_message,
|
50 |
response = message,
|
51 |
+
options = options,
|
52 |
uses_scale = False
|
53 |
)
|
54 |
|