File size: 4,125 Bytes
f8c4dcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
113
114
115
116
117
118
119
120
121
# lisa_hr_agent.py

from langchain_community.llms import Ollama
from datetime import datetime
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
import textwrap

class LISAHRAgent:
    def __init__(self):
        self.memory = {}
        self.questions = [
            ("name", "What is the full name of the selected candidate?"),
            ("job_title", "What is the job title offered?"),
            ("salary", "What is the monthly salary offered (in Rs.)?"),
            ("joining_date", "What is the joining date? (e.g., 5 June 2025)"),
            ("probation_period", "What is the probation period? (e.g., 3 months)?"),
            ("location", "What is the job location?")
        ]
        self.index = 0

    def ask_next(self):
        if self.index < len(self.questions):
            return self.questions[self.index][1]
        return None

    def receive_answer(self, answer):
        key = self.questions[self.index][0]
        self.memory[key] = answer
        self.index += 1

    def is_complete(self):
        return self.index >= len(self.questions)

    def get_inputs(self):
        return {
            **self.memory,
            "today": datetime.today().strftime("%d %B %Y")
        }

def generate_letter_with_llm(data: dict) -> str:
    llm = Ollama(model="phi")  # You can change model if you like

    prompt = f"""

You are a professional HR assistant. Write a detailed and formal appointment letter for a selected candidate with the following information:



Candidate Name: {data['name']}

Job Title: {data['job_title']}

Monthly Salary: Rs. {data['salary']}

Joining Date: {data['joining_date']}

Probation Period: {data['probation_period']}

Location: {data['location']}

Date of Letter: {data['today']}

Company Name: Amsaa

Founder: Amir Hameed



Instructions:

- This is an appointment letter, the candidate has already been selected.

- Include a letterhead title at the top: "Amsaa – Appointment Letter"

- Start with date, recipient name, and subject ("Appointment for the position of [Job Title]")

- Include details like reporting authority, job location, salary in Rs., joining date, probation period.

- Maintain a professional and polite tone throughout.

- Add a paragraph welcoming the candidate and emphasizing the company’s vision and values.

- Conclude with "Sincerely, Amir Hameed, Founder & CEO, Amsaa"

- Format should be clean and easy to read.

"""
    response = llm.invoke(prompt)
    return response.strip()

def save_letter_as_pdf(content: str, filename="appointment_letter.pdf"):
    c = canvas.Canvas(filename, pagesize=A4)
    width, height = A4
    margin = 50
    y_position = height - margin

    # Header
    c.setFont("Helvetica-Bold", 16)
    c.drawString(margin, y_position, "Amsaa – Appointment Letter")
    y_position -= 30

    c.setFont("Helvetica", 12)
    # Wrap and draw each line
    for line in content.split('\n'):
        if not line.strip():
            y_position -= 12
            continue
        wrapped_lines = textwrap.wrap(line, width=95)
        for wrap_line in wrapped_lines:
            c.drawString(margin, y_position, wrap_line)
            y_position -= 14
            if y_position < 50:  # Add new page if needed
                c.showPage()
                y_position = height - margin
                c.setFont("Helvetica", 12)

    c.save()
    print(f"\n[✓] Appointment letter saved as: {filename}")

def main():
    agent = LISAHRAgent()

    print("\n👩‍💼 Welcome to LISA HR — AI HR Assistant (Powered by LLM)\n")

    while not agent.is_complete():
        question = agent.ask_next()
        answer = input(f"{question} ")
        agent.receive_answer(answer)

    print("\n🧠 Generating Appointment Letter with LLM...\n")
    collected_data = agent.get_inputs()
    letter = generate_letter_with_llm(collected_data)

    save_letter_as_pdf(letter)

    print("\n📄 Preview:\n")
    print(letter)

if __name__ == "__main__":
    main()