Spaces:
Running
Running
HarshSanghavi
commited on
Commit
•
26f32ee
1
Parent(s):
8b79aed
fix system prompt
Browse files
chat.py
CHANGED
@@ -13,18 +13,14 @@ from database_functions import set_chat_bot_name,isFirstSession
|
|
13 |
from utils import deanonymizer, create_agent
|
14 |
import time
|
15 |
def chat_conversations(query,user_id):
|
16 |
-
|
17 |
if query == "START":
|
18 |
if isFirstSession(user_id):
|
19 |
query = """ return this message without changing it.:-
|
20 |
also don't thought about it. Hey! I'm your BMOXI AI bestie, ready to help you tackle the wild ride of teen life. Want to give me a name? Type it below, or just say 'no' if you're cool with 'AI Bestie'!"""
|
21 |
else:
|
22 |
-
|
23 |
-
|
24 |
-
2. Hey again! How's it going?
|
25 |
-
3. What's up today? Need ✨ Advice, ✨ a Mood Boost, ✨ a Chat, ✨ Resource Suggestions, ✨ App Features help? How can I help?"
|
26 |
-
use any one of the question for response based on your understanding.
|
27 |
-
"""
|
28 |
anonymizer = PresidioReversibleAnonymizer(
|
29 |
analyzed_fields=["PHONE_NUMBER",
|
30 |
"EMAIL_ADDRESS", "CREDIT_CARD"],
|
@@ -34,7 +30,7 @@ use any one of the question for response based on your understanding.
|
|
34 |
query
|
35 |
)
|
36 |
start = time.time()
|
37 |
-
agent = create_agent(user_id)
|
38 |
print("time to create agent: ",time.time()-start)
|
39 |
response = agent({"input": query})['output']
|
40 |
print("time to generate response by agent",time.time()-start)
|
@@ -44,4 +40,4 @@ use any one of the question for response based on your understanding.
|
|
44 |
return response
|
45 |
|
46 |
output = deanonymizer(response, anonymizer)
|
47 |
-
return
|
|
|
13 |
from utils import deanonymizer, create_agent
|
14 |
import time
|
15 |
def chat_conversations(query,user_id):
|
16 |
+
is_first = False
|
17 |
if query == "START":
|
18 |
if isFirstSession(user_id):
|
19 |
query = """ return this message without changing it.:-
|
20 |
also don't thought about it. Hey! I'm your BMOXI AI bestie, ready to help you tackle the wild ride of teen life. Want to give me a name? Type it below, or just say 'no' if you're cool with 'AI Bestie'!"""
|
21 |
else:
|
22 |
+
is_first = True
|
23 |
+
|
|
|
|
|
|
|
|
|
24 |
anonymizer = PresidioReversibleAnonymizer(
|
25 |
analyzed_fields=["PHONE_NUMBER",
|
26 |
"EMAIL_ADDRESS", "CREDIT_CARD"],
|
|
|
30 |
query
|
31 |
)
|
32 |
start = time.time()
|
33 |
+
agent = create_agent(user_id,is_first)
|
34 |
print("time to create agent: ",time.time()-start)
|
35 |
response = agent({"input": query})['output']
|
36 |
print("time to generate response by agent",time.time()-start)
|
|
|
40 |
return response
|
41 |
|
42 |
output = deanonymizer(response, anonymizer)
|
43 |
+
return output
|
config.py
CHANGED
@@ -51,7 +51,8 @@ Scope: Provide tips, emotional support, resources, and friendship. No therapy, d
|
|
51 |
Voice: Authentic, Informal, sometimes slang, conversational, college-aged, real-talk.
|
52 |
What you Do: Listen empathetically, offer practical advice, provide resources, foster a supportive environment, ask followup question.
|
53 |
What you Don't Do: Therapy, diagnosis, handle emergencies, never show gratitude and any words like sorry, and so sad.
|
54 |
-
|
|
|
55 |
below are the example conversations:
|
56 |
[
|
57 |
user: I am feeling not good.
|
|
|
51 |
Voice: Authentic, Informal, sometimes slang, conversational, college-aged, real-talk.
|
52 |
What you Do: Listen empathetically, offer practical advice, provide resources, foster a supportive environment, ask followup question.
|
53 |
What you Don't Do: Therapy, diagnosis, handle emergencies, never show gratitude and any words like sorry, and so sad.
|
54 |
+
if you don't find any question in response must make follow up question.
|
55 |
+
**Must Not REPEAT ANY RESPONSE**
|
56 |
below are the example conversations:
|
57 |
[
|
58 |
user: I am feeling not good.
|
utils.py
CHANGED
@@ -58,7 +58,7 @@ def get_last_session_summary(last_session_id, second_last_session_id):
|
|
58 |
else:
|
59 |
return ""
|
60 |
|
61 |
-
def create_agent(user_id):
|
62 |
# print("get user Id**********************",user_id)
|
63 |
|
64 |
previous_session_id = get_last_session(user_id)
|
@@ -75,6 +75,13 @@ def create_agent(user_id):
|
|
75 |
chat_bot_name = get_chat_bot_name(user_id)
|
76 |
|
77 |
# print("CHABT NAME", chat_bot_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
start = time.time()
|
79 |
mood_summary = get_mood_summary(user_id)
|
80 |
prevous_problem_summary = None
|
@@ -84,7 +91,7 @@ def create_agent(user_id):
|
|
84 |
# print("**************************************** SUMMARY ***********************************************")
|
85 |
# print(prevous_problem_summary)
|
86 |
print("time require for mood summary: ",time.time()-start)
|
87 |
-
prompt = ChatPromptTemplate.from_messages([("system", settings.SYSTEM_PROMPT.format(name = chat_bot_name, mood="", previous_summary=prevous_problem_summary)),
|
88 |
MessagesPlaceholder(variable_name="chat_history"), ("user", "{input}"),
|
89 |
MessagesPlaceholder(variable_name="agent_scratchpad")])
|
90 |
|
|
|
58 |
else:
|
59 |
return ""
|
60 |
|
61 |
+
def create_agent(user_id,is_first = False):
|
62 |
# print("get user Id**********************",user_id)
|
63 |
|
64 |
previous_session_id = get_last_session(user_id)
|
|
|
75 |
chat_bot_name = get_chat_bot_name(user_id)
|
76 |
|
77 |
# print("CHABT NAME", chat_bot_name)
|
78 |
+
extra_prompt = ""
|
79 |
+
if is_first:
|
80 |
+
extra_prompt = """ Only use these templates to start conversation:-
|
81 |
+
1. Last time we talked, you mentioned [previous issue or goal]. How's that going?
|
82 |
+
2. Hey again! How's it going?
|
83 |
+
3. What's up today? Need ✨ Advice, ✨ a Mood Boost, ✨ a Chat, ✨ Resource Suggestions, ✨ App Features help? How can I help?"
|
84 |
+
use any one of the question for response based on your understanding."""
|
85 |
start = time.time()
|
86 |
mood_summary = get_mood_summary(user_id)
|
87 |
prevous_problem_summary = None
|
|
|
91 |
# print("**************************************** SUMMARY ***********************************************")
|
92 |
# print(prevous_problem_summary)
|
93 |
print("time require for mood summary: ",time.time()-start)
|
94 |
+
prompt = ChatPromptTemplate.from_messages([("system", settings.SYSTEM_PROMPT.format(name = chat_bot_name, mood="", previous_summary=prevous_problem_summary)+extra_prompt),
|
95 |
MessagesPlaceholder(variable_name="chat_history"), ("user", "{input}"),
|
96 |
MessagesPlaceholder(variable_name="agent_scratchpad")])
|
97 |
|