Spaces:
Running
Running
Update tools/email_server.py
Browse files- tools/email_server.py +9 -10
tools/email_server.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
from utils.llm_utils import get_llm_response
|
| 2 |
from email.mime.text import MIMEText
|
| 3 |
from email.mime.multipart import MIMEMultipart
|
|
|
|
|
|
|
| 4 |
import json
|
| 5 |
|
| 6 |
|
|
@@ -24,10 +26,8 @@ async def draft_email(
|
|
| 24 |
"""
|
| 25 |
try:
|
| 26 |
prompt = f"""Draft a {tone} email with the following details:
|
| 27 |
-
|
| 28 |
Recipient: {recipient}
|
| 29 |
Subject: {subject}
|
| 30 |
-
|
| 31 |
Context/Purpose:
|
| 32 |
{context}
|
| 33 |
|
|
@@ -42,9 +42,8 @@ Tone should be: {tone}
|
|
| 42 |
|
| 43 |
email_body = await get_llm_response(prompt, temperature=0.7)
|
| 44 |
|
| 45 |
-
# Create formatted email
|
| 46 |
-
email_html = f"""
|
| 47 |
-
<!DOCTYPE html>
|
| 48 |
<html>
|
| 49 |
<head>
|
| 50 |
<style>
|
|
@@ -69,12 +68,11 @@ Tone should be: {tone}
|
|
| 69 |
</div>
|
| 70 |
</div>
|
| 71 |
</body>
|
| 72 |
-
</html>
|
| 73 |
-
"""
|
| 74 |
|
| 75 |
# Save to file
|
|
|
|
| 76 |
output_path = f"data/outputs/email_draft_{datetime.now().strftime('%Y%m%d_%H%M%S')}.html"
|
| 77 |
-
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
|
| 78 |
|
| 79 |
with open(output_path, 'w', encoding='utf-8') as f:
|
| 80 |
f.write(email_html)
|
|
@@ -114,7 +112,9 @@ Write a professional reply email."""
|
|
| 114 |
|
| 115 |
reply = await get_llm_response(prompt, temperature=0.7)
|
| 116 |
|
|
|
|
| 117 |
output_path = f"data/outputs/email_reply_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
|
|
|
|
| 118 |
with open(output_path, 'w', encoding='utf-8') as f:
|
| 119 |
f.write(reply)
|
| 120 |
|
|
@@ -125,5 +125,4 @@ Write a professional reply email."""
|
|
| 125 |
}
|
| 126 |
|
| 127 |
except Exception as e:
|
| 128 |
-
return {'error': str(e), 'success': False}
|
| 129 |
-
|
|
|
|
| 1 |
from utils.llm_utils import get_llm_response
|
| 2 |
from email.mime.text import MIMEText
|
| 3 |
from email.mime.multipart import MIMEMultipart
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from datetime import datetime
|
| 6 |
import json
|
| 7 |
|
| 8 |
|
|
|
|
| 26 |
"""
|
| 27 |
try:
|
| 28 |
prompt = f"""Draft a {tone} email with the following details:
|
|
|
|
| 29 |
Recipient: {recipient}
|
| 30 |
Subject: {subject}
|
|
|
|
| 31 |
Context/Purpose:
|
| 32 |
{context}
|
| 33 |
|
|
|
|
| 42 |
|
| 43 |
email_body = await get_llm_response(prompt, temperature=0.7)
|
| 44 |
|
| 45 |
+
# Create formatted email HTML
|
| 46 |
+
email_html = f"""<!DOCTYPE html>
|
|
|
|
| 47 |
<html>
|
| 48 |
<head>
|
| 49 |
<style>
|
|
|
|
| 68 |
</div>
|
| 69 |
</div>
|
| 70 |
</body>
|
| 71 |
+
</html>"""
|
|
|
|
| 72 |
|
| 73 |
# Save to file
|
| 74 |
+
Path("data/outputs").mkdir(parents=True, exist_ok=True)
|
| 75 |
output_path = f"data/outputs/email_draft_{datetime.now().strftime('%Y%m%d_%H%M%S')}.html"
|
|
|
|
| 76 |
|
| 77 |
with open(output_path, 'w', encoding='utf-8') as f:
|
| 78 |
f.write(email_html)
|
|
|
|
| 112 |
|
| 113 |
reply = await get_llm_response(prompt, temperature=0.7)
|
| 114 |
|
| 115 |
+
Path("data/outputs").mkdir(parents=True, exist_ok=True)
|
| 116 |
output_path = f"data/outputs/email_reply_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
|
| 117 |
+
|
| 118 |
with open(output_path, 'w', encoding='utf-8') as f:
|
| 119 |
f.write(reply)
|
| 120 |
|
|
|
|
| 125 |
}
|
| 126 |
|
| 127 |
except Exception as e:
|
| 128 |
+
return {'error': str(e), 'success': False}
|
|
|