File size: 15,645 Bytes
d7762a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import os
from langchain.agents import tool
from langchain_community.chat_models import ChatOpenAI
import pandas as pd

from config import settings



def get_embeddings(text_list):
    encoded_input = settings.tokenizer(
        text_list, padding=True, truncation=True, return_tensors="pt"
    )
    # encoded_input = {k: v.to(device) for k, v in encoded_input.items()}
    encoded_input = {k: v for k, v in encoded_input.items()}
    model_output = settings.model(**encoded_input)
    
    cls_pool = model_output.last_hidden_state[:, 0]
    return cls_pool

def reg(chat):
  question_embedding = get_embeddings([chat]).cpu().detach().numpy()
  scores, samples = settings.dataset.get_nearest_examples(
      "embeddings", question_embedding, k=5
  )
  samples_df = pd.DataFrame.from_dict(samples)
  print(samples_df.columns)
  samples_df["scores"] = scores
  samples_df.sort_values("scores", ascending=False, inplace=True)
  return samples_df[['title', 'cover_image', 'referral_link', 'category_id']]


@tool("MOXICASTS-questions", return_direct=True)
def moxicast(prompt: str) -> str:
    """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.
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content

@tool("PEP-TALKPODS-questions", return_direct=True)
def peptalks(prompt: str) -> str:
    """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.
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content



@tool("SOCIAL-SANCTUARY-questions", return_direct=True)
def sactury(prompt: str) -> str:
    """this function is used when user wants to know about SOCIAL SANCTUARY feature.THE SOCIAL SANCTUARY Anonymous community forum for support and sharing.
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content


@tool("POWER-ZENS-questions", return_direct=True)
def power_zens(prompt: str) -> str:
    """this function is used when user wants to know about POWER ZENS feature. POWER ZENS Mini meditations for emotional control.

    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content



@tool("MY-CALENDAR-questions", return_direct=True)
def my_calender(prompt: str) -> str:
    """this function is used when user wants to know about MY CALENDAR feature.MY CALENDAR: Visual calendar for tracking self-care rituals and moods.
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content




@tool("PUSH-AFFIRMATIONS-questions", return_direct=True)
def affirmations(prompt: str) -> str:
    """this function is used when user wants to know about PUSH AFFIRMATIONS feature.PUSH AFFIRMATIONS: Daily text affirmations for positive thinking.
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content

@tool("HOROSCOPE-questions", return_direct=True)
def horoscope(prompt: str) -> str:
    """this function is used when user wants to know about HOROSCOPE feature.SELF-LOVE HOROSCOPE: Weekly personalized horoscope readings.
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content



@tool("INFLUENCER-POSTS-questions", return_direct=True)
def influencer_post(prompt: str) -> str:
    """this function is used when user wants to know about INFLUENCER POSTS feature.INFLUENCER POSTS: Exclusive access to social media influencer advice (coming soon).
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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)."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content


@tool("MY-VIBECHECK-questions", return_direct=True)
def my_vibecheck(prompt: str) -> str:
    """this function is used when user wants to know about MY VIBECHECK feature. MY VIBECHECK: Monitor and understand emotional patterns.

    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content



@tool("MY-RITUALS-questions", return_direct=True)
def my_rituals(prompt: str) -> str:
    """this function is used when user wants to know about MY RITUALS feature.MY RITUALS: Create personalized self-care routines.
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content




@tool("MY-REWARDS-questions", return_direct=True)
def my_rewards(prompt: str) -> str:
    """this function is used when user wants to know about MY REWARDS feature.MY REWARDS: Earn points for self-care, redeemable for gift cards.
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content


@tool("mentoring-questions", return_direct=True)
def mentoring(prompt: str) -> str:
    """this function is used when user wants to know about 1-1 mentoring feature.  1:1 MENTORING: Personalized mentoring (coming soon).

    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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)."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content



@tool("MY-JOURNAL-questions", return_direct=True)
def my_journal(prompt: str) -> str:
    """this function is used when user wants to know about MY JOURNAL feature.MY JOURNAL: Guided journaling exercises for self-reflection.
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    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."
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are going to make answer only using this context not use any other information
   context : {context}
    Input: {input}
    """
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content

@tool("recommandation_tool", return_direct=True)
def recommand_podcast(prompt: str) -> str:
    """ this function is used when your best friend want any recommandation and tips. also you feel that this is the best time for any recommandation or your friend.
    Args:
        prompt (string): user query

    Returns:
        string: answer of the query
    """
    df = reg(prompt)
    context = """"""
    for index, row in df.iterrows():
        'title', 'cover_image', 'referral_link', 'category_id'
        context+= f"Row {index + 1}: Title: {row['title']} image: {row['cover_image']} referral_link: {row['referral_link']} category_id: {row['category_id']}"
    llm = ChatOpenAI(model=settings.OPENAI_MODEL, openai_api_key=settings.OPENAI_KEY, temperature=0.7)
    # Define the system prompt
    system_template = """ you are give the recommandation of podcast. also you are giving referal link of podcast.
    you must use the context only not any other information.
    context : {context}
    Input: {input}
    """
    print(system_template.format(context=context, input=prompt))
    response = llm.invoke(system_template.format(context=context, input=prompt))

    return response.content

@tool("set-chat-bot-name", return_direct=True)
def set_chatbot_name(name: str) -> str:
    """ this function is used when your best friend want to give you new name.
    Args:
        name (string): new name of you.

    Returns:
        string: response after setting new name.
    """

    return "Okay, from now my name will be "+ name