Seth commited on
Commit
8bc8877
·
1 Parent(s): f779bc1
Files changed (1) hide show
  1. backend/app/gpt_service.py +14 -0
backend/app/gpt_service.py CHANGED
@@ -248,6 +248,20 @@ If sender_name is not provided, use "Alex Thompson" as the sender name."""
248
  email_data["subject"] = email_data["subject"].replace("{{first_name}}", first_name)
249
  email_data["subject"] = email_data["subject"].replace("{{company}}", company)
250
  email_data["subject"] = email_data["subject"].replace("{{sender_name}}", "Alex Thompson")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
 
252
  # Return list of email sequences (ensure all fields are strings, not None)
253
  return [{
 
248
  email_data["subject"] = email_data["subject"].replace("{{first_name}}", first_name)
249
  email_data["subject"] = email_data["subject"].replace("{{company}}", company)
250
  email_data["subject"] = email_data["subject"].replace("{{sender_name}}", "Alex Thompson")
251
+
252
+ # Ensure first name is in the greeting if it's missing
253
+ # Fix cases where GPT generates "Hi," instead of "Hi {first_name},"
254
+ body = email_data["body"].strip()
255
+ if first_name and body:
256
+ # Check if body starts with "Hi," or "Hi " but doesn't have the first name
257
+ if body.startswith("Hi,") or (body.startswith("Hi ") and first_name not in body[:50]):
258
+ # Replace "Hi," or "Hi " at the start with "Hi {first_name},"
259
+ if body.startswith("Hi,"):
260
+ email_data["body"] = f"Hi {first_name},\n\n" + body[3:].lstrip()
261
+ elif body.startswith("Hi "):
262
+ # Find where "Hi " ends (after potential whitespace)
263
+ rest = body[3:].lstrip()
264
+ email_data["body"] = f"Hi {first_name},\n\n{rest}"
265
 
266
  # Return list of email sequences (ensure all fields are strings, not None)
267
  return [{