import json def extract_json(input_string: str) -> dict: """String to Json function""" # First, ensure we remove json wrapper input_string = input_string.replace("```json", "```").replace("```", "") # Now, ensure we have stripped everything so it is just json input_string_formatted = input_string.lstrip("{").rstrip("}") # Ensure we do not have the weird \_ behaviour that models sometimes include input_string_formatted = input_string_formatted.replace("\_", "_") try: return True, json.loads(input_string_formatted) except json.JSONDecodeError as e: print(f"Error parsing JSON Output: {input_string}. Error: {e}") return False, {} def generate_markdown_report(data): # Header report = f"# CV Analysis Report\n\n" report += f"**Name:** {data.get('personName', 'Unknown')} \n" report += f"**Job:** {data.get('jobTitle', 'N/A')} at {data.get('companyName', 'N/A')} \n" report += ( f"**Job Description:** {data.get('jobDesc', 'No description available.')}\n\n" ) report += "---\n\n" report += "## Key Findings\n\n" experiences = data.get("experience", []) if experiences: report += "### Experience\n\n" report += ( "| Job Posting Requirement | CV Details | Explanation | Impact Score |\n" ) report += ( "| ----------------------- | ---------- | ----------- | -------------- |\n" ) for exp in experiences: report += f"| {exp.get('jobPostingDetails', 'N/A')} | {exp.get('cvDetails', 'N/A')} | {exp.get('explanation', '')} | **{exp.get('severityScore', 0)}** |\n" report += "\n" education = data.get("education", []) if education: report += "### Education\n\n" report += ( "| Job Posting Requirement | CV Details | Explanation | Impact Score |\n" ) report += ( "| ----------------------- | ---------- | ----------- | -------------- |\n" ) for edu in education: report += f"| {edu.get('jobPostingDetails', 'N/A')} | {edu.get('cvDetails', 'N/A')} | {edu.get('explanation', '')} | **{edu.get('severityScore', 0)}** |\n" report += "\n" responsibilities = data.get("responsibilities", []) if responsibilities: report += "### Responsibilities\n\n" report += ( "| Job Posting Requirement | CV Details | Explanation | Impact Score |\n" ) report += ( "| ----------------------- | ---------- | ----------- | -------------- |\n" ) for resp in responsibilities: report += f"| {resp.get('jobPostingDetails', 'N/A')} | {resp.get('cvDetails', 'N/A')} | {resp.get('explanation', '')} | **{resp.get('severityScore', 0)}** |\n" report += "\n" languages = data.get("languages", []) if languages: report += "### Languages\n\n" report += ( "| Job Posting Requirement | CV Details | Explanation | Impact Score |\n" ) report += ( "| ----------------------- | ---------- | ----------- | -------------- |\n" ) for lang in languages: report += f"| {lang.get('jobPostingDetails', 'N/A')} | {lang.get('cvDetails', 'N/A')} | {lang.get('explanation', '')} | **{lang.get('severityScore', 0)}** |\n" report += "\n" # Tools tools = data.get("tools", []) if tools: report += "### Tools\n\n" report += ( "| Job Posting Requirement | CV Details | Explanation | Impact Score |\n" ) report += ( "| ----------------------- | ---------- | ----------- | -------------- |\n" ) for tool in tools: report += f"| {tool.get('jobPostingDetails', 'N/A')} | {tool.get('cvDetails', 'N/A')} | {tool.get('explanation', '')} | **{tool.get('severityScore', 0)}** |\n" report += "\n" # Closing report += "---\n" return report def format_chat_history_cohere(chat_history: list, background_info: dict) -> list: """Takes streamlit chat history, and converts to cohere format""" # Could use cohere to track history, maybe for the future new_output = [ { "role": "USER", "message": f"Hi there! Here is my CV! {background_info['cv']}.\n\n I'd like you to act as a senior technical recruiter, recruiting for a role at a specific company. I want you to ask highly specific questions about the role, and critique my CV and its' suitability for the role. Please also ask general interview questions.", }, { "role": "CHATBOT", "message": f"Thanks. Can you send me the job posting?", }, { "role": "USER", "message": f"Here is the job posting: {background_info['job_posting']}", }, ] for item in chat_history: new_output.append( { "role": "USER" if item["role"] == "user" else "CHATBOT", "message": item["message"], } ) return new_output if __name__ == "__main__": example_json = """ """ extract_json(example_json)