ProximileAdmin commited on
Commit
e51c027
·
verified ·
1 Parent(s): b5d96ec

Update email_processor.py

Browse files
Files changed (1) hide show
  1. email_processor.py +29 -16
email_processor.py CHANGED
@@ -74,38 +74,49 @@ def load_email_guidelines():
74
  print(f"Error loading email guidelines: {e}")
75
  return "No guidelines available."
76
 
77
- def create_email_format_prompt(email_guidelines):
78
  """
79
  Create the prompt template that will be sent to the language model.
80
  Incorporates the provided email guidelines and placeholders for user input.
81
 
82
  Args:
83
  email_guidelines: The guidelines text to include in the prompt
 
84
  """
85
- return """<EMAIL_GUIDELINES>
86
- """ + email_guidelines + """
 
 
 
 
 
 
 
 
87
  </EMAIL_GUIDELINES>
 
88
  =========================
89
 
90
  Your Task:
91
- 1. Review the user's draft email.
92
- 2. Apply the above style, formatting, and general content guidelines to the email.
93
- 3. Output a reformatted email ready for use.
94
 
95
- The following email thread precedes the user's draft email:
96
  <PREVIOUS_EMAILS>
97
- {preceding_conversation}
98
  </PREVIOUS_EMAILS>
99
 
100
- The rough draft of the user's email is as follows:
101
  <USER_EMAIL_DRAFT>
102
- {drafted_user_reply}
103
  </USER_EMAIL_DRAFT>
104
 
105
- Your task is to rewrite the user's email draft to align with the provided guidelines.
106
- Begin your reply with the exact string EMAIL_STARTS_HERE followed by the revised email.
107
- If you have additional suggestions, include them only AFTER the revised email draft, separated by the string SUGGESTIONS_START_HERE.
108
- Do not assume any new information or context beyond what is provided in the user's immediate draft email. Do not add any new URLs, attachments, phone numbers, or other content beyond what is provided in the user's immediate draft email. Do not add a subject line. Begin the email body immediately after EMAIL_STARTS_HERE. Include the user's typical signature at the end of the email, if they have one. Do not use info (even placeholders) that is not provided in the user's immediate draft email or in the preceding email thread (even if the guidelines call for it). Do not use markdown formatting. Assume your redrafted reply message might be sent by the user after only a cursory review."""
 
109
 
110
  def process_email(
111
  preceding_conversation,
@@ -118,7 +129,8 @@ def process_email(
118
  top_p,
119
  password,
120
  clients,
121
- custom_guidelines=None
 
122
  ):
123
  """
124
  Process the email and return a formatted response and suggestions.
@@ -135,6 +147,7 @@ def process_email(
135
  password: The actual password to verify against
136
  clients: Dictionary of configured API clients
137
  custom_guidelines: Optional custom guidelines to use instead of default
 
138
 
139
  Returns:
140
  Tuple of (formatted_email, suggestions)
@@ -153,7 +166,7 @@ def process_email(
153
  email_guidelines = custom_guidelines
154
 
155
  # Get the email format prompt template
156
- email_format_prompt = create_email_format_prompt(email_guidelines)
157
 
158
  # Format the prompt using the template
159
  formatted_prompt = email_format_prompt.format(
 
74
  print(f"Error loading email guidelines: {e}")
75
  return "No guidelines available."
76
 
77
+ def create_email_format_prompt(email_guidelines, identity=None):
78
  """
79
  Create the prompt template that will be sent to the language model.
80
  Incorporates the provided email guidelines and placeholders for user input.
81
 
82
  Args:
83
  email_guidelines: The guidelines text to include in the prompt
84
+ identity: Optional identity perspective to write from
85
  """
86
+ identity_section = ""
87
+ if identity and identity.strip():
88
+ identity_section = f"""
89
+ <IDENTITY>
90
+ The email is being written from the perspective of: {identity}
91
+ </IDENTITY>
92
+ """
93
+
94
+ return f"""<EMAIL_GUIDELINES>
95
+ {email_guidelines}
96
  </EMAIL_GUIDELINES>
97
+ {identity_section}
98
  =========================
99
 
100
  Your Task:
101
+ 1. Review the user's draft email
102
+ 2. Apply the style, formatting, and content guidelines above to improve the email
103
+ 3. Provide a polished, ready-to-send version
104
 
105
+ Previous email thread:
106
  <PREVIOUS_EMAILS>
107
+ {{preceding_conversation}}
108
  </PREVIOUS_EMAILS>
109
 
110
+ User's draft reply:
111
  <USER_EMAIL_DRAFT>
112
+ {{drafted_user_reply}}
113
  </USER_EMAIL_DRAFT>
114
 
115
+ Rewrite the draft to follow the guidelines while preserving the user's intent.
116
+ Begin with EMAIL_STARTS_HERE followed by the revised email.
117
+ If you have suggestions, add them after SUGGESTIONS_START_HERE.
118
+
119
+ Don't add any information not found in the original draft or thread. Don't create new URLs, phone numbers, attachments, or subject lines. Start directly with the email body after EMAIL_STARTS_HERE. Include the user's signature if present in their draft. Don't use markdown formatting."""
120
 
121
  def process_email(
122
  preceding_conversation,
 
129
  top_p,
130
  password,
131
  clients,
132
+ custom_guidelines=None,
133
+ identity=None
134
  ):
135
  """
136
  Process the email and return a formatted response and suggestions.
 
147
  password: The actual password to verify against
148
  clients: Dictionary of configured API clients
149
  custom_guidelines: Optional custom guidelines to use instead of default
150
+ identity: Optional identity perspective to write from
151
 
152
  Returns:
153
  Tuple of (formatted_email, suggestions)
 
166
  email_guidelines = custom_guidelines
167
 
168
  # Get the email format prompt template
169
+ email_format_prompt = create_email_format_prompt(email_guidelines, identity)
170
 
171
  # Format the prompt using the template
172
  formatted_prompt = email_format_prompt.format(