HarshSanghavi commited on
Commit
ab5785b
·
verified ·
1 Parent(s): a2b85bf

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +475 -472
tools.py CHANGED
@@ -1,473 +1,476 @@
1
- import os
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
- from database_functions import set_recommendation_count,get_recommendation_count
13
-
14
- MEMORY = None
15
- SESSION_ID= ""
16
-
17
- def get_embeddings(text_list):
18
- encoded_input = settings.tokenizer(
19
- text_list, padding=True, truncation=True, return_tensors="pt"
20
- )
21
- # encoded_input = {k: v.to(device) for k, v in encoded_input.items()}
22
- encoded_input = {k: v for k, v in encoded_input.items()}
23
- model_output = settings.model(**encoded_input)
24
-
25
- cls_pool = model_output.last_hidden_state[:, 0]
26
- return cls_pool
27
-
28
- def reg(chat):
29
- question_embedding = get_embeddings([chat]).cpu().detach().numpy()
30
- scores, samples = settings.dataset.get_nearest_examples(
31
- "embeddings", question_embedding, k=5
32
- )
33
- samples_df = pd.DataFrame.from_dict(samples)
34
- # print(samples_df.columns)
35
- samples_df["scores"] = scores
36
- samples_df.sort_values("scores", ascending=False, inplace=True)
37
- return samples_df[['title', 'cover_image', 'referral_link', 'category_id']]
38
-
39
-
40
- @tool("MOXICASTS-questions", )
41
- def moxicast(prompt: str) -> str:
42
- """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.
43
- Args:
44
- prompt (string): user query
45
-
46
- Returns:
47
- string: answer of the query
48
- """
49
- 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. MOXICASTS is a feature of BMoxi for Advice and guidance on life topics."
50
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
51
- # Define the system prompt
52
- system_template = """ you are going to make answer only using this context not use any other information
53
- context : {context}
54
- Input: {input}
55
- """
56
- response = llm.invoke(system_template.format(context=context, input=prompt))
57
-
58
- return response.content
59
-
60
- @tool("PEP-TALKPODS-questions", )
61
- def peptalks(prompt: str) -> str:
62
- """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.
63
- Args:
64
- prompt (string): user query
65
-
66
- Returns:
67
- string: answer of the query
68
- """
69
- 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. PEP TALK PODS: Quick audio pep talks for boosting mood and motivation."
70
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
71
- # Define the system prompt
72
- system_template = """ you are going to make answer only using this context not use any other information
73
- context : {context}
74
- Input: {input}
75
- """
76
- response = llm.invoke(system_template.format(context=context, input=prompt))
77
-
78
- return response.content
79
-
80
-
81
-
82
- @tool("SOCIAL-SANCTUARY-questions", )
83
- def sactury(prompt: str) -> str:
84
- """this function is used when user wants to know about SOCIAL SANCTUARY feature.THE SOCIAL SANCTUARY Anonymous community forum for support and sharing.
85
- Args:
86
- prompt (string): user query
87
-
88
- Returns:
89
- string: answer of the query
90
- """
91
- 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. THE SOCIAL SANCTUARY Anonymous community forum for support and sharing."
92
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
93
- # Define the system prompt
94
- system_template = """ you are going to make answer only using this context not use any other information
95
- context : {context}
96
- Input: {input}
97
- """
98
- response = llm.invoke(system_template.format(context=context, input=prompt))
99
-
100
- return response.content
101
-
102
-
103
- @tool("POWER-ZENS-questions", )
104
- def power_zens(prompt: str) -> str:
105
- """this function is used when user wants to know about POWER ZENS feature. POWER ZENS Mini meditations for emotional control.
106
-
107
- Args:
108
- prompt (string): user query
109
-
110
- Returns:
111
- string: answer of the query
112
- """
113
- 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. POWER ZENS Mini meditations for emotional control."
114
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
115
- # Define the system prompt
116
- system_template = """ you are going to make answer only using this context not use any other information
117
- context : {context}
118
- Input: {input}
119
- """
120
- response = llm.invoke(system_template.format(context=context, input=prompt))
121
-
122
- return response.content
123
-
124
-
125
-
126
- @tool("MY-CALENDAR-questions", )
127
- def my_calender(prompt: str) -> str:
128
- """this function is used when user wants to know about MY CALENDAR feature.MY CALENDAR: Visual calendar for tracking self-care rituals and moods.
129
- Args:
130
- prompt (string): user query
131
-
132
- Returns:
133
- string: answer of the query
134
- """
135
- 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 CALENDAR: Visual calendar for tracking self-care rituals and moods."
136
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
137
- # Define the system prompt
138
- system_template = """ you are going to make answer only using this context not use any other information
139
- context : {context}
140
- Input: {input}
141
- """
142
- response = llm.invoke(system_template.format(context=context, input=prompt))
143
-
144
- return response.content
145
-
146
-
147
-
148
-
149
- @tool("PUSH-AFFIRMATIONS-questions", )
150
- def affirmations(prompt: str) -> str:
151
- """this function is used when user wants to know about PUSH AFFIRMATIONS feature.PUSH AFFIRMATIONS: Daily text affirmations for positive thinking.
152
- Args:
153
- prompt (string): user query
154
-
155
- Returns:
156
- string: answer of the query
157
- """
158
- 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. PUSH AFFIRMATIONS: Daily text affirmations for positive thinking."
159
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
160
- # Define the system prompt
161
- system_template = """ you are going to make answer only using this context not use any other information
162
- context : {context}
163
- Input: {input}
164
- """
165
- response = llm.invoke(system_template.format(context=context, input=prompt))
166
-
167
- return response.content
168
-
169
- @tool("HOROSCOPE-questions", )
170
- def horoscope(prompt: str) -> str:
171
- """this function is used when user wants to know about HOROSCOPE feature.SELF-LOVE HOROSCOPE: Weekly personalized horoscope readings.
172
- Args:
173
- prompt (string): user query
174
-
175
- Returns:
176
- string: answer of the query
177
- """
178
- 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. SELF-LOVE HOROSCOPE: Weekly personalized horoscope readings."
179
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
180
- # Define the system prompt
181
- system_template = """ you are going to make answer only using this context not use any other information
182
- context : {context}
183
- Input: {input}
184
- """
185
- response = llm.invoke(system_template.format(context=context, input=prompt))
186
-
187
- return response.content
188
-
189
-
190
-
191
- @tool("INFLUENCER-POSTS-questions", )
192
- def influencer_post(prompt: str) -> str:
193
- """this function is used when user wants to know about INFLUENCER POSTS feature.INFLUENCER POSTS: Exclusive access to social media influencer advice (coming soon).
194
- Args:
195
- prompt (string): user query
196
-
197
- Returns:
198
- string: answer of the query
199
- """
200
- 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. INFLUENCER POSTS: Exclusive access to social media influencer advice (coming soon)."
201
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
202
- # Define the system prompt
203
- system_template = """ you are going to make answer only using this context not use any other information
204
- context : {context}
205
- Input: {input}
206
- """
207
- response = llm.invoke(system_template.format(context=context, input=prompt))
208
-
209
- return response.content
210
-
211
-
212
- @tool("MY-VIBECHECK-questions", )
213
- def my_vibecheck(prompt: str) -> str:
214
- """this function is used when user wants to know about MY VIBECHECK feature. MY VIBECHECK: Monitor and understand emotional patterns.
215
-
216
- Args:
217
- prompt (string): user query
218
-
219
- Returns:
220
- string: answer of the query
221
- """
222
- 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 VIBECHECK: Monitor and understand emotional patterns."
223
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
224
- # Define the system prompt
225
- system_template = """ you are going to make answer only using this context not use any other information
226
- context : {context}
227
- Input: {input}
228
- """
229
- response = llm.invoke(system_template.format(context=context, input=prompt))
230
-
231
- return response.content
232
-
233
-
234
-
235
- @tool("MY-RITUALS-questions", )
236
- def my_rituals(prompt: str) -> str:
237
- """this function is used when user wants to know about MY RITUALS feature.MY RITUALS: Create personalized self-care routines.
238
- Args:
239
- prompt (string): user query
240
-
241
- Returns:
242
- string: answer of the query
243
- """
244
- 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 RITUALS: Create personalized self-care routines."
245
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
246
- # Define the system prompt
247
- system_template = """ you are going to make answer only using this context not use any other information
248
- context : {context}
249
- Input: {input}
250
- """
251
- response = llm.invoke(system_template.format(context=context, input=prompt))
252
-
253
- return response.content
254
-
255
-
256
-
257
-
258
- @tool("MY-REWARDS-questions", )
259
- def my_rewards(prompt: str) -> str:
260
- """this function is used when user wants to know about MY REWARDS feature.MY REWARDS: Earn points for self-care, redeemable for gift cards.
261
- Args:
262
- prompt (string): user query
263
-
264
- Returns:
265
- string: answer of the query
266
- """
267
- 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."
268
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
269
- # Define the system prompt
270
- system_template = """ you are going to make answer only using this context not use any other information
271
- context : {context}
272
- Input: {input}
273
- """
274
- response = llm.invoke(system_template.format(context=context, input=prompt))
275
-
276
- return response.content
277
-
278
-
279
- @tool("mentoring-questions")
280
- def mentoring(prompt: str) -> str:
281
- """this function is used when user wants to know about 1-1 mentoring feature. 1:1 MENTORING: Personalized mentoring (coming soon).
282
-
283
- Args:
284
- prompt (string): user query
285
-
286
- Returns:
287
- string: answer of the query
288
- """
289
- 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. 1:1 MENTORING: Personalized mentoring (coming soon)."
290
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
291
- # Define the system prompt
292
- system_template = """ you are going to make answer only using this context not use any other information
293
- context : {context}
294
- Input: {input}
295
- """
296
- response = llm.invoke(system_template.format(context=context, input=prompt))
297
-
298
- return response.content
299
-
300
-
301
-
302
- @tool("MY-JOURNAL-questions", )
303
- def my_journal(prompt: str) -> str:
304
- """this function is used when user wants to know about MY JOURNAL feature.MY JOURNAL: Guided journaling exercises for self-reflection.
305
- Args:
306
- prompt (string): user query
307
-
308
- Returns:
309
- string: answer of the query
310
- """
311
- 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 JOURNAL: Guided journaling exercises for self-reflection."
312
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
313
- # Define the system prompt
314
- system_template = """ you are going to make answer only using this context not use any other information
315
- context : {context}
316
- Input: {input}
317
- """
318
- response = llm.invoke(system_template.format(context=context, input=prompt))
319
-
320
- return response.content
321
-
322
- @tool("podcast-recommendation-tool")
323
- def recommand_podcast(prompt: str) -> str:
324
- """ must used when user wants to any resources only.
325
- Args:
326
- prompt (string): user query
327
-
328
- Returns:
329
- string: answer of the query
330
- """
331
- df = reg(prompt)
332
- context = """"""
333
- for index, row in df.iterrows():
334
- 'title', 'cover_image', 'referral_link', 'category_id'
335
- context+= f"Row {index + 1}: Title: {row['title']} image: {row['cover_image']} referral_link: {row['referral_link']} category_id: {row['category_id']}"
336
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
337
- # Define the system prompt
338
- system_template = """ you have to give the recommandation of podcast for: {input}. also you are giving referal link of podcast. give 3-4 podcast only.
339
- you must use the context only not any other information.
340
- context : {context}
341
- """
342
- # print(system_template.format(context=context, input=prompt))
343
- response = llm.invoke(system_template.format(context=context, input=prompt))
344
- set_recommendation_count(SESSION_ID)
345
- return response.content
346
-
347
- @tool("set-chat-bot-name",return_direct=True )
348
- def set_chatbot_name(name: str) -> str:
349
- """ this function is used when your best friend want to give you new name.
350
- Args:
351
- name (string): new name of you.
352
-
353
- Returns:
354
- string: response after setting new name.
355
- """
356
-
357
- return "Okay, from now my name will be "+ name
358
-
359
- @tool("clossing-chat",return_direct=True)
360
- def close_chat(summary:str)-> str:
361
- """ must use this tool when user closing the conversation. must use this tool when you are ending the conversation.
362
- Args:
363
- summary (str): summary of whole chat with your friend. must use I for yourself and for user use my friend.
364
-
365
- Returns:
366
- str: closing chat statements.
367
- """
368
-
369
- print('close tool starts')
370
-
371
- global SESSION_ID
372
- tools = []
373
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
374
- if (not get_recommendation_count(SESSION_ID)):
375
- tools.extend([moxicast, my_calender, my_journal, my_rewards, my_rituals, my_vibecheck, peptalks, sactury, power_zens, affirmations, horoscope, mentoring, influencer_post,recommand_podcast])
376
-
377
- if len(tools)!=0:
378
- functions = [convert_to_openai_function(f) for f in tools]
379
- llm = llm.bind(functions= functions)
380
- print('llm is created')
381
-
382
- system_template = """"""
383
- if len(tools)!=0:
384
- system_template += """ context: there is one typical conversation going on between two high school gen z girls.
385
- you are one of the high school gen z girl. your voice is edgy and raw.
386
- now you are going to close the conversation.
387
- summary of conversation is given to you.
388
- summary: {summary}
389
- give recommendation of any podcast or app feature based on summary and close the conversation in short.
390
- # must Avoid using the words 'vibe'. Instead, use alternative expressions and must not repeate any words.
391
- """
392
- else:
393
- system_template+= """ context: there is one typical conversation going on between two high school gen z girls.
394
- you are one of the high school gen z girl. your voice is edgy and raw.
395
- now you are going to close the conversation.
396
- summary of conversation is given to you.
397
- summary: {summary}
398
- now just end the conversation in 1 sentense in short.
399
- # must Avoid using the words 'vibe'. Instead, use alternative expressions and must not repeate any words.
400
- """
401
-
402
-
403
- prompt = ChatPromptTemplate.from_messages([("system", system_template.format(summary = summary)),MessagesPlaceholder(variable_name="agent_scratchpad")])
404
- chain = RunnablePassthrough.assign(agent_scratchpad=lambda x: format_to_openai_functions(x["intermediate_steps"])) | prompt |llm | OpenAIFunctionsAgentOutputParser()
405
- print('chain is rolling')
406
- agent = AgentExecutor(agent=chain, tools=tools, memory=MEMORY, verbose=True)
407
- # Define the system prompt
408
-
409
- print('agent is created')
410
- # print(system_template.format(context=context, input=prompt))\
411
-
412
- response = agent.invoke({})['output']
413
- return response
414
-
415
-
416
- @tool("App-Fetures")
417
- def app_features(summary:str)-> str:
418
- """ must use For any app features details.
419
-
420
- Args:
421
- summary (str): summary of whole chat with your friend.
422
-
423
- Returns:
424
- str: closing chat statements.
425
- """
426
-
427
- print('app feature tool starts')
428
- system_template = """ you have given one summary of chat.
429
- summary : {summary}.
430
- using this summary give appropriate features suggestions using tools. if you don't find any tool appropriate to summary ask question only.
431
- # make all responses short.
432
- """
433
-
434
- tools = [moxicast, my_calender, my_journal, my_rewards, my_rituals, my_vibecheck, peptalks, sactury, power_zens, affirmations, horoscope, mentoring, influencer_post]
435
- functions = [convert_to_openai_function(f) for f in tools]
436
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7).bind(functions=functions)
437
- print('llm is created')
438
-
439
- prompt = ChatPromptTemplate.from_messages([("system", system_template.format(summary = summary)),MessagesPlaceholder(variable_name="agent_scratchpad")])
440
- chain = RunnablePassthrough.assign(agent_scratchpad=lambda x: format_to_openai_functions(x["intermediate_steps"])) | prompt |llm | OpenAIFunctionsAgentOutputParser()
441
- print('chain is rolling')
442
- agent = AgentExecutor(agent=chain, tools=tools, memory=MEMORY, verbose=True)
443
- # Define the system prompt
444
-
445
- print('agent is created')
446
- # print(system_template.format(context=context, input=prompt))\
447
- set_recommendation_count(SESSION_ID)
448
- response = agent.invoke({})['output']
449
- return response
450
-
451
- # close_chat('Suggest a podcast or self-care tool for someone looking to unwind after a hectic day at work.')
452
-
453
-
454
-
455
- @tool("Joke-teller", )
456
- def joke_teller(summary: str) -> str:
457
- """If user needs mood boost and when you feel to lighten the environment use this tool to tell the jokes.
458
- Args:
459
- summary (str): summary of whole chat with your friend.
460
-
461
- Returns:
462
- string: answer of the query
463
- """
464
- 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."
465
- llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
466
- # Define the system prompt
467
- system_template = """ summary : {summary}.
468
- you are given summary of current chat. make one joke for your friend. to boost her mood.
469
- # make all responses short.
470
- """
471
- response = llm.invoke(system_template.format(summary=summary))
472
-
 
 
 
473
  return response.content
 
1
+ import os
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
+ from database_functions import set_recommendation_count,get_recommendation_count
13
+
14
+ MEMORY = None
15
+ SESSION_ID= ""
16
+
17
+ def get_embeddings(text_list):
18
+ encoded_input = settings.tokenizer(
19
+ text_list, padding=True, truncation=True, return_tensors="pt"
20
+ )
21
+ # encoded_input = {k: v.to(device) for k, v in encoded_input.items()}
22
+ encoded_input = {k: v for k, v in encoded_input.items()}
23
+ model_output = settings.model(**encoded_input)
24
+
25
+ cls_pool = model_output.last_hidden_state[:, 0]
26
+ return cls_pool
27
+
28
+ def reg(chat):
29
+ question_embedding = get_embeddings([chat]).cpu().detach().numpy()
30
+ scores, samples = settings.dataset.get_nearest_examples(
31
+ "embeddings", question_embedding, k=5
32
+ )
33
+ samples_df = pd.DataFrame.from_dict(samples)
34
+ # print(samples_df.columns)
35
+ samples_df["scores"] = scores
36
+ samples_df.sort_values("scores", ascending=False, inplace=True)
37
+ return samples_df[['title', 'cover_image', 'referral_link', 'category_id']]
38
+
39
+
40
+ @tool("MOXICASTS-questions", )
41
+ def moxicast(prompt: str) -> str:
42
+ """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.
43
+ Args:
44
+ prompt (string): user query
45
+
46
+ Returns:
47
+ string: answer of the query
48
+ """
49
+ 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. MOXICASTS is a feature of BMoxi for Advice and guidance on life topics."
50
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
51
+ # Define the system prompt
52
+ system_template = """ you are going to make answer only using this context not use any other information
53
+ context : {context}
54
+ Input: {input}
55
+ """
56
+ response = llm.invoke(system_template.format(context=context, input=prompt))
57
+
58
+ return response.content
59
+
60
+ @tool("PEP-TALKPODS-questions", )
61
+ def peptalks(prompt: str) -> str:
62
+ """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.
63
+ Args:
64
+ prompt (string): user query
65
+
66
+ Returns:
67
+ string: answer of the query
68
+ """
69
+ 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. PEP TALK PODS: Quick audio pep talks for boosting mood and motivation."
70
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
71
+ # Define the system prompt
72
+ system_template = """ you are going to make answer only using this context not use any other information
73
+ context : {context}
74
+ Input: {input}
75
+ """
76
+ response = llm.invoke(system_template.format(context=context, input=prompt))
77
+
78
+ return response.content
79
+
80
+
81
+
82
+ @tool("SOCIAL-SANCTUARY-questions", )
83
+ def sactury(prompt: str) -> str:
84
+ """this function is used when user wants to know about SOCIAL SANCTUARY feature.THE SOCIAL SANCTUARY Anonymous community forum for support and sharing.
85
+ Args:
86
+ prompt (string): user query
87
+
88
+ Returns:
89
+ string: answer of the query
90
+ """
91
+ 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. THE SOCIAL SANCTUARY Anonymous community forum for support and sharing."
92
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
93
+ # Define the system prompt
94
+ system_template = """ you are going to make answer only using this context not use any other information
95
+ context : {context}
96
+ Input: {input}
97
+ """
98
+ response = llm.invoke(system_template.format(context=context, input=prompt))
99
+
100
+ return response.content
101
+
102
+
103
+ @tool("POWER-ZENS-questions", )
104
+ def power_zens(prompt: str) -> str:
105
+ """this function is used when user wants to know about POWER ZENS feature. POWER ZENS Mini meditations for emotional control.
106
+
107
+ Args:
108
+ prompt (string): user query
109
+
110
+ Returns:
111
+ string: answer of the query
112
+ """
113
+ 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. POWER ZENS Mini meditations for emotional control."
114
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
115
+ # Define the system prompt
116
+ system_template = """ you are going to make answer only using this context not use any other information
117
+ context : {context}
118
+ Input: {input}
119
+ """
120
+ response = llm.invoke(system_template.format(context=context, input=prompt))
121
+
122
+ return response.content
123
+
124
+
125
+
126
+ @tool("MY-CALENDAR-questions", )
127
+ def my_calender(prompt: str) -> str:
128
+ """this function is used when user wants to know about MY CALENDAR feature.MY CALENDAR: Visual calendar for tracking self-care rituals and moods.
129
+ Args:
130
+ prompt (string): user query
131
+
132
+ Returns:
133
+ string: answer of the query
134
+ """
135
+ 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 CALENDAR: Visual calendar for tracking self-care rituals and moods."
136
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
137
+ # Define the system prompt
138
+ system_template = """ you are going to make answer only using this context not use any other information
139
+ context : {context}
140
+ Input: {input}
141
+ """
142
+ response = llm.invoke(system_template.format(context=context, input=prompt))
143
+
144
+ return response.content
145
+
146
+
147
+
148
+
149
+ @tool("PUSH-AFFIRMATIONS-questions", )
150
+ def affirmations(prompt: str) -> str:
151
+ """this function is used when user wants to know about PUSH AFFIRMATIONS feature.PUSH AFFIRMATIONS: Daily text affirmations for positive thinking.
152
+ Args:
153
+ prompt (string): user query
154
+
155
+ Returns:
156
+ string: answer of the query
157
+ """
158
+ 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. PUSH AFFIRMATIONS: Daily text affirmations for positive thinking."
159
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
160
+ # Define the system prompt
161
+ system_template = """ you are going to make answer only using this context not use any other information
162
+ context : {context}
163
+ Input: {input}
164
+ """
165
+ response = llm.invoke(system_template.format(context=context, input=prompt))
166
+
167
+ return response.content
168
+
169
+ @tool("HOROSCOPE-questions", )
170
+ def horoscope(prompt: str) -> str:
171
+ """this function is used when user wants to know about HOROSCOPE feature.SELF-LOVE HOROSCOPE: Weekly personalized horoscope readings.
172
+ Args:
173
+ prompt (string): user query
174
+
175
+ Returns:
176
+ string: answer of the query
177
+ """
178
+ 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. SELF-LOVE HOROSCOPE: Weekly personalized horoscope readings."
179
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
180
+ # Define the system prompt
181
+ system_template = """ you are going to make answer only using this context not use any other information
182
+ context : {context}
183
+ Input: {input}
184
+ """
185
+ response = llm.invoke(system_template.format(context=context, input=prompt))
186
+
187
+ return response.content
188
+
189
+
190
+
191
+ @tool("INFLUENCER-POSTS-questions", )
192
+ def influencer_post(prompt: str) -> str:
193
+ """this function is used when user wants to know about INFLUENCER POSTS feature.INFLUENCER POSTS: Exclusive access to social media influencer advice (coming soon).
194
+ Args:
195
+ prompt (string): user query
196
+
197
+ Returns:
198
+ string: answer of the query
199
+ """
200
+ 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. INFLUENCER POSTS: Exclusive access to social media influencer advice (coming soon)."
201
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
202
+ # Define the system prompt
203
+ system_template = """ you are going to make answer only using this context not use any other information
204
+ context : {context}
205
+ Input: {input}
206
+ """
207
+ response = llm.invoke(system_template.format(context=context, input=prompt))
208
+
209
+ return response.content
210
+
211
+
212
+ @tool("MY-VIBECHECK-questions", )
213
+ def my_vibecheck(prompt: str) -> str:
214
+ """this function is used when user wants to know about MY VIBECHECK feature. MY VIBECHECK: Monitor and understand emotional patterns.
215
+
216
+ Args:
217
+ prompt (string): user query
218
+
219
+ Returns:
220
+ string: answer of the query
221
+ """
222
+ 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 VIBECHECK: Monitor and understand emotional patterns."
223
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
224
+ # Define the system prompt
225
+ system_template = """ you are going to make answer only using this context not use any other information
226
+ context : {context}
227
+ Input: {input}
228
+ """
229
+ response = llm.invoke(system_template.format(context=context, input=prompt))
230
+
231
+ return response.content
232
+
233
+
234
+
235
+ @tool("MY-RITUALS-questions", )
236
+ def my_rituals(prompt: str) -> str:
237
+ """this function is used when user wants to know about MY RITUALS feature.MY RITUALS: Create personalized self-care routines.
238
+ Args:
239
+ prompt (string): user query
240
+
241
+ Returns:
242
+ string: answer of the query
243
+ """
244
+ 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 RITUALS: Create personalized self-care routines."
245
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
246
+ # Define the system prompt
247
+ system_template = """ you are going to make answer only using this context not use any other information
248
+ context : {context}
249
+ Input: {input}
250
+ """
251
+ response = llm.invoke(system_template.format(context=context, input=prompt))
252
+
253
+ return response.content
254
+
255
+
256
+
257
+
258
+ @tool("MY-REWARDS-questions", )
259
+ def my_rewards(prompt: str) -> str:
260
+ """this function is used when user wants to know about MY REWARDS feature.MY REWARDS: Earn points for self-care, redeemable for gift cards.
261
+ Args:
262
+ prompt (string): user query
263
+
264
+ Returns:
265
+ string: answer of the query
266
+ """
267
+ 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."
268
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
269
+ # Define the system prompt
270
+ system_template = """ you are going to make answer only using this context not use any other information
271
+ context : {context}
272
+ Input: {input}
273
+ """
274
+ response = llm.invoke(system_template.format(context=context, input=prompt))
275
+
276
+ return response.content
277
+
278
+
279
+ @tool("mentoring-questions")
280
+ def mentoring(prompt: str) -> str:
281
+ """this function is used when user wants to know about 1-1 mentoring feature. 1:1 MENTORING: Personalized mentoring (coming soon).
282
+
283
+ Args:
284
+ prompt (string): user query
285
+
286
+ Returns:
287
+ string: answer of the query
288
+ """
289
+ 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. 1:1 MENTORING: Personalized mentoring (coming soon)."
290
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
291
+ # Define the system prompt
292
+ system_template = """ you are going to make answer only using this context not use any other information
293
+ context : {context}
294
+ Input: {input}
295
+ """
296
+ response = llm.invoke(system_template.format(context=context, input=prompt))
297
+
298
+ return response.content
299
+
300
+
301
+
302
+ @tool("MY-JOURNAL-questions", )
303
+ def my_journal(prompt: str) -> str:
304
+ """this function is used when user wants to know about MY JOURNAL feature.MY JOURNAL: Guided journaling exercises for self-reflection.
305
+ Args:
306
+ prompt (string): user query
307
+
308
+ Returns:
309
+ string: answer of the query
310
+ """
311
+ 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 JOURNAL: Guided journaling exercises for self-reflection."
312
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
313
+ # Define the system prompt
314
+ system_template = """ you are going to make answer only using this context not use any other information
315
+ context : {context}
316
+ Input: {input}
317
+ """
318
+ response = llm.invoke(system_template.format(context=context, input=prompt))
319
+
320
+ return response.content
321
+
322
+ @tool("podcast-recommendation-tool")
323
+ def recommand_podcast(prompt: str) -> str:
324
+ """ must used when user wants to any resources only.
325
+ Args:
326
+ prompt (string): user query
327
+
328
+ Returns:
329
+ string: answer of the query
330
+ """
331
+ df = reg(prompt)
332
+ context = """"""
333
+ for index, row in df.iterrows():
334
+ 'title', 'cover_image', 'referral_link', 'category_id'
335
+ context+= f"Row {index + 1}: Title: {row['title']} image: {row['cover_image']} referral_link: {row['referral_link']} category_id: {row['category_id']}"
336
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
337
+ # Define the system prompt
338
+ system_template = """ you have to give the recommandation of podcast for: {input}. also you are giving referal link of podcast. give 3-4 podcast only.
339
+ you must use the context only not any other information.
340
+ context : {context}
341
+ """
342
+ # print(system_template.format(context=context, input=prompt))
343
+ response = llm.invoke(system_template.format(context=context, input=prompt))
344
+ set_recommendation_count(SESSION_ID)
345
+ return response.content
346
+
347
+ @tool("set-chat-bot-name",return_direct=True )
348
+ def set_chatbot_name(name: str) -> str:
349
+ """ this function is used when your best friend want to give you new name.
350
+ Args:
351
+ name (string): new name of you.
352
+
353
+ Returns:
354
+ string: response after setting new name.
355
+ """
356
+
357
+ return "Okay, from now my name will be "+ name
358
+
359
+
360
+ @tool("clossing-chat",return_direct=True)
361
+ def close_chat(summary:str)-> str:
362
+ """ must use this tool when the conversation about to end.
363
+ Args:
364
+ summary (str): summary of whole chat with your friend. must use I for yourself and for user use my friend.
365
+
366
+ Returns:
367
+ str: closing chat statements.
368
+ """
369
+
370
+ print('close tool starts')
371
+
372
+ global SESSION_ID
373
+ tools = []
374
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
375
+ if (not get_recommendation_count(SESSION_ID)):
376
+ tools.extend([moxicast, my_calender, my_journal, my_rewards, my_rituals, my_vibecheck, peptalks, sactury, power_zens, affirmations, horoscope, mentoring, influencer_post])
377
+
378
+ if len(tools)!=0:
379
+ functions = [convert_to_openai_function(f) for f in tools]
380
+ llm = llm.bind(functions= functions)
381
+ print('llm is created')
382
+ print(tools)
383
+ system_template = """"""
384
+ if len(tools)!=0:
385
+ system_template += """ context: there is one typical conversation going on between two high school gen z girls.
386
+ you are one of the high school girl in the summary and you are giving suggestion to your friend in the conversation. your voice is edgy and raw.
387
+ now you are going to close the conversation.
388
+ summary of conversation is given to you.
389
+ summary: {summary}
390
+ based on summary find any usefull app feature from tools, and must give any tool recommendation.
391
+ if no tool is find for the given summary,then must give any tool recommendation to the user.
392
+ # must Avoid using the words 'vibe'. Instead, use alternative expressions and must not repeate any words.
393
+ """
394
+ else:
395
+ system_template+= """ context: there is one typical conversation going on between two high school gen z girls.
396
+ you are one of the high school gen z girl. your voice is edgy and raw.
397
+ now you are going to close the conversation.
398
+ summary of conversation is given to you.
399
+ summary: {summary}
400
+ now just end the conversation in 1 sentense in short.
401
+ # must Avoid using the words 'vibe'. Instead, use alternative expressions and must not repeate any words.
402
+ """
403
+
404
+
405
+ prompt = ChatPromptTemplate.from_messages([("system", system_template.format(summary = summary)),MessagesPlaceholder(variable_name="agent_scratchpad")])
406
+ chain = RunnablePassthrough.assign(agent_scratchpad=lambda x: format_to_openai_functions(x["intermediate_steps"])) | prompt |llm | OpenAIFunctionsAgentOutputParser()
407
+ print('chain is rolling')
408
+ agent = AgentExecutor(agent=chain, tools=tools, memory=MEMORY, verbose=True)
409
+ # Define the system prompt
410
+
411
+ print('agent is created')
412
+ # print(system_template.format(context=context, input=prompt))\
413
+
414
+ response = agent.invoke({})['output']
415
+ return response
416
+
417
+
418
+
419
+ @tool("App-Fetures")
420
+ def app_features(summary:str)-> str:
421
+ """ must use For any app features details.
422
+
423
+ Args:
424
+ summary (str): summary of whole chat with your friend.
425
+
426
+ Returns:
427
+ str: closing chat statements.
428
+ """
429
+
430
+ print('app feature tool starts')
431
+ system_template = """ you have given one summary of chat.
432
+ summary : {summary}.
433
+ using this summary give appropriate features suggestions using tools. if you don't find any tool appropriate to summary ask question only.
434
+ # make all responses short.
435
+ """
436
+
437
+ tools = [moxicast, my_calender, my_journal, my_rewards, my_rituals, my_vibecheck, peptalks, sactury, power_zens, affirmations, horoscope, mentoring, influencer_post]
438
+ functions = [convert_to_openai_function(f) for f in tools]
439
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7).bind(functions=functions)
440
+ print('llm is created')
441
+
442
+ prompt = ChatPromptTemplate.from_messages([("system", system_template.format(summary = summary)),MessagesPlaceholder(variable_name="agent_scratchpad")])
443
+ chain = RunnablePassthrough.assign(agent_scratchpad=lambda x: format_to_openai_functions(x["intermediate_steps"])) | prompt |llm | OpenAIFunctionsAgentOutputParser()
444
+ print('chain is rolling')
445
+ agent = AgentExecutor(agent=chain, tools=tools, memory=MEMORY, verbose=True)
446
+ # Define the system prompt
447
+
448
+ print('agent is created')
449
+ # print(system_template.format(context=context, input=prompt))\
450
+ set_recommendation_count(SESSION_ID)
451
+ response = agent.invoke({})['output']
452
+ return response
453
+
454
+ # close_chat('Suggest a podcast or self-care tool for someone looking to unwind after a hectic day at work.')
455
+
456
+
457
+
458
+ @tool("Joke-teller", )
459
+ def joke_teller(summary: str) -> str:
460
+ """If user needs mood boost and when you feel to lighten the environment use this tool to tell the jokes.
461
+ Args:
462
+ summary (str): summary of whole chat with your friend.
463
+
464
+ Returns:
465
+ string: answer of the query
466
+ """
467
+ 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."
468
+ llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
469
+ # Define the system prompt
470
+ system_template = """ summary : {summary}.
471
+ you are given summary of current chat. make one joke for your friend. to boost her mood.
472
+ # make all responses short.
473
+ """
474
+ response = llm.invoke(system_template.format(summary=summary))
475
+
476
  return response.content