ak0601 commited on
Commit
ed6d52b
·
verified ·
1 Parent(s): 0a448c3

Update app_hug.py

Browse files
Files changed (1) hide show
  1. app_hug.py +81 -58
app_hug.py CHANGED
@@ -55,7 +55,7 @@ class MessageType(str, Enum):
55
  FOLLOWUP = "followup"
56
 
57
  class GenerateMessageRequest(BaseModel):
58
- job_evaluation: str
59
  sender_email: EmailStr
60
  reply_to_email: Optional[EmailStr] = Field(None, description="Recruiter's email for reply-to header")
61
  recipient_email: EmailStr
@@ -68,6 +68,7 @@ class GenerateMessageRequest(BaseModel):
68
  organisation: str
69
  message_type: MessageType
70
  send_email: bool = False
 
71
 
72
  class FeedbackRequest(BaseModel):
73
  message: str
@@ -178,7 +179,6 @@ def create_email_message(sender: str, to: str, subject: str, message_text: str,
178
  message["Subject"] = subject
179
  if reply_to:
180
  message["Reply-To"] = reply_to
181
- message["Cc"] = reply_to
182
  raw_message = base64.urlsafe_b64encode(message.as_bytes()).decode()
183
  return {"raw": raw_message}
184
 
@@ -255,8 +255,9 @@ def generate_recruitment_message_with_subject(
255
  org: str,
256
  candidate: str,
257
  current_pos: str,
258
- evaluation: str,
259
- feedback: Optional[str] = None
 
260
  ) -> Tuple[str, str]:
261
  api_key = os.getenv("OPENAI_API_KEY")
262
  llm = ChatOpenAI(
@@ -265,44 +266,64 @@ def generate_recruitment_message_with_subject(
265
  max_tokens=600,
266
  openai_api_key=api_key
267
  )
268
- base_prompt = f"""
269
- Generate a professional recruitment {msg_type} with the following details:
270
- - Company hiring: {company}
271
- - Role: {role_title}
272
- - Recruiter: {recruiter} from {org}
273
- - Candidate: {candidate}
274
- - Candidate's current position: {current_pos}
275
- - Evaluation: {evaluation}
276
- """
277
  if msg_type == "outreach":
278
- prompt = base_prompt + """
279
- Create an initial outreach message that:
280
- - Introduces the recruiter and organization
281
- - Mentions the specific role and company
282
- - Expresses interest in discussing the opportunity
283
- - Keeps it short and to the point.
284
- - Do not include any placeholders like [Candidate Name] or [Role Title] in the email.
285
- """
286
- elif msg_type == "introductory":
287
- prompt = base_prompt + """
288
- Create an introductory message that:
289
- - Thanks the candidate for their initial response
290
- - Provides more details about the role and company
291
- - Explains why this opportunity aligns with their background
292
- - Suggests next steps (like a call or meeting)
293
- - Maintains a warm, professional tone
294
  """
295
- else: # followup
296
- prompt = base_prompt + """
297
- Create a follow-up message that:
298
- - References previous communication
299
- - Reiterates interest in the candidate
300
- - Addresses any potential concerns
301
- - Provides additional compelling reasons to consider the role
302
- - Includes a clear call to action
303
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  if feedback:
305
  prompt += f"\n\nPlease modify the message based on this feedback: {feedback}"
 
 
 
 
 
 
 
 
 
 
 
 
306
  prompt += """
307
 
308
  Please provide your response in the following format:
@@ -311,6 +332,7 @@ def generate_recruitment_message_with_subject(
311
  BODY:
312
  [Your email body content here]
313
  """
 
314
  try:
315
  messages = [
316
  SystemMessage(content="You are a professional recruitment message writer. Generate both an email subject line and body content. Follow the exact format requested."),
@@ -398,17 +420,17 @@ async def send_message(request: SendMessageRequest):
398
 
399
 
400
  formatted_html = format_email_html(
401
- request.email_body
402
- )
403
  # Create the email
404
  email_message = create_email_message(
405
- sender=request.sender_email,
406
- to=request.recipient_email,
407
- subject=request.subject,
408
- message_text=formatted_html,
409
- reply_to=request.reply_to_email,
410
- is_html=True
411
- )
412
  # Send the email
413
  email_sent = send_gmail_message(service, "me", email_message)
414
  if email_sent:
@@ -445,7 +467,8 @@ async def generate_message(request: GenerateMessageRequest, background_tasks: Ba
445
  org=request.organisation,
446
  candidate=request.candidate_name,
447
  current_pos=current_position,
448
- evaluation=request.job_evaluation
 
449
  )
450
  email_sent = False
451
  if request.send_email:
@@ -464,18 +487,18 @@ async def generate_message(request: GenerateMessageRequest, background_tasks: Ba
464
  service = authenticate_gmail(request.sender_email)
465
  if service:
466
  formatted_html = format_email_html(
467
- generated_message,
468
- sender_name=request.recruiter_name,
469
- sender_org=request.organisation
470
- )
471
  email_message = create_email_message(
472
- sender=request.sender_email,
473
- to=request.recipient_email,
474
- subject=email_subject,
475
- message_text=formatted_html,
476
- reply_to=request.reply_to_email,
477
- is_html=True
478
- )
479
  email_sent = send_gmail_message(service, "me", email_message)
480
  if not email_sent:
481
  return MessageResponse(
 
55
  FOLLOWUP = "followup"
56
 
57
  class GenerateMessageRequest(BaseModel):
58
+ job_evaluation: Optional[str] = Field(None, description="(Optional) Recruiter's evaluation of candidate for the job")
59
  sender_email: EmailStr
60
  reply_to_email: Optional[EmailStr] = Field(None, description="Recruiter's email for reply-to header")
61
  recipient_email: EmailStr
 
68
  organisation: str
69
  message_type: MessageType
70
  send_email: bool = False
71
+ past_conversation: Optional[str] = Field(None, description="(Optional) Previous messages with candidate")
72
 
73
  class FeedbackRequest(BaseModel):
74
  message: str
 
179
  message["Subject"] = subject
180
  if reply_to:
181
  message["Reply-To"] = reply_to
 
182
  raw_message = base64.urlsafe_b64encode(message.as_bytes()).decode()
183
  return {"raw": raw_message}
184
 
 
255
  org: str,
256
  candidate: str,
257
  current_pos: str,
258
+ evaluation: Optional[str] = None,
259
+ feedback: Optional[str] = None,
260
+ past_conversation: Optional[str] = None
261
  ) -> Tuple[str, str]:
262
  api_key = os.getenv("OPENAI_API_KEY")
263
  llm = ChatOpenAI(
 
266
  max_tokens=600,
267
  openai_api_key=api_key
268
  )
269
+ # Outreach: Only request consent
 
 
 
 
 
 
 
 
270
  if msg_type == "outreach":
271
+ prompt = f"""
272
+ Generate a professional initial outreach message to a candidate.
273
+ - Introduce yourself as {recruiter} from {org}
274
+ - Clearly state you are reaching out about an open role ({role_title}) at {company}
275
+ - Ask if they are open to learning more or interested in a quick chat.
276
+ - Do NOT discuss any job evaluation or judgment.
277
+ - Explicitly request their consent to share more details. E.g., 'Would you be open to hearing more about this opportunity?'
278
+ - Keep it short and friendly.
279
+ - No placeholders like [Candidate Name] or [Role Title] in the output.
 
 
 
 
 
 
 
280
  """
281
+ else:
282
+ base_prompt = f"""
283
+ Generate a professional recruitment {msg_type} with the following details:
284
+ - Company hiring: {company}
285
+ - Role: {role_title}
286
+ - Recruiter: {recruiter} from {org}
287
+ - Candidate: {candidate}
288
+ - Candidate's current position: {current_pos}
289
  """
290
+ if evaluation:
291
+ base_prompt += f"- Evaluation: {evaluation}\n"
292
+ prompt = base_prompt
293
+ if msg_type == "introductory":
294
+ prompt += """
295
+ Create an introductory message that:
296
+ - Thanks the candidate for their initial response
297
+ - Provides more details about the role and company
298
+ - Explains why this opportunity aligns with their background
299
+ - Suggests next steps (like a call or meeting)
300
+ - Maintains a warm, professional tone
301
+ """
302
+ else: # followup
303
+ prompt += """
304
+ Create a follow-up message that:
305
+ - References previous communication
306
+ - Reiterates interest in the candidate
307
+ - Addresses any potential concerns
308
+ - Provides additional compelling reasons to consider the role
309
+ - Includes a clear call to action
310
+ """
311
+
312
+ # Use feedback if provided
313
  if feedback:
314
  prompt += f"\n\nPlease modify the message based on this feedback: {feedback}"
315
+
316
+ # Use past conversation if provided
317
+ if past_conversation:
318
+ prompt += f"""
319
+ Use the following past conversation as context to inform your reply:
320
+
321
+ PAST CONVERSATION:
322
+ {past_conversation}
323
+
324
+ Write a reply message to the candidate, maintaining professionalism and continuity.
325
+ """
326
+
327
  prompt += """
328
 
329
  Please provide your response in the following format:
 
332
  BODY:
333
  [Your email body content here]
334
  """
335
+
336
  try:
337
  messages = [
338
  SystemMessage(content="You are a professional recruitment message writer. Generate both an email subject line and body content. Follow the exact format requested."),
 
420
 
421
 
422
  formatted_html = format_email_html(
423
+ request.email_body
424
+ )
425
  # Create the email
426
  email_message = create_email_message(
427
+ sender=request.sender_email,
428
+ to=request.recipient_email,
429
+ subject=request.subject,
430
+ message_text=formatted_html,
431
+ reply_to=request.reply_to_email,
432
+ is_html=True
433
+ )
434
  # Send the email
435
  email_sent = send_gmail_message(service, "me", email_message)
436
  if email_sent:
 
467
  org=request.organisation,
468
  candidate=request.candidate_name,
469
  current_pos=current_position,
470
+ evaluation=request.job_evaluation,
471
+ past_conversation=request.past_conversation
472
  )
473
  email_sent = False
474
  if request.send_email:
 
487
  service = authenticate_gmail(request.sender_email)
488
  if service:
489
  formatted_html = format_email_html(
490
+ generated_message,
491
+ sender_name=request.recruiter_name,
492
+ sender_org=request.organisation
493
+ )
494
  email_message = create_email_message(
495
+ sender=request.sender_email,
496
+ to=request.recipient_email,
497
+ subject=email_subject,
498
+ message_text=formatted_html,
499
+ reply_to=request.reply_to_email,
500
+ is_html=True
501
+ )
502
  email_sent = send_gmail_message(service, "me", email_message)
503
  if not email_sent:
504
  return MessageResponse(