File size: 2,926 Bytes
98346d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
from src.utils.llm import get_llm



EMAIL_PROMPT = PromptTemplate(
    input_variables=["email_type", "context", "tone", "recipient", "sender"],
    template="""You are an expert professional email writer.

    Write a {email_type} email with the following details:
    - Recipient: {recipient}
    - Sender: {sender}
    - Tone: {tone}
    - Context/Purpose: {context}
    Requirements:
    - Write a clear subject line
    - Keep it professional and concise
    - Match the requested tone exactly
    - Include proper greeting and sign-off

Email:"""
)

COVER_LETTER_PROMPT = PromptTemplate(
    input_variables=["job_title", "company", "skills", "experience", "name"],
    template="""You are an expert cover letter writer.

Write a compelling cover letter for the following:
- Applicant Name: {name}
- Job Title: {job_title}
- Company: {company}
- Key Skills: {skills}
- Experience Summary: {experience}

Requirements:
- Start with a strong opening paragraph
- Highlight relevant skills and experience
- Show enthusiasm for the role and company
- End with a clear call to action
- Keep it to 3-4 paragraphs

Cover Letter:"""
)


def write_email(
    email_type: str,
    context: str,
    tone: str = "professional",
    recipient: str = "Team",
    sender: str = "Your Name"
) -> str:
    """
    Generates a professional email.

    Args:
        email_type: Type of email (e.g. follow-up, apology, introduction)
        context: Purpose or context of the email
        tone: Tone of the email (professional, friendly, formal)
        recipient: Name of the recipient
        sender: Name of the sender

    Returns:
        Generated email string
    """
    if not context.strip():
        return "⚠️ Please provide context for the email."
    llm = get_llm()
    chain = EMAIL_PROMPT | llm | StrOutputParser()
    return chain.invoke({
        "email_type": email_type,
        "context": context,
        "tone": tone,
        "recipient": recipient,
        "sender": sender
    })

def write_cover_letter(
    job_title: str,
    company: str,
    skills: str,
    experience: str,
    name: str = "Your Name"
) -> str:
    """
    Generates a cover letter.

    Args:
        job_title: Job title applying for
        company: Company name
        skills: Key skills relevant to the role
        experience: Brief experience summary
        name: Applicant name

    Returns:
        Generated cover letter string
    """
    if not job_title.strip() or not company.strip():
        return "⚠️ Please provide job title and company name."

    llm = get_llm()
    chain = COVER_LETTER_PROMPT | llm | StrOutputParser()

    return chain.invoke({
        "job_title": job_title,
        "company": company,
        "skills": skills,
        "experience": experience,
        "name": name
    })