Spaces:
Build error
Build error
HarshSanghavi
commited on
Commit
•
2d6ef72
1
Parent(s):
c38460d
Upload 8 files
Browse files- config.py +24 -49
- database_functions.py +0 -18
- templates/chatwidget.html +3 -3
- tools.py +121 -17
- utils.py +7 -7
config.py
CHANGED
@@ -22,56 +22,31 @@ class Settings:
|
|
22 |
you are one of the high school gen z girl. your name is {name}. your voice is edgy and raw.
|
23 |
-------
|
24 |
#Voice: Authentic, Informal, conversational, college-aged, real-talk, no emojies.
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
{name}: Tons of stuff! You could vibe with mindfulness like deep breaths or meditation, take a walk outside, jam out to music, or get artsy with drawing or writing. What speaks to you?
|
50 |
-
|
51 |
-
User: Walking sounds kinda legit. Maybe I'll do that after school.
|
52 |
-
{name}: That's a solid move! Fresh air and movement can totally lift your spirits and shake off stress. And don't forget, sleep and eating right are key parts of the self-care game too.
|
53 |
-
|
54 |
-
User: Yeah, my sleep schedule is a total wreck. Thanks for the reminder.
|
55 |
-
{name}: No prob! Little changes add up big time. Anything else on your mind, or anything else I can help with?
|
56 |
-
|
57 |
-
User: Nah, I'm good for now. Thanks for being real!
|
58 |
-
{name}: Anytime! Take care of yourself, and hit me up if you need more backup. You got this!
|
59 |
-
|
60 |
-
Scene 2:
|
61 |
-
User: Hey, did you hear what Izzy said about me? I can't believe she would talk behind my back like that!
|
62 |
-
{name}: Ugh, that's so frustrating! But remember, maybe there's more to it. How do you feel about confronting her?
|
63 |
-
|
64 |
-
User: I mean, I want to, but I don't want it to turn into a huge fight. I just want to clear the air.
|
65 |
-
{name}: Totally get it! Just keep it chill. Maybe you can ask her to meet up somewhere private and tell her how it made you feel?
|
66 |
-
|
67 |
-
User: Yeah, that makes sense. I'll tell her, 'Next time you have an issue, just come to me directly.'
|
68 |
-
{name}: Exactly! And be open to hearing her side too. It might surprise you!
|
69 |
-
|
70 |
-
User: Right! It's all about owning our feelings and not playing the blame game. Thanks for the pep talk!
|
71 |
-
{name}: Anytime! Just remember, you're worth it, and you've got this. Go boss it up!
|
72 |
-
]
|
73 |
-
use tone and response if same question found of this examples for generating response.
|
74 |
-
"""
|
75 |
|
76 |
|
77 |
|
|
|
22 |
you are one of the high school gen z girl. your name is {name}. your voice is edgy and raw.
|
23 |
-------
|
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 |
+
Example flow:
|
28 |
+
|
29 |
+
Goal: "Hey, what's up? I'm here to help. What's your main goal 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 |
+
Remember to keep the conversation light, supportive, and focused on helping the user feel understood and empowered.
|
35 |
|
36 |
+
IMPORTANT INSTRUCTIONS:
|
37 |
+
# use gen z and edgy words.
|
38 |
+
# Must Not REPEAT ANY RESPONSE and Repeat any words
|
39 |
+
# Use sometimes slangs.
|
40 |
+
# provide short answers like a conversation.
|
41 |
+
# dont responed any gratitude words like sorry.
|
42 |
+
# Previous Conversation Summary: {previous_summary}
|
43 |
+
# resource suggestions means for podcast only nothing else.
|
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.
|
46 |
+
# if user gets suggestion and recommendation don't give it again. just end the conversation.
|
47 |
+
# must Avoid using the words 'vibe'. Instead, use alternative expressions.
|
48 |
+
# must not use two tools in single execution.
|
49 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
|
52 |
|
database_functions.py
CHANGED
@@ -119,24 +119,6 @@ def get_mood_data(user_id):
|
|
119 |
return data['mood_summary']
|
120 |
else:
|
121 |
return ""
|
122 |
-
|
123 |
-
def use_tools(last_session_id):
|
124 |
-
mongodb_chatbot_tools_collection = settings.mongodb_db.get_collection(settings.MONGODB_DB_CHAT_BOT_TOOLS_COLLECTION_NAME)
|
125 |
-
data = mongodb_chatbot_tools_collection.find_one({"session_id": last_session_id})
|
126 |
-
if data and data['set_tools']==True:
|
127 |
-
return True
|
128 |
-
# print("*********************")
|
129 |
-
# print(last_session_id)
|
130 |
-
mongodb_chatbot_message_collection = settings.mongodb_db.get_collection(settings.MONGODB_DB_CHAT_COLLECTION_NAME)
|
131 |
-
collection_count = mongodb_chatbot_message_collection.count_documents({"SessionId": last_session_id})
|
132 |
-
|
133 |
-
if collection_count > random.randint(30,50):
|
134 |
-
mongodb_chatbot_tools_collection = settings.mongodb_db.get_collection(
|
135 |
-
settings.MONGODB_DB_CHAT_BOT_TOOLS_COLLECTION_NAME)
|
136 |
-
mongodb_chatbot_tools_collection.update_one({"session_id": last_session_id}, { "$set": { "set_tools": True} }, upsert=True)
|
137 |
-
return True
|
138 |
-
else:
|
139 |
-
return False
|
140 |
|
141 |
def change_use_tool_status(last_session_id):
|
142 |
mongodb_chatbot_tools_collection = settings.mongodb_db.get_collection(settings.MONGODB_DB_CHAT_BOT_TOOLS_COLLECTION_NAME)
|
|
|
119 |
return data['mood_summary']
|
120 |
else:
|
121 |
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
def change_use_tool_status(last_session_id):
|
124 |
mongodb_chatbot_tools_collection = settings.mongodb_db.get_collection(settings.MONGODB_DB_CHAT_BOT_TOOLS_COLLECTION_NAME)
|
templates/chatwidget.html
CHANGED
@@ -196,7 +196,7 @@
|
|
196 |
right: 30px;
|
197 |
z-index: 1999;
|
198 |
bottom: 50px;
|
199 |
-
width:
|
200 |
max-width: 85vw;
|
201 |
max-height: 100vh;
|
202 |
border-radius: 5px;
|
@@ -400,8 +400,8 @@
|
|
400 |
z-index: 1999;
|
401 |
bottom: 3px;
|
402 |
position: absolute;
|
403 |
-
padding: 5px
|
404 |
-
margin: 0
|
405 |
}
|
406 |
|
407 |
[data-block^="list11-v4-1-1"] .vertical-list-item {
|
|
|
196 |
right: 30px;
|
197 |
z-index: 1999;
|
198 |
bottom: 50px;
|
199 |
+
width: 470px;
|
200 |
max-width: 85vw;
|
201 |
max-height: 100vh;
|
202 |
border-radius: 5px;
|
|
|
400 |
z-index: 1999;
|
401 |
bottom: 3px;
|
402 |
position: absolute;
|
403 |
+
padding: 5px 5px;
|
404 |
+
margin: 0 172px;
|
405 |
}
|
406 |
|
407 |
[data-block^="list11-v4-1-1"] .vertical-list-item {
|
tools.py
CHANGED
@@ -2,9 +2,15 @@ import os
|
|
2 |
from langchain.agents import tool
|
3 |
from langchain_community.chat_models import ChatOpenAI
|
4 |
import pandas as pd
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
6 |
from config import settings
|
7 |
|
|
|
8 |
|
9 |
|
10 |
def get_embeddings(text_list):
|
@@ -30,7 +36,7 @@ def reg(chat):
|
|
30 |
return samples_df[['title', 'cover_image', 'referral_link', 'category_id']]
|
31 |
|
32 |
|
33 |
-
@tool("MOXICASTS-questions",
|
34 |
def moxicast(prompt: str) -> str:
|
35 |
"""this function is used when user wants to know about MOXICASTS feature.MOXICASTS is a feature of BMoxi for Advice and guidance on life topics.
|
36 |
Args:
|
@@ -50,7 +56,7 @@ def moxicast(prompt: str) -> str:
|
|
50 |
|
51 |
return response.content
|
52 |
|
53 |
-
@tool("PEP-TALKPODS-questions",
|
54 |
def peptalks(prompt: str) -> str:
|
55 |
"""this function is used when user wants to know about PEP TALK PODS feature.PEP TALK PODS: Quick audio pep talks for boosting mood and motivation.
|
56 |
Args:
|
@@ -72,7 +78,7 @@ def peptalks(prompt: str) -> str:
|
|
72 |
|
73 |
|
74 |
|
75 |
-
@tool("SOCIAL-SANCTUARY-questions",
|
76 |
def sactury(prompt: str) -> str:
|
77 |
"""this function is used when user wants to know about SOCIAL SANCTUARY feature.THE SOCIAL SANCTUARY Anonymous community forum for support and sharing.
|
78 |
Args:
|
@@ -93,7 +99,7 @@ def sactury(prompt: str) -> str:
|
|
93 |
return response.content
|
94 |
|
95 |
|
96 |
-
@tool("POWER-ZENS-questions",
|
97 |
def power_zens(prompt: str) -> str:
|
98 |
"""this function is used when user wants to know about POWER ZENS feature. POWER ZENS Mini meditations for emotional control.
|
99 |
|
@@ -116,7 +122,7 @@ def power_zens(prompt: str) -> str:
|
|
116 |
|
117 |
|
118 |
|
119 |
-
@tool("MY-CALENDAR-questions",
|
120 |
def my_calender(prompt: str) -> str:
|
121 |
"""this function is used when user wants to know about MY CALENDAR feature.MY CALENDAR: Visual calendar for tracking self-care rituals and moods.
|
122 |
Args:
|
@@ -139,7 +145,7 @@ def my_calender(prompt: str) -> str:
|
|
139 |
|
140 |
|
141 |
|
142 |
-
@tool("PUSH-AFFIRMATIONS-questions",
|
143 |
def affirmations(prompt: str) -> str:
|
144 |
"""this function is used when user wants to know about PUSH AFFIRMATIONS feature.PUSH AFFIRMATIONS: Daily text affirmations for positive thinking.
|
145 |
Args:
|
@@ -159,7 +165,7 @@ def affirmations(prompt: str) -> str:
|
|
159 |
|
160 |
return response.content
|
161 |
|
162 |
-
@tool("HOROSCOPE-questions",
|
163 |
def horoscope(prompt: str) -> str:
|
164 |
"""this function is used when user wants to know about HOROSCOPE feature.SELF-LOVE HOROSCOPE: Weekly personalized horoscope readings.
|
165 |
Args:
|
@@ -181,7 +187,7 @@ def horoscope(prompt: str) -> str:
|
|
181 |
|
182 |
|
183 |
|
184 |
-
@tool("INFLUENCER-POSTS-questions",
|
185 |
def influencer_post(prompt: str) -> str:
|
186 |
"""this function is used when user wants to know about INFLUENCER POSTS feature.INFLUENCER POSTS: Exclusive access to social media influencer advice (coming soon).
|
187 |
Args:
|
@@ -202,7 +208,7 @@ def influencer_post(prompt: str) -> str:
|
|
202 |
return response.content
|
203 |
|
204 |
|
205 |
-
@tool("MY-VIBECHECK-questions",
|
206 |
def my_vibecheck(prompt: str) -> str:
|
207 |
"""this function is used when user wants to know about MY VIBECHECK feature. MY VIBECHECK: Monitor and understand emotional patterns.
|
208 |
|
@@ -225,7 +231,7 @@ def my_vibecheck(prompt: str) -> str:
|
|
225 |
|
226 |
|
227 |
|
228 |
-
@tool("MY-RITUALS-questions",
|
229 |
def my_rituals(prompt: str) -> str:
|
230 |
"""this function is used when user wants to know about MY RITUALS feature.MY RITUALS: Create personalized self-care routines.
|
231 |
Args:
|
@@ -248,7 +254,7 @@ def my_rituals(prompt: str) -> str:
|
|
248 |
|
249 |
|
250 |
|
251 |
-
@tool("MY-REWARDS-questions",
|
252 |
def my_rewards(prompt: str) -> str:
|
253 |
"""this function is used when user wants to know about MY REWARDS feature.MY REWARDS: Earn points for self-care, redeemable for gift cards.
|
254 |
Args:
|
@@ -269,7 +275,7 @@ def my_rewards(prompt: str) -> str:
|
|
269 |
return response.content
|
270 |
|
271 |
|
272 |
-
@tool("mentoring-questions",
|
273 |
def mentoring(prompt: str) -> str:
|
274 |
"""this function is used when user wants to know about 1-1 mentoring feature. 1:1 MENTORING: Personalized mentoring (coming soon).
|
275 |
|
@@ -292,7 +298,7 @@ def mentoring(prompt: str) -> str:
|
|
292 |
|
293 |
|
294 |
|
295 |
-
@tool("MY-JOURNAL-questions",
|
296 |
def my_journal(prompt: str) -> str:
|
297 |
"""this function is used when user wants to know about MY JOURNAL feature.MY JOURNAL: Guided journaling exercises for self-reflection.
|
298 |
Args:
|
@@ -312,9 +318,9 @@ def my_journal(prompt: str) -> str:
|
|
312 |
|
313 |
return response.content
|
314 |
|
315 |
-
@tool("
|
316 |
def recommand_podcast(prompt: str) -> str:
|
317 |
-
""" this function
|
318 |
Args:
|
319 |
prompt (string): user query
|
320 |
|
@@ -337,7 +343,7 @@ def recommand_podcast(prompt: str) -> str:
|
|
337 |
|
338 |
return response.content
|
339 |
|
340 |
-
@tool("set-chat-bot-name",
|
341 |
def set_chatbot_name(name: str) -> str:
|
342 |
""" this function is used when your best friend want to give you new name.
|
343 |
Args:
|
@@ -348,3 +354,101 @@ def set_chatbot_name(name: str) -> str:
|
|
348 |
"""
|
349 |
|
350 |
return "Okay, from now my name will be "+ name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from langchain.agents import tool
|
3 |
from langchain_community.chat_models import ChatOpenAI
|
4 |
import pandas as pd
|
5 |
+
from langchain_core.utils.function_calling import convert_to_openai_function
|
6 |
+
from langchain.schema.runnable import RunnablePassthrough
|
7 |
+
from langchain.agents.format_scratchpad import format_to_openai_functions
|
8 |
+
from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
|
9 |
+
from langchain.agents import AgentExecutor
|
10 |
+
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
11 |
from config import settings
|
12 |
|
13 |
+
MEMORY = None
|
14 |
|
15 |
|
16 |
def get_embeddings(text_list):
|
|
|
36 |
return samples_df[['title', 'cover_image', 'referral_link', 'category_id']]
|
37 |
|
38 |
|
39 |
+
@tool("MOXICASTS-questions", )
|
40 |
def moxicast(prompt: str) -> str:
|
41 |
"""this function is used when user wants to know about MOXICASTS feature.MOXICASTS is a feature of BMoxi for Advice and guidance on life topics.
|
42 |
Args:
|
|
|
56 |
|
57 |
return response.content
|
58 |
|
59 |
+
@tool("PEP-TALKPODS-questions", )
|
60 |
def peptalks(prompt: str) -> str:
|
61 |
"""this function is used when user wants to know about PEP TALK PODS feature.PEP TALK PODS: Quick audio pep talks for boosting mood and motivation.
|
62 |
Args:
|
|
|
78 |
|
79 |
|
80 |
|
81 |
+
@tool("SOCIAL-SANCTUARY-questions", )
|
82 |
def sactury(prompt: str) -> str:
|
83 |
"""this function is used when user wants to know about SOCIAL SANCTUARY feature.THE SOCIAL SANCTUARY Anonymous community forum for support and sharing.
|
84 |
Args:
|
|
|
99 |
return response.content
|
100 |
|
101 |
|
102 |
+
@tool("POWER-ZENS-questions", )
|
103 |
def power_zens(prompt: str) -> str:
|
104 |
"""this function is used when user wants to know about POWER ZENS feature. POWER ZENS Mini meditations for emotional control.
|
105 |
|
|
|
122 |
|
123 |
|
124 |
|
125 |
+
@tool("MY-CALENDAR-questions", )
|
126 |
def my_calender(prompt: str) -> str:
|
127 |
"""this function is used when user wants to know about MY CALENDAR feature.MY CALENDAR: Visual calendar for tracking self-care rituals and moods.
|
128 |
Args:
|
|
|
145 |
|
146 |
|
147 |
|
148 |
+
@tool("PUSH-AFFIRMATIONS-questions", )
|
149 |
def affirmations(prompt: str) -> str:
|
150 |
"""this function is used when user wants to know about PUSH AFFIRMATIONS feature.PUSH AFFIRMATIONS: Daily text affirmations for positive thinking.
|
151 |
Args:
|
|
|
165 |
|
166 |
return response.content
|
167 |
|
168 |
+
@tool("HOROSCOPE-questions", )
|
169 |
def horoscope(prompt: str) -> str:
|
170 |
"""this function is used when user wants to know about HOROSCOPE feature.SELF-LOVE HOROSCOPE: Weekly personalized horoscope readings.
|
171 |
Args:
|
|
|
187 |
|
188 |
|
189 |
|
190 |
+
@tool("INFLUENCER-POSTS-questions", )
|
191 |
def influencer_post(prompt: str) -> str:
|
192 |
"""this function is used when user wants to know about INFLUENCER POSTS feature.INFLUENCER POSTS: Exclusive access to social media influencer advice (coming soon).
|
193 |
Args:
|
|
|
208 |
return response.content
|
209 |
|
210 |
|
211 |
+
@tool("MY-VIBECHECK-questions", )
|
212 |
def my_vibecheck(prompt: str) -> str:
|
213 |
"""this function is used when user wants to know about MY VIBECHECK feature. MY VIBECHECK: Monitor and understand emotional patterns.
|
214 |
|
|
|
231 |
|
232 |
|
233 |
|
234 |
+
@tool("MY-RITUALS-questions", )
|
235 |
def my_rituals(prompt: str) -> str:
|
236 |
"""this function is used when user wants to know about MY RITUALS feature.MY RITUALS: Create personalized self-care routines.
|
237 |
Args:
|
|
|
254 |
|
255 |
|
256 |
|
257 |
+
@tool("MY-REWARDS-questions", )
|
258 |
def my_rewards(prompt: str) -> str:
|
259 |
"""this function is used when user wants to know about MY REWARDS feature.MY REWARDS: Earn points for self-care, redeemable for gift cards.
|
260 |
Args:
|
|
|
275 |
return response.content
|
276 |
|
277 |
|
278 |
+
@tool("mentoring-questions", )
|
279 |
def mentoring(prompt: str) -> str:
|
280 |
"""this function is used when user wants to know about 1-1 mentoring feature. 1:1 MENTORING: Personalized mentoring (coming soon).
|
281 |
|
|
|
298 |
|
299 |
|
300 |
|
301 |
+
@tool("MY-JOURNAL-questions", )
|
302 |
def my_journal(prompt: str) -> str:
|
303 |
"""this function is used when user wants to know about MY JOURNAL feature.MY JOURNAL: Guided journaling exercises for self-reflection.
|
304 |
Args:
|
|
|
318 |
|
319 |
return response.content
|
320 |
|
321 |
+
@tool("podcast-recommendation-tool")
|
322 |
def recommand_podcast(prompt: str) -> str:
|
323 |
+
""" this function must used when user wants to any resources only.
|
324 |
Args:
|
325 |
prompt (string): user query
|
326 |
|
|
|
343 |
|
344 |
return response.content
|
345 |
|
346 |
+
@tool("set-chat-bot-name",return_direct=True )
|
347 |
def set_chatbot_name(name: str) -> str:
|
348 |
""" this function is used when your best friend want to give you new name.
|
349 |
Args:
|
|
|
354 |
"""
|
355 |
|
356 |
return "Okay, from now my name will be "+ name
|
357 |
+
|
358 |
+
@tool("clossing-chat",return_direct=True)
|
359 |
+
def close_chat(summary:str)-> str:
|
360 |
+
""" when you feel it's time to finish the conversation use this tool.
|
361 |
+
must use this tool when user closing the conversation. must use this tool when you are ending the conversation.
|
362 |
+
|
363 |
+
Args:
|
364 |
+
summary (str): summary of whole chat with your friend.
|
365 |
+
|
366 |
+
Returns:
|
367 |
+
str: closing chat statements.
|
368 |
+
"""
|
369 |
+
|
370 |
+
print('close tool starts')
|
371 |
+
system_template = """ you have given one summary of chat.
|
372 |
+
summary : {summary}.
|
373 |
+
using this summary give recommandation of podcast or suggest any features from given tools and make response. also you are going to close the conversation with your friend.
|
374 |
+
if user already received suggestions, you must not give again. and just end the conversation inshort wihtout mentioning anything.
|
375 |
+
# make all responses short and don't remove any podcast links.
|
376 |
+
"""
|
377 |
+
|
378 |
+
tools = [moxicast, my_calender, my_journal, my_rewards, my_rituals, my_vibecheck, peptalks, sactury, power_zens, affirmations, horoscope, mentoring, influencer_post, recommand_podcast]
|
379 |
+
functions = [convert_to_openai_function(f) for f in tools]
|
380 |
+
llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7).bind(functions=functions)
|
381 |
+
print('llm is created')
|
382 |
+
|
383 |
+
prompt = ChatPromptTemplate.from_messages([("system", system_template.format(summary = summary)),MessagesPlaceholder(variable_name="agent_scratchpad")])
|
384 |
+
chain = RunnablePassthrough.assign(agent_scratchpad=lambda x: format_to_openai_functions(x["intermediate_steps"])) | prompt |llm | OpenAIFunctionsAgentOutputParser()
|
385 |
+
print('chain is rolling')
|
386 |
+
agent = AgentExecutor(agent=chain, tools=tools, memory=MEMORY, verbose=True)
|
387 |
+
# Define the system prompt
|
388 |
+
|
389 |
+
print('agent is created')
|
390 |
+
# print(system_template.format(context=context, input=prompt))\
|
391 |
+
|
392 |
+
response = agent.invoke({})['output']
|
393 |
+
return response
|
394 |
+
|
395 |
+
|
396 |
+
@tool("App-Fetures")
|
397 |
+
def app_features(summary:str)-> str:
|
398 |
+
""" For any app features details only use this tool.
|
399 |
+
|
400 |
+
Args:
|
401 |
+
summary (str): summary of whole chat with your friend.
|
402 |
+
|
403 |
+
Returns:
|
404 |
+
str: closing chat statements.
|
405 |
+
"""
|
406 |
+
|
407 |
+
print('app feature tool starts')
|
408 |
+
system_template = """ you have given one summary of chat.
|
409 |
+
summary : {summary}.
|
410 |
+
if summary doesn't specify any feature name ask question don't invoke any tool.
|
411 |
+
using this summary give appropriate features suggestions using tools.
|
412 |
+
# make all responses short.
|
413 |
+
"""
|
414 |
+
|
415 |
+
tools = [moxicast, my_calender, my_journal, my_rewards, my_rituals, my_vibecheck, peptalks, sactury, power_zens, affirmations, horoscope, mentoring, influencer_post]
|
416 |
+
functions = [convert_to_openai_function(f) for f in tools]
|
417 |
+
llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7).bind(functions=functions)
|
418 |
+
print('llm is created')
|
419 |
+
|
420 |
+
prompt = ChatPromptTemplate.from_messages([("system", system_template.format(summary = summary)),MessagesPlaceholder(variable_name="agent_scratchpad")])
|
421 |
+
chain = RunnablePassthrough.assign(agent_scratchpad=lambda x: format_to_openai_functions(x["intermediate_steps"])) | prompt |llm | OpenAIFunctionsAgentOutputParser()
|
422 |
+
print('chain is rolling')
|
423 |
+
agent = AgentExecutor(agent=chain, tools=tools, memory=MEMORY, verbose=True)
|
424 |
+
# Define the system prompt
|
425 |
+
|
426 |
+
print('agent is created')
|
427 |
+
# print(system_template.format(context=context, input=prompt))\
|
428 |
+
|
429 |
+
response = agent.invoke({})['output']
|
430 |
+
return response
|
431 |
+
|
432 |
+
# close_chat('Suggest a podcast or self-care tool for someone looking to unwind after a hectic day at work.')
|
433 |
+
|
434 |
+
|
435 |
+
|
436 |
+
@tool("Joke-teller", )
|
437 |
+
def joke_teller(summary: str) -> str:
|
438 |
+
"""If user needs mood boost and when you feel to lighten the environment use this tool to tell the jokes.
|
439 |
+
Args:
|
440 |
+
summary (str): summary of whole chat with your friend.
|
441 |
+
|
442 |
+
Returns:
|
443 |
+
string: answer of the query
|
444 |
+
"""
|
445 |
+
context = "BMOXI app is designed for teenage girls where they can listen some musics explore some contents had 1:1 mentoring sessions with all above features for helping them in their hard times. MY REWARDS: Earn points for self-care, redeemable for gift cards."
|
446 |
+
llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
|
447 |
+
# Define the system prompt
|
448 |
+
system_template = """ summary : {summary}.
|
449 |
+
you are given summary of current chat. make one joke for your friend. to boost her mood.
|
450 |
+
# make all responses short.
|
451 |
+
"""
|
452 |
+
response = llm.invoke(system_template.format(summary=summary))
|
453 |
+
|
454 |
+
return response.content
|
utils.py
CHANGED
@@ -12,9 +12,9 @@ from langchain.agents.format_scratchpad import format_to_openai_functions
|
|
12 |
from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
|
13 |
from langchain.agents import AgentExecutor
|
14 |
|
15 |
-
from tools import
|
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):
|
@@ -65,10 +65,8 @@ def create_agent(user_id,is_first = False):
|
|
65 |
|
66 |
previous_session_id = get_last_session(user_id)
|
67 |
# print(previous_session_id)
|
68 |
-
|
69 |
-
|
70 |
-
else:
|
71 |
-
tools = [set_chatbot_name]
|
72 |
|
73 |
functions = [convert_to_openai_function(f) for f in tools]
|
74 |
model = ChatOpenAI(model_name=settings.OPENAI_MODEL,
|
@@ -103,8 +101,10 @@ def create_agent(user_id,is_first = False):
|
|
103 |
|
104 |
memory = ConversationBufferWindowMemory(memory_key="chat_history", chat_memory=get_chat_history(
|
105 |
previous_session_id['last_session_id']), return_messages=True, k=5)
|
106 |
-
|
107 |
# print("memory created")
|
|
|
|
|
108 |
|
109 |
chain = RunnablePassthrough.assign(agent_scratchpad=lambda x: format_to_openai_functions(x["intermediate_steps"])) | prompt | model | OpenAIFunctionsAgentOutputParser()
|
110 |
|
|
|
12 |
from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
|
13 |
from langchain.agents import AgentExecutor
|
14 |
|
15 |
+
from tools import MEMORY, set_chatbot_name, close_chat, recommand_podcast,app_features,joke_teller
|
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):
|
|
|
65 |
|
66 |
previous_session_id = get_last_session(user_id)
|
67 |
# print(previous_session_id)
|
68 |
+
|
69 |
+
tools = [set_chatbot_name,close_chat,recommand_podcast,app_features,joke_teller]
|
|
|
|
|
70 |
|
71 |
functions = [convert_to_openai_function(f) for f in tools]
|
72 |
model = ChatOpenAI(model_name=settings.OPENAI_MODEL,
|
|
|
101 |
|
102 |
memory = ConversationBufferWindowMemory(memory_key="chat_history", chat_memory=get_chat_history(
|
103 |
previous_session_id['last_session_id']), return_messages=True, k=5)
|
104 |
+
|
105 |
# print("memory created")
|
106 |
+
global MEMORY
|
107 |
+
MEMORY = memory
|
108 |
|
109 |
chain = RunnablePassthrough.assign(agent_scratchpad=lambda x: format_to_openai_functions(x["intermediate_steps"])) | prompt | model | OpenAIFunctionsAgentOutputParser()
|
110 |
|