Danialebrat commited on
Commit
e2e92de
·
1 Parent(s): dac4a38

fixing bugs - header and message exceeding character limit

Browse files
Config_files/message_system_config.json CHANGED
@@ -19,8 +19,8 @@
19
  ],
20
  "AI_Jargon": ["elevate", "enhance", "ignite", "reignite", "rekindle", "rediscover","passion", "boost", "fuel", "thrill", "revive", "spark", "performing", "fresh", "tone", "enthusiasm", "illuminate"],
21
  "AI_phrases_singeo": ["your voice deserves more"],
22
- "header_limit": 35,
23
- "message_limit": 115,
24
  "LLM_models": ["gpt-4o-mini", "gpt-4o", "gpt-4.1-mini", "gemini-2.5-flash-lite-preview-06-17", "claude-3-5-haiku-latest", "google/gemma-3-27b-instruct/bf-16"],
25
  "openai_models": ["gpt-4o-mini", "gpt-4o", "gpt-4.1-nano", "gpt-3.5-turbo", "gpt-4.1-mini"],
26
  "reasoning": ["o1", "o4-mini", "o1-mini", "o3-mini"],
 
19
  ],
20
  "AI_Jargon": ["elevate", "enhance", "ignite", "reignite", "rekindle", "rediscover","passion", "boost", "fuel", "thrill", "revive", "spark", "performing", "fresh", "tone", "enthusiasm", "illuminate"],
21
  "AI_phrases_singeo": ["your voice deserves more"],
22
+ "header_limit": 30,
23
+ "message_limit": 135,
24
  "LLM_models": ["gpt-4o-mini", "gpt-4o", "gpt-4.1-mini", "gemini-2.5-flash-lite-preview-06-17", "claude-3-5-haiku-latest", "google/gemma-3-27b-instruct/bf-16"],
25
  "openai_models": ["gpt-4o-mini", "gpt-4o", "gpt-4.1-nano", "gpt-3.5-turbo", "gpt-4.1-mini"],
26
  "reasoning": ["o1", "o4-mini", "o1-mini", "o3-mini"],
Messaging_system/LLM.py CHANGED
@@ -152,7 +152,7 @@ class LLM:
152
  print(e.response)
153
 
154
  print("Max retries exceeded. Returning empty response.")
155
- return [], {}
156
 
157
  # =========================================================================
158
  def get_message_google(self, prompt, instructions, max_retries=4):
@@ -182,6 +182,10 @@ class LLM:
182
  output["message"].strip()) > self.Core.config_file["message_limit"]:
183
  print(
184
  f"'header' or 'message' is more than specified characters in response on attempt {attempt + 1}. Retrying...")
 
 
 
 
185
  continue
186
  return output
187
 
@@ -191,7 +195,7 @@ class LLM:
191
  print(f"Error in attempt {attempt}: {e}")
192
 
193
  print("Max retries exceeded. Returning empty response.")
194
- return [], {}
195
 
196
  # =========================================================================
197
 
@@ -273,7 +277,7 @@ class LLM:
273
  print(e.response)
274
 
275
  print("Max retries exceeded. Returning empty response.")
276
- return [], {}
277
 
278
  # ======================================================================
279
 
@@ -331,7 +335,7 @@ class LLM:
331
  print("Error processing output:", parse_error)
332
 
333
  print("Max retries exceeded. Returning empty response.")
334
- return [], {}
335
 
336
  def get_message_claude(self, prompt, instructions, max_retries=4):
337
  """
@@ -387,7 +391,7 @@ class LLM:
387
  print("Error processing output:", parse_error)
388
 
389
  print("Max retries exceeded. Returning empty response.")
390
- return [], {}
391
 
392
  # ======================================================================
393
 
 
152
  print(e.response)
153
 
154
  print("Max retries exceeded. Returning empty response.")
155
+ return None
156
 
157
  # =========================================================================
158
  def get_message_google(self, prompt, instructions, max_retries=4):
 
182
  output["message"].strip()) > self.Core.config_file["message_limit"]:
183
  print(
184
  f"'header' or 'message' is more than specified characters in response on attempt {attempt + 1}. Retrying...")
185
+ headchar= len(output["header"].strip())
186
+ messagechar = len(output["message"].strip())
187
+ print(
188
+ f"'header' has {headchar} chars and 'message' has {messagechar} ...")
189
  continue
190
  return output
191
 
 
195
  print(f"Error in attempt {attempt}: {e}")
196
 
197
  print("Max retries exceeded. Returning empty response.")
198
+ return None
199
 
200
  # =========================================================================
201
 
 
277
  print(e.response)
278
 
279
  print("Max retries exceeded. Returning empty response.")
280
+ return None
281
 
282
  # ======================================================================
283
 
 
335
  print("Error processing output:", parse_error)
336
 
337
  print("Max retries exceeded. Returning empty response.")
338
+ return None
339
 
340
  def get_message_claude(self, prompt, instructions, max_retries=4):
341
  """
 
391
  print("Error processing output:", parse_error)
392
 
393
  print("Max retries exceeded. Returning empty response.")
394
+ return None
395
 
396
  # ======================================================================
397
 
Messaging_system/Message_generator.py CHANGED
@@ -186,7 +186,7 @@ Common instructor phrases:
186
 
187
  ABSOLUTE RULE – OVERRIDES EVERYTHING ELSE:
188
  the header and the message **MUST NOT** contain any banned word or phrases(case-insensitive; singular, plural, verb forms, or their derivatives)
189
- - **important Note:** header must be less than {self.Core.config_file["header_limit"]} and message must be less than {self.Core.config_file["message_limit"]} characters.
190
 
191
 
192
  Banned word:
 
186
 
187
  ABSOLUTE RULE – OVERRIDES EVERYTHING ELSE:
188
  the header and the message **MUST NOT** contain any banned word or phrases(case-insensitive; singular, plural, verb forms, or their derivatives)
189
+ - **important Note:** header **must be** less than {self.Core.config_file["header_limit"]} characters and message **must be less** than {self.Core.config_file["message_limit"]} characters.
190
 
191
 
192
  Banned word:
Messaging_system/MultiMessage.py CHANGED
@@ -34,7 +34,7 @@ class MultiMessage:
34
  Subsequent messages are generated by referencing all previously generated ones.
35
  """
36
  first_message_str = user.get("message", None)
37
- if not first_message_str:
38
  print("No initial message found; cannot build a multi-message sequence.")
39
  return None
40
 
@@ -79,7 +79,7 @@ class MultiMessage:
79
 
80
  # ---- (B) actually generate the next message; hand it the UPDATED user ----
81
  next_msg_raw = self.generate_next_messages(message_sequence, msg_number, user)
82
- if not next_msg_raw:
83
  print(f"Could not generate the message for step {msg_number}. Stopping.")
84
  break
85
 
@@ -167,7 +167,7 @@ Mimic the example style as much as possible and make it personalized using provi
167
  for i, m in enumerate(recent_messages, start=1):
168
  header = m.get("header", "").strip()
169
  body = m.get("message", "").strip()
170
- previous_text.append(f"Message {i}: (Header) {header}\n (Body) {body}")
171
 
172
  # Combine into a single string
173
  previous_text_str = "\n\n".join(previous_text)
@@ -373,7 +373,7 @@ Common instructor phrases:
373
 
374
  ABSOLUTE RULE – OVERRIDES EVERYTHING ELSE:
375
  the header and the message **MUST NOT** contain any banned word or phrases(case-insensitive; singular, plural, verb forms, or their derivatives)
376
- - **important Note:** header must be less than {self.Core.config_file["header_limit"]} and message must be less than {self.Core.config_file["message_limit"]} characters.
377
 
378
  Banned word:
379
  {jargon_list}
 
34
  Subsequent messages are generated by referencing all previously generated ones.
35
  """
36
  first_message_str = user.get("message", None)
37
+ if first_message_str is None:
38
  print("No initial message found; cannot build a multi-message sequence.")
39
  return None
40
 
 
79
 
80
  # ---- (B) actually generate the next message; hand it the UPDATED user ----
81
  next_msg_raw = self.generate_next_messages(message_sequence, msg_number, user)
82
+ if next_msg_raw is None:
83
  print(f"Could not generate the message for step {msg_number}. Stopping.")
84
  break
85
 
 
167
  for i, m in enumerate(recent_messages, start=1):
168
  header = m.get("header", "").strip()
169
  body = m.get("message", "").strip()
170
+ previous_text.append(f"Message {i}:\n header: {header}\n message: {body}")
171
 
172
  # Combine into a single string
173
  previous_text_str = "\n\n".join(previous_text)
 
373
 
374
  ABSOLUTE RULE – OVERRIDES EVERYTHING ELSE:
375
  the header and the message **MUST NOT** contain any banned word or phrases(case-insensitive; singular, plural, verb forms, or their derivatives)
376
+ - **important Note:** header **must be** less than {self.Core.config_file["header_limit"]} characters and message **must be less** than {self.Core.config_file["message_limit"]} characters.
377
 
378
  Banned word:
379
  {jargon_list}
Messaging_system/PromptGenerator.py CHANGED
@@ -51,7 +51,7 @@ Use these info only to *flavour* the header and message if they add value. Never
51
  - {self.safe_get(self.Core.segment_info)}
52
  - first name: {self.safe_get(user.get("first_name"))} --> Only use if is available and the first name is a **valid name**
53
  - Experience level (0-9): {self.safe_get(user.get("difficulty"))}
54
- - User profile --> use **indirectly** if it can improve personalization:
55
  {self.safe_get(user.get("user_info"))}
56
  """
57
  return user_info
@@ -197,8 +197,9 @@ Goal: Make the recommendation feel personalized and casually relevant — not ge
197
 
198
  general_instructions = f"""
199
  - Ensure that the output is a valid JSON following above structure.
200
- - header < {self.Core.config_file["header_limit"]} and message < {self.Core.config_file["message_limit"]} characters.
201
  - 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).
 
 
202
  """
203
 
204
  instructions = f"""
 
51
  - {self.safe_get(self.Core.segment_info)}
52
  - first name: {self.safe_get(user.get("first_name"))} --> Only use if is available and the first name is a **valid name**
53
  - Experience level (0-9): {self.safe_get(user.get("difficulty"))}
54
+ - User profile --> use **indirectly** if it can improve personalization and **do not** use their preferences keywords ("genre, styles") directly in the message:
55
  {self.safe_get(user.get("user_info"))}
56
  """
57
  return user_info
 
197
 
198
  general_instructions = f"""
199
  - Ensure that the output is a valid JSON following above structure.
 
200
  - 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).
201
+ - **important Note:** header **must be** less than {self.Core.config_file["header_limit"]} characters and message **must be less** than {self.Core.config_file["message_limit"]} characters.
202
+
203
  """
204
 
205
  instructions = f"""
messaging_main_test.py CHANGED
@@ -129,7 +129,7 @@ if __name__ == "__main__":
129
  recsys_contents = ["workout", "course", "quick_tips"]
130
 
131
  # number_of_samples = users.shape[0]
132
- number_of_samples = 10
133
 
134
  # number of messages to generate
135
  number_of_messages = 3
 
129
  recsys_contents = ["workout", "course", "quick_tips"]
130
 
131
  # number_of_samples = users.shape[0]
132
+ number_of_samples = 20
133
 
134
  # number of messages to generate
135
  number_of_messages = 3