Spaces:
Configuration error
Configuration error
File size: 2,162 Bytes
91b2483 edc4b6c 91b2483 edc4b6c 91b2483 edc4b6c 91b2483 b9464fb 91b2483 edc4b6c b9464fb edc4b6c b9464fb edc4b6c 91b2483 edc4b6c 91b2483 b9464fb edc4b6c b9464fb edc4b6c b9464fb edc4b6c b9464fb edc4b6c b9464fb edc4b6c b9464fb edc4b6c b9464fb 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 |
'''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
|