File size: 2,689 Bytes
91b2483
 
 
 
edc4b6c
7482626
 
91b2483
f9a80bc
 
91b2483
 
 
b91ffb5
91b2483
 
 
 
 
 
edc4b6c
b91ffb5
91b2483
 
 
 
 
 
b9464fb
7482626
 
 
 
 
 
91b2483
7482626
91b2483
2db495f
91b2483
32f0097
91b2483
 
 
 
bef6750
7482626
b9464fb
b91ffb5
 
 
bef6750
edc4b6c
b9464fb
edc4b6c
 
 
91b2483
edc4b6c
91b2483
 
b9464fb
 
edc4b6c
 
b9464fb
edc4b6c
b9464fb
edc4b6c
 
b9464fb
edc4b6c
 
b9464fb
edc4b6c
 
 
b9464fb
edc4b6c
b9464fb
f9a80bc
edc4b6c
b9464fb
 
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
'''Agent responsible for writing the resume based on user provided context'''

import json
import logging
import os
from smolagents import OpenAIServerModel, CodeAgent
from configuration import INFERENCE_URL, AGENT_MODEL, AGENT_INSTRUCTIONS

# pylint: disable=broad-exception-caught

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def write_resume(content: str, user_instructions: str = None, job_summary: dict = None) -> str:

    """
    Generates a resume based on the provided content.

    Args:
        content (str): The content to be used for generating the resume.
        user_instructions (str, optional): Additional instructions from the user.
        job_summary (dict, optional): Extracted/summarized job call information.

    Returns:
        str: The generated resume.
    """

    if content['status'] == 'success':

        model = OpenAIServerModel(
            model_id=AGENT_MODEL,
            api_base=INFERENCE_URL,
            api_key=os.environ.get("API_KEY"),
        )

        agent = CodeAgent(
            model=model,
            tools=[],
            additional_authorized_imports=['json', 'pandas'],
            name="writer_agent",
            verbosity_level=1,
            max_steps=20,
            planning_interval=5
        )

        # Prepare instructions - combine default with user instructions and job summary
        instructions = AGENT_INSTRUCTIONS

        if job_summary is not None:
            instructions += f"\n\nJob Requirements and Details:\n{json.dumps(job_summary)}"
            logger.info("Added job summary to agent prompt")

        if user_instructions and user_instructions.strip():

            instructions += f"\n\nAdditional user instructions:\n{user_instructions.strip()}"
            logger.info("Added user instructions to agent prompt")

        submitted_answer = agent.run(
            instructions + '\n' + json.dumps(content['structured_text']),
        )

        logger.info("submitted_answer: %s", submitted_answer)

        # Create data directory if it doesn't exist
        data_dir = 'data'

        if not os.path.exists(data_dir):

            os.makedirs(data_dir)
            logger.info("Created data directory: %s", data_dir)

        # Save the resume to resume.md in the data directory
        resume_file_path = os.path.join(data_dir, 'resume.md')

        try:
            with open(resume_file_path, 'w', encoding='utf-8') as f:
                f.write(submitted_answer)

            logger.info("Resume saved to: %s", resume_file_path)

        except Exception as e:
            logger.error("Failed to save resume to file: %s", e)

    return submitted_answer