Spaces:
Configuration error
Configuration error
'''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 | |