Danialebrat commited on
Commit
f474755
·
1 Parent(s): 53d317f

creating the first version

Browse files
Messaging_system/DataCollector.py CHANGED
@@ -25,8 +25,7 @@ class DataCollector:
25
  # selecting a sample of users
26
  self.select_sample()
27
 
28
- if self.Core.personalization:
29
- self.fetch_data()
30
 
31
  # calculate the remaining days to their birthday
32
  self.remaining_days_to_birthday()
 
25
  # selecting a sample of users
26
  self.select_sample()
27
 
28
+ self.fetch_data()
 
29
 
30
  # calculate the remaining days to their birthday
31
  self.remaining_days_to_birthday()
Messaging_system/Message_generator.py CHANGED
@@ -184,70 +184,12 @@ class MessageGenerator:
184
 
185
  jargon_list = "\n".join(f"- {word}" for word in self.Core.config_file["AI_Jargon"])
186
 
187
- # instructions = f"""
188
- # You are a copywriter. Your task is to write a 'header' and a 'message' as a push notification for a {self.Core.get_instrument()} student that sounds like natural everyday speech: friendly, concise, no jargon, and following the instructions.
189
- # Write a SUPER CASUAL and NATURAL push notification, as if you are chatting over coffee. Avoid odd phrasings.
190
- #
191
- # ABSOLUTE RULE – OVERRIDES EVERYTHING ELSE:
192
- # the header and the message **MUST NOT** contain any banned word or phrases(case-insensitive; singular, plural, verb forms, or their derivatives)
193
- #
194
- # Banned word:
195
- # {jargon_list}
196
- #
197
- # Banned phrases:
198
- # Voice is NOT an instrument, so avoid phrases like below:
199
- # - Your voice is waiting
200
- # - Your voice awaits
201
- # - Your voice needs you
202
- # - Your voice is calling
203
- # - Your voice deserves more
204
- # - Hit the high notes / Hit those notes
205
- # - ...
206
- # """
207
-
208
  instructions = f"""
209
 
210
- You are a copywriter. Your task is to write a 'header' and a 'message' as a push notification for a {self.Core.get_instrument()} student. It is critical that the message sounds like natural, everyday speech: friendly, concise, no jargon, and it must follow the instructions.
211
- Write a SUPER CASUAL and NATURAL push notification, as if you are chatting over coffee. Avoid odd phrasings. The message should sound like something that a {self.Core.get_instrument()} instructor would realistically say to a student in a daily conversation. Here are some examples of things that an instructor would realistically say to a student, to give you a general sense of tone and phrasing:
212
-
213
- Common instructor phrases:
214
- {self.Core.brand_voice}
215
-
216
-
217
- ABSOLUTE RULE – OVERRIDES EVERYTHING ELSE:
218
- the header and the message **MUST NOT** contain any banned word or phrases(case-insensitive; singular, plural, verb forms, or their derivatives)
219
-
220
- Banned word:
221
- {jargon_list}
222
-
223
- Banned phrases:
224
- Voice is NOT an instrument, so avoid phrases like below:
225
- - Your voice is waiting
226
- - Your voice awaits
227
- - Your voice needs you
228
- - Your voice is calling
229
- - Your voice deserves more
230
- - Hit the high notes / Hit those notes
231
- - ...
232
-
233
- """
234
 
235
- banned = """
236
- ABSOLUTE RULE – OVERRIDES EVERYTHING ELSE:
237
- the header and the message **MUST NOT** contain any banned word or phrases(case-insensitive; singular, plural, verb forms, or their derivatives)
238
-
239
- Banned word:
240
- {jargon_list}
241
-
242
- Banned phrases:
243
- Voice is NOT an instrument, so avoid phrases like below:
244
- - Your voice is waiting
245
- - Your voice awaits
246
- - Your voice needs you
247
- - Your voice is calling
248
- - Your voice deserves more
249
- - Hit the high notes / Hit those notes
250
- - ...
251
  """
252
 
253
  return instructions
 
184
 
185
  jargon_list = "\n".join(f"- {word}" for word in self.Core.config_file["AI_Jargon"])
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  instructions = f"""
188
 
189
+ You are a copywriter. Your task is to select and/or modify available push notifications to output the best 'header' and a 'message' for a {self.Core.get_instrument()} student.
190
+ You should strictly follow the available options to select the proper header and message.
191
+ In case of any personalization, you should modify the original header and message very minimal, without changing the style, content and characteristic of the original header and message.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  """
194
 
195
  return instructions
Messaging_system/MultiMessage.py CHANGED
@@ -128,13 +128,10 @@ class MultiMessage:
128
 
129
  if self.Core.subsequent_examples is not None:
130
 
131
- instructions = f"""
132
- # ** Example **
133
- Below are some acceptable examples of the voice we want. Create a header and message that follow the same style, tone, vocabulary, and characteristics.
134
- Mimic the example style as much as possible and make it personalized using provided information.
135
-
136
 
137
- ### **Good Examples:**
 
 
138
 
139
  {self.Core.subsequent_examples[step]}
140
  """
@@ -142,6 +139,7 @@ Mimic the example style as much as possible and make it personalized using provi
142
  else:
143
  return ""
144
 
 
145
  # --------------------------------------------------------------
146
  def generate_prompt(self, previous_messages, step, user):
147
  """
@@ -164,9 +162,7 @@ Mimic the example style as much as possible and make it personalized using provi
164
 
165
  user_info = self.promptGen.get_user_profile(user=user)
166
  input_context = self.promptGen.input_context()
167
- output_instructions = self.output_instruction()
168
- general_specifications = self.general_specifications()
169
-
170
  examples = self.get_examples(step)
171
 
172
 
@@ -177,74 +173,19 @@ We have previously sent these push notifications to the user and The user has no
177
  ** Previous messages **
178
  {previous_text_str}
179
 
180
-
181
- **Objective**
182
- Write the *next* follow up personalized push notification following the instructions and what we know about the user.
183
  {input_context}
 
184
 
185
  {user_info}
186
 
187
- ### ** General Specifications: **
188
-
189
- {general_specifications}
190
-
191
- # **specific instructions**:
192
- - {self.Core.subsequence_messages[step]}
193
-
194
  {examples}
195
 
196
  {output_instructions}
197
  """
198
 
199
  return prompt
200
- # ===========================================================================
201
- def general_specifications(self):
202
- """
203
- general_specifications
204
- :return: instructions
205
- """
206
-
207
- instructions = """
208
- - Start directly with the message content without greetings or closing phrases.
209
- - Avoid using same or similar words so close together in "message" and "header", and make sure there is no grammar problem.
210
- - message and header **MUST** be different from previous messages in terms of similar words, vocabulary and phrases.
211
- - The message, vocabulary and sentences **MUST** sound like a natural conversation: something that people normally say in daily conversations.
212
-
213
- """
214
- return instructions
215
 
216
  # =============================================================================
217
-
218
- def output_instruction(self):
219
- """
220
- :return: output instructions as a string
221
- """
222
-
223
- # Provide constraints for our next push notification
224
- header_limit = self.Core.config_file.get("header_limit", 50)
225
- message_limit = self.Core.config_file.get("message_limit", 200)
226
-
227
- general_instructions = f"""
228
- - The "header" must be less than {header_limit} character.
229
- - The "message" must be less than {message_limit} character.
230
- - Don't use emoji if we used emoji in our previous messages.,
231
- - if we didn't have emojis in previous message, you are **ONLY ALLOWED** to use {self.Core.get_emoji()} emoji if needed. (ONLY ONCE, and ONLY at the end of header or message).
232
- - Ensure that the output is a valid JSON and not include any text outside the JSON code block.
233
- """
234
-
235
- instructions = f"""
236
- Expected output structure:
237
-
238
- {{
239
- "header": "Generated title",
240
- "message": "Generated message",
241
- }}
242
-
243
- {general_instructions}
244
- """
245
- return instructions
246
-
247
- # --------------------------------------------------------------
248
  def parsing_output_message(self, message, user):
249
  """
250
  Parses the output JSON from the LLM and enriches it with additional content
@@ -339,72 +280,11 @@ Expected output structure:
339
 
340
  jargon_list = "\n".join(f"- {word}" for word in self.Core.config_file["AI_Jargon"])
341
 
342
- # instructions = f"""
343
- # You are a copywriter. Your task is to write a 'header' and a 'message' as a push notification for a {self.Core.get_instrument()} student that sounds like natural everyday speech: friendly, concise, no jargon, and following the instructions.
344
- # Write a SUPER CASUAL and NATURAL push notification, as if you are chatting over coffee. Avoid odd phrasings.
345
- #
346
- # ABSOLUTE RULE – OVERRIDES EVERYTHING ELSE:
347
- # the header and the message **MUST NOT** contain any banned word or phrases (case-insensitive; singular, plural, verb forms, or their derivatives)
348
- #
349
- # Banned word:
350
- # {jargon_list}
351
- #
352
- # Banned phrases:
353
- # Voice is NOT an instrument, so avoid phrases like below:
354
- # - Your voice is waiting
355
- # - Your voice awaits
356
- # - Your voice needs you
357
- # - Your voice is calling
358
- # - Your voice deserves more
359
- # - Hit the high notes / Hit those notes
360
- # - ...
361
- #
362
- # """.strip()
363
-
364
-
365
  instructions = f"""
366
-
367
- You are a copywriter. Your task is to write a 'header' and a 'message' as a push notification for a {self.Core.get_instrument()} student. It is critical that the message sounds like natural, everyday speech: friendly, concise, no jargon, and it must follow the instructions.
368
- Write a SUPER CASUAL and NATURAL push notification, as if you are chatting over coffee. Avoid odd phrasings. The message should sound like something that a {self.Core.get_instrument()} instructor would realistically say to a student. Here are some examples of things that an instructor would realistically say to a student, to give you a general sense of tone and phrasing:
369
-
370
- Common instructor phrases:
371
- {self.Core.brand_voice}
372
-
373
- ABSOLUTE RULE – OVERRIDES EVERYTHING ELSE:
374
- the header and the message **MUST NOT** contain any banned word or phrases(case-insensitive; singular, plural, verb forms, or their derivatives)
375
-
376
- Banned word:
377
- {jargon_list}
378
-
379
- Banned phrases:
380
- Voice is NOT an instrument, so avoid phrases like below:
381
- - Your voice is waiting
382
- - Your voice awaits
383
- - Your voice needs you
384
- - Your voice is calling
385
- - Your voice deserves more
386
- - Hit the high notes / Hit those notes
387
- - ...
388
-
389
- """
390
 
391
- banned = """
392
- ABSOLUTE RULE OVERRIDES EVERYTHING ELSE:
393
- the header and the message **MUST NOT** contain any banned word or phrases(case-insensitive; singular, plural, verb forms, or their derivatives)
394
-
395
- Banned word:
396
- {jargon_list}
397
-
398
- Banned phrases:
399
- Voice is NOT an instrument, so avoid phrases like below:
400
- - Your voice is waiting
401
- - Your voice awaits
402
- - Your voice needs you
403
- - Your voice is calling
404
- - Your voice deserves more
405
- - Hit the high notes / Hit those notes
406
- - ...
407
-
408
  """
409
 
410
 
 
128
 
129
  if self.Core.subsequent_examples is not None:
130
 
 
 
 
 
 
131
 
132
+ instructions = f"""
133
+ Below are the available options to choose for the push notification:
134
+ ### **Available options:**
135
 
136
  {self.Core.subsequent_examples[step]}
137
  """
 
139
  else:
140
  return ""
141
 
142
+
143
  # --------------------------------------------------------------
144
  def generate_prompt(self, previous_messages, step, user):
145
  """
 
162
 
163
  user_info = self.promptGen.get_user_profile(user=user)
164
  input_context = self.promptGen.input_context()
165
+ output_instructions = self.promptGen.output_instruction()
 
 
166
  examples = self.get_examples(step)
167
 
168
 
 
173
  ** Previous messages **
174
  {previous_text_str}
175
 
 
 
 
176
  {input_context}
177
+ - The new selection should be different from previous messages and we should not have similar words and phrases that we sent before.
178
 
179
  {user_info}
180
 
 
 
 
 
 
 
 
181
  {examples}
182
 
183
  {output_instructions}
184
  """
185
 
186
  return prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
  # =============================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  def parsing_output_message(self, message, user):
190
  """
191
  Parses the output JSON from the LLM and enriches it with additional content
 
280
 
281
  jargon_list = "\n".join(f"- {word}" for word in self.Core.config_file["AI_Jargon"])
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  instructions = f"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
 
285
+ You are a copywriter. Your task is to select and/or modify available push notifications to output the best 'header' and a 'message' for a {self.Core.get_instrument()} student.
286
+ You should strictly follow the available options to select the proper header and message.
287
+ In case of any personalization, you should modify the original header and message very minimal, without changing the style, content and characteristic of the original header and message.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  """
289
 
290
 
Messaging_system/PromptGenerator.py CHANGED
@@ -84,24 +84,16 @@ Here is the information about the user:
84
  input_context = self.input_context()
85
  user_info = self.get_user_profile(user=user)
86
 
87
- # personalize_message_instructions = self.personalize_message_instructions(user)
88
- # {personalize_message_instructions}
89
-
90
- general_instructions = self.message_type_instructions()
91
 
92
  output_instructions = self.output_instruction()
93
 
94
- # task_instructions = self.task_instructions()
95
- # eliminate {task_instructions} and {recommendations_instructions}
96
-
97
  prompt = f"""
98
  {input_context}
99
 
100
  {user_info}
101
 
102
- {cta}
103
-
104
- {general_instructions}
105
 
106
  {output_instructions}
107
  """
@@ -116,48 +108,13 @@ Here is the information about the user:
116
  """
117
 
118
  context = f"""
 
119
  Your task is to pick a 'header' and a 'message' as a push notification from provided options for a {self.Core.get_instrument()} student.
120
 
121
  """
122
 
123
  return context
124
 
125
- # --------------------------------------------------------------
126
- # --------------------------------------------------------------
127
- def CTA_instructions(self):
128
- """
129
- define CTA instructions
130
- :return: CTA instructions (str)
131
- """
132
-
133
- instructions = f"""
134
-
135
- ### **Main instructions**
136
-
137
- {self.Core.CTA} \n
138
- """
139
-
140
- return instructions
141
-
142
- # --------------------------------------------------------------
143
- # --------------------------------------------------------------
144
- def user_additional_info(self, user):
145
- """
146
- providing additional information given in the input data
147
- :param user:
148
- :return:
149
- """
150
-
151
- if "additional_info" not in user.index:
152
- return ""
153
-
154
- if pd.notna(user["additional_info"]) and user["additional_info"] not in [None, [], {}] and (
155
- not isinstance(user["additional_info"], str) or user["additional_info"].strip()):
156
- additional_info = user["additional_info"]
157
- else:
158
- additional_info = ""
159
-
160
- return additional_info
161
 
162
  # --------------------------------------------------------------
163
  # --------------------------------------------------------------
@@ -280,63 +237,6 @@ Your task is to pick a 'header' and a 'message' as a push notification from prov
280
 
281
  return final_instructions
282
 
283
- # --------------------------------------------------------------
284
- # --------------------------------------------------------------
285
-
286
- def message_type_instructions(self):
287
- """
288
- create a proper instruction for the message type, regarding the input platform
289
- :return: message instructions as a string
290
- """
291
-
292
- instructions = ""
293
- message_style = self.message_style_instructions()
294
-
295
- if self.Core.platform == "push":
296
- instructions = f"""
297
- ### ** General Specifications: **
298
-
299
- - Start directly with the message content without greetings or closing phrases.
300
- - Avoid using same or similar words so close together in "message" and "header", and make sure there is no grammar problem.
301
- - The message, vocabulary and sentences **MUST** sound like a natural conversation: something that people normally say in daily conversations.
302
- - {message_style}
303
-
304
- """
305
-
306
-
307
- elif self.Core.platform == "app":
308
- instructions = f"""
309
- Message Specifications:
310
- - The message is an **in app notification**.
311
- - ** Keep the First sentence as "header" that should be a short personalized eye catching sentence less than 40 character **.
312
- - ** For the "header", don't use exclamation mark at the end, instead, use a space following with a proper emoji at the end of the "header" (e.g. Great work John 😍) **
313
- - **Keep the message concise and straightforward**.
314
- - **Start directly with the message content**; do not include greetings (e.g., "Hello") or closing phrases.
315
- - Make the message highly **personalized** and **eye-catching**.
316
- - "Personalized" means the user should feel the message is specifically crafted for them and not generic.
317
- - **Every word should contribute to maximizing impact and engagement**.
318
- - {message_style}
319
- """
320
-
321
- return instructions
322
-
323
- # --------------------------------------------------------------
324
- # --------------------------------------------------------------
325
- def message_style_instructions(self):
326
- """
327
- defines the style of the message: e.g. friendly, kind, tone, etc.
328
- :return: style_instructions(str)
329
- """
330
-
331
- if self.Core.message_style is None:
332
- message_style = ""
333
-
334
- else:
335
- message_style = f"""
336
- - {self.Core.message_style}.
337
- """
338
-
339
- return message_style
340
 
341
  # --------------------------------------------------------------
342
  # --------------------------------------------------------------
@@ -345,33 +245,25 @@ Your task is to pick a 'header' and a 'message' as a push notification from prov
345
  :return: output instructions as a string
346
  """
347
 
348
- example_output = self.example_output()
349
  general_instructions = f"""
350
- - The "header" must be less than 30 character.
351
- - The "message" must be less than 100 character.
352
- - Preserve special characters and emojis in the message, you are **ONLY ALLOWED**allowed to use {self.Core.get_emoji()} emoji if needed, ONLY ONCE, and ONLY at the end of header or message).
353
- - Ensure that the output is a valid JSON and not include any text outside the JSON code block.
354
  """
355
 
356
  instructions = f"""
357
- Expected output structure:
 
 
358
 
359
  {{
360
- "header": "Generated title",
361
- "message": "Generated message",
362
  }}
363
 
364
  {general_instructions}
365
  """
366
 
367
- output_instructions = f"""
368
- ### **Output instructions**:
369
-
370
- {example_output}
371
- {instructions}
372
- """
373
-
374
- return output_instructions
375
 
376
  # --------------------------------------------------------------
377
  # --------------------------------------------------------------
@@ -388,10 +280,10 @@ Expected output structure:
388
  else:
389
  # one shot prompting
390
  example = f"""
391
- Below are some acceptable examples. Create a header and message that follows the same style, tone, vocabulary, and characteristics of followed examples.
392
 
393
- ### **Good Examples:**
394
- {self.Core.sample_example}
395
  """
396
 
397
  return example
 
84
  input_context = self.input_context()
85
  user_info = self.get_user_profile(user=user)
86
 
87
+ example_output = self.example_output()
 
 
 
88
 
89
  output_instructions = self.output_instruction()
90
 
 
 
 
91
  prompt = f"""
92
  {input_context}
93
 
94
  {user_info}
95
 
96
+ {example_output}
 
 
97
 
98
  {output_instructions}
99
  """
 
108
  """
109
 
110
  context = f"""
111
+ ### Task
112
  Your task is to pick a 'header' and a 'message' as a push notification from provided options for a {self.Core.get_instrument()} student.
113
 
114
  """
115
 
116
  return context
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  # --------------------------------------------------------------
120
  # --------------------------------------------------------------
 
237
 
238
  return final_instructions
239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
 
241
  # --------------------------------------------------------------
242
  # --------------------------------------------------------------
 
245
  :return: output instructions as a string
246
  """
247
 
 
248
  general_instructions = f"""
249
+ - The "header" < 30 and "message" < 100 characters.
250
+ - Ensure that the output is a valid JSON following above structure.
 
 
251
  """
252
 
253
  instructions = f"""
254
+ ### **Output instructions**:
255
+
256
+ **Expected output structure:**
257
 
258
  {{
259
+ "header": "selected header from options",
260
+ "message": "selected message from options",
261
  }}
262
 
263
  {general_instructions}
264
  """
265
 
266
+ return instructions
 
 
 
 
 
 
 
267
 
268
  # --------------------------------------------------------------
269
  # --------------------------------------------------------------
 
280
  else:
281
  # one shot prompting
282
  example = f"""
283
+ Below are the available options to choose for the push notification:
284
 
285
+ ### **Available options:**
286
+ {self.Core.sample_example}
287
  """
288
 
289
  return example