resumate / functions /writer_agent.py
gperdrizet's picture
General clean up, added save of results to linkedin resume parsing and github repo list retreival.
b9464fb verified
raw
history blame
2.16 kB
'''Agent responsible for writing the resume based on user provided context'''
import json
import logging
import os
from smolagents import CodeAgent
from configuration import AGENT_MODEL, INSTRUCTIONS
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def write_resume(content: str, user_instructions: str = 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.
Returns:
str: The generated resume.
"""
if content['status'] == 'success':
agent = CodeAgent(
model=AGENT_MODEL,
tools=[],
additional_authorized_imports=['json'],
name="writer_agent",
verbosity_level=5,
max_steps=20,
planning_interval=5
)
# Prepare instructions - combine default with user instructions
instructions = INSTRUCTIONS
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: # pylint: disable=broad-exception-caught
logger.error("Failed to save resume to file: %s", e)
return submitted_answer