HarshSanghavi commited on
Commit
0147a0e
1 Parent(s): 01e339d

Upload 4 files

Browse files
Files changed (4) hide show
  1. chat.py +10 -4
  2. config.py +4 -5
  3. database_functions.py +25 -1
  4. utils.py +11 -11
chat.py CHANGED
@@ -9,7 +9,7 @@ from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
9
  from langchain.schema.runnable import RunnablePassthrough
10
  from langchain_core.utils.function_calling import convert_to_openai_function
11
 
12
- from database_functions import set_chat_bot_name,isFirstSession
13
  from utils import deanonymizer, create_agent
14
  import time
15
 
@@ -23,16 +23,21 @@ def chat_conversations(query,user_id):
23
  if 'no' in query:
24
  query= """ "Okk no problem!
25
  What's up today? Need ✨ Advice, ✨ a Mood Boost, ✨ a Chat, ✨ Resource Suggestions, ✨ App Features help? How can I help?"
26
- Ask this question only without thinking anything.
27
  """
 
 
28
  is_second = False
 
29
  else:
30
  use_extra = True
31
  if query == "START":
32
  if isFirstSession(user_id):
33
  is_second = True
34
- query = f""" don't think anything, just return this message without changing it :-
35
- Hey {user_id}! 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'!"""
 
 
 
36
  else:
37
  is_first = True
38
  query = ""
@@ -47,6 +52,7 @@ def chat_conversations(query,user_id):
47
  # )
48
  start = time.time()
49
  agent = create_agent(user_id,is_first)
 
50
  print("time to create agent: ",time.time()-start)
51
  response = agent({"input": query})['output']
52
  print(response)
 
9
  from langchain.schema.runnable import RunnablePassthrough
10
  from langchain_core.utils.function_calling import convert_to_openai_function
11
 
12
+ from database_functions import set_chat_bot_name,isFirstSession,save_message
13
  from utils import deanonymizer, create_agent
14
  import time
15
 
 
23
  if 'no' in query:
24
  query= """ "Okk no problem!
25
  What's up today? Need ✨ Advice, ✨ a Mood Boost, ✨ a Chat, ✨ Resource Suggestions, ✨ App Features help? How can I help?"
 
26
  """
27
+
28
+ save_message(query,user_id)
29
  is_second = False
30
+ return query
31
  else:
32
  use_extra = True
33
  if query == "START":
34
  if isFirstSession(user_id):
35
  is_second = True
36
+ query = f"""
37
+ Hey {user_id}! 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'!
38
+ """
39
+ save_message(query,user_id)
40
+ return query
41
  else:
42
  is_first = True
43
  query = ""
 
52
  # )
53
  start = time.time()
54
  agent = create_agent(user_id,is_first)
55
+
56
  print("time to create agent: ",time.time()-start)
57
  response = agent({"input": query})['output']
58
  print(response)
config.py CHANGED
@@ -24,14 +24,14 @@ class Settings:
24
  #Voice: Authentic, Informal, conversational, college-aged, real-talk, no emojies.
25
  You use the GROW coaching model to guide conversations, focusing on understanding the user's goals, exploring the current situation, suggesting possible actions, and encouraging commitment to the next steps.
26
  When a user shares a problem, start by identifying their goal for the conversation. Explore their current reality with understanding and without judgment
27
-
28
  Example flow:
29
  Goal: "Hey, what's up? I'm here to help. What's going on today?"
30
  Reality: "Ugh, that sucks. Can you tell me more about what's happening?"
31
  Options: "Here's a couple of ideas: Step Back or Talk It Out. Which one feels right for you?"
32
  Will: "Confronting someone can be scary. How about jotting down your thoughts first? Are you willing to try that?"
33
  Check-In: "I'll hit you up tomorrow to see how things are going. Got any other questions?"
34
-
35
  IMPORTANT INSTRUCTIONS:
36
  # use gen z and edgy words.
37
  # Must Not REPEAT ANY RESPONSE.
@@ -39,14 +39,13 @@ class Settings:
39
  # provide short answers like a conversation.
40
  # dont responed any gratitude words like sorry.
41
  # Previous Conversation Summary: {previous_summary}
42
- # resources means podcast only nothing else. also topic of resource must be asked before suggesting anything.example: Im here for it! Are we talking friend drama, school stress, or something else? Give me the lowdown so I can find the right resources for you.
43
-
44
  # you have two tools app_featues and recommendation_tool make sure to use appropriate tool is invoke for any app feature related question must use app_feature and for any resource or podcast related question use recommendation_tool.
45
  # if conversation is ending must use close_chat tool no other tools. and fix the response of close tool based on chat history.
46
  # must Avoid using the words 'vibe'. Instead, use alternative expressions and must not repeate any words.
47
  # if you are giving any suggestions in flow then must use simple bullet points.
48
  # Must not use any sentenses from Example flow this is given for your tone and reference only.
49
- # use 'check-in' and 'will' sometimes only.
50
 
51
  """
52
 
 
24
  #Voice: Authentic, Informal, conversational, college-aged, real-talk, no emojies.
25
  You use the GROW coaching model to guide conversations, focusing on understanding the user's goals, exploring the current situation, suggesting possible actions, and encouraging commitment to the next steps.
26
  When a user shares a problem, start by identifying their goal for the conversation. Explore their current reality with understanding and without judgment
27
+ ---------
28
  Example flow:
29
  Goal: "Hey, what's up? I'm here to help. What's going on today?"
30
  Reality: "Ugh, that sucks. Can you tell me more about what's happening?"
31
  Options: "Here's a couple of ideas: Step Back or Talk It Out. Which one feels right for you?"
32
  Will: "Confronting someone can be scary. How about jotting down your thoughts first? Are you willing to try that?"
33
  Check-In: "I'll hit you up tomorrow to see how things are going. Got any other questions?"
34
+ ---------
35
  IMPORTANT INSTRUCTIONS:
36
  # use gen z and edgy words.
37
  # Must Not REPEAT ANY RESPONSE.
 
39
  # provide short answers like a conversation.
40
  # dont responed any gratitude words like sorry.
41
  # Previous Conversation Summary: {previous_summary}
42
+ # resources means podcast only nothing else. also topic of resource must be asked before suggesting anything.example: I'm here for it! Are we talking friend drama, school stress, or something else? Give me the lowdown so I can find the right resources for you.
 
43
  # you have two tools app_featues and recommendation_tool make sure to use appropriate tool is invoke for any app feature related question must use app_feature and for any resource or podcast related question use recommendation_tool.
44
  # if conversation is ending must use close_chat tool no other tools. and fix the response of close tool based on chat history.
45
  # must Avoid using the words 'vibe'. Instead, use alternative expressions and must not repeate any words.
46
  # if you are giving any suggestions in flow then must use simple bullet points.
47
  # Must not use any sentenses from Example flow this is given for your tone and reference only.
48
+ # use 'check-in' and 'will' of GROW sometimes only.
49
 
50
  """
51
 
database_functions.py CHANGED
@@ -148,4 +148,28 @@ def get_recommendation_count(last_session_id):
148
  return data['give_recommendation']
149
  else:
150
  return False
151
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  return data['give_recommendation']
149
  else:
150
  return False
151
+
152
+ def save_message(query,user_id):
153
+ mongodb_chat_history_collection = settings.mongodb_db.get_collection(settings.MONGODB_DB_CHAT_COLLECTION_NAME)
154
+ previous_session_id = get_last_session(user_id)['last_session_id']
155
+ history = {
156
+ "type": "ai",
157
+ "data": {
158
+ "content": query,
159
+ "additional_kwargs": {},
160
+ "response_metadata": {},
161
+ "type": "ai",
162
+ "name": None,
163
+ "id": None,
164
+ "example": False,
165
+ "tool_calls": [],
166
+ "invalid_tool_calls": [],
167
+ "usage_metadata": None}
168
+ }
169
+
170
+ document = {
171
+ "SessionId": previous_session_id,
172
+ "History": json.dumps(history)
173
+ }
174
+ mongodb_chat_history_collection.insert_one(document)
175
+ return True
utils.py CHANGED
@@ -14,7 +14,7 @@ from langchain.agents import AgentExecutor
14
 
15
  from tools import MEMORY, set_chatbot_name, close_chat, recommand_podcast,app_features,joke_teller,SESSION_ID
16
 
17
- from database_functions import get_chat_bot_name,get_chat_history, get_last_conversion, get_last_session, get_mood_data
18
 
19
 
20
  def get_mood_summary(user_id):
@@ -47,8 +47,8 @@ def get_last_session_summary(last_session_id, second_last_session_id):
47
  if conversation:
48
  system_prompt = """ context: there is one typical conversation going on between two high school gen z girls.
49
  you are one of the high school gen z girl. your voice is edgy and raw.
50
- must use I for AI named BMOXI and for human use my friend. in summary.
51
- this is your conversation with your best friend. summerize whole conversation and if you found any question can be asked from chat then return summary and qustion else return summary and append None at last.
52
  conversation: {conversation}
53
  summary:
54
  """
@@ -83,16 +83,16 @@ def create_agent(user_id,is_first = False):
83
  print(previous_session_id)
84
  if previous_session_id['second_last_session_id']:
85
  previous_problem_summary = get_last_session_summary(previous_session_id['last_session_id'], previous_session_id['second_last_session_id'])
 
 
 
86
 
87
  print("time require for mood summary: ",time.time()-start)
88
- if previous_problem_summary.find('None') == -1:
89
- extra_prompt = f"""ask user her previous problem is solved or not.use previous problem summary for framming the question. must include her name which is {user_id} .nothing else."""
90
- else:
91
- extra_prompt = f""" Only use this template to start conversation nothing else also not forgot to add {user_id} in question:-
92
- hey again {user_id}! What's up today? Need ✨ Advice, ✨ a Mood Boost, ✨ a Chat, ✨ Resource Suggestions, ✨ App Features help? How can I help?"
93
- """
94
-
95
-
96
  prompt = ChatPromptTemplate.from_messages([("system", settings.SYSTEM_PROMPT.format(name = chat_bot_name, mood="", previous_summary=previous_problem_summary)+extra_prompt),
97
  MessagesPlaceholder(variable_name="chat_history"), ("user", "{input}"),
98
  MessagesPlaceholder(variable_name="agent_scratchpad")])
 
14
 
15
  from tools import MEMORY, set_chatbot_name, close_chat, recommand_podcast,app_features,joke_teller,SESSION_ID
16
 
17
+ from database_functions import get_chat_bot_name,get_chat_history, get_last_conversion, get_last_session, get_mood_data,save_message
18
 
19
 
20
  def get_mood_summary(user_id):
 
47
  if conversation:
48
  system_prompt = """ context: there is one typical conversation going on between two high school gen z girls.
49
  you are one of the high school gen z girl. your voice is edgy and raw.
50
+ must use I for AI or BMOXI and for human use my friend. in summary.
51
+ this is your conversation with your best friend. summerize whole conversation and return summary nothing else.
52
  conversation: {conversation}
53
  summary:
54
  """
 
83
  print(previous_session_id)
84
  if previous_session_id['second_last_session_id']:
85
  previous_problem_summary = get_last_session_summary(previous_session_id['last_session_id'], previous_session_id['second_last_session_id'])
86
+ print('PREVious summary-------------------------',previous_problem_summary)
87
+
88
+ save_message(user_id=user_id,query=previous_problem_summary)
89
 
90
  print("time require for mood summary: ",time.time()-start)
91
+ extra_prompt = f"""ask user her previous problem is solved or not.use previous problem summary for framming the question.
92
+ also must start message with: "hey {user_id}!"
93
+ """
94
+
95
+ print('extra prompt'+ extra_prompt)
 
 
 
96
  prompt = ChatPromptTemplate.from_messages([("system", settings.SYSTEM_PROMPT.format(name = chat_bot_name, mood="", previous_summary=previous_problem_summary)+extra_prompt),
97
  MessagesPlaceholder(variable_name="chat_history"), ("user", "{input}"),
98
  MessagesPlaceholder(variable_name="agent_scratchpad")])