""" Test script for OpenAI integration. This script tests the 'Why Hire Me' section generation using OpenAI. """ import os import dotenv from openai import OpenAI # Load environment variables from .env file dotenv.load_dotenv() def get_openai_client(): """ Get the OpenAI client with the API key from environment variables. Returns: OpenAI: The OpenAI client """ api_key = os.getenv("OPENAI_API_KEY") if not api_key: raise ValueError("OPENAI_API_KEY environment variable is not set. Please set it in the .env file.") if api_key == "your_openai_api_key_here": raise ValueError("Please replace the placeholder API key in the .env file with your actual OpenAI API key.") return OpenAI(api_key=api_key) def generate_why_hire_me_section(job_description): """ Generate a 'Why Hire Me' section based on the job description using OpenAI. Args: job_description (str): The job description text Returns: str: LaTeX formatted 'Why Hire Me' section """ client = get_openai_client() # Create the prompt for OpenAI prompt = f""" Generate a "Why Hire Me" section for a resume based on the job description below. The section should explain why the candidate is a good fit for the position. Use LaTeX formatting with the '\\section*{{Why Hire Me}}' heading. Keep it concise (3-5 paragraphs), professional, and highlight key qualifications that match the job. Don't mention specific experience unless it's generic enough to apply to most professionals. Job Description: {job_description} The response should be LaTeX formatted text that can be directly inserted into a resume. """ try: response = client.responses.create( model="gpt-5.2-chat-latest", reasoning={"effort": "medium"}, instructions="You are a professional resume writer who specializes in creating compelling 'Why Hire Me' sections for job applications.", input=prompt ) # Extract the generated text from the response why_hire_me_text = response.output_text # Ensure it has the proper LaTeX section heading if not already included if "\\section" not in why_hire_me_text: why_hire_me_text = "\\section*{Why Hire Me}\n" + why_hire_me_text return why_hire_me_text except Exception as e: print(f"Error generating 'Why Hire Me' section: {str(e)}") # Return a fallback section if there's an error return None def main(): """Main function to test the OpenAI integration.""" print("Testing OpenAI integration for 'Why Hire Me' section generation...") # Sample job description job_description = """ Software Engineer - Full Stack Developer Job Description: We are looking for a Full Stack Developer who is passionate about building web applications. The ideal candidate will have experience with both frontend and backend technologies, and a strong understanding of software development principles. Responsibilities: - Develop and maintain web applications using modern JavaScript frameworks (React, Angular) and backend technologies (Node.js, Python) - Write clean, maintainable, and efficient code - Collaborate with cross-functional teams to define and implement new features - Troubleshoot and debug applications - Optimize applications for maximum speed and scalability Requirements: - 3+ years of experience in full-stack development - Proficiency in JavaScript, HTML, CSS, and at least one modern frontend framework (React, Angular, Vue) - Experience with backend development using Node.js, Python, or similar technologies - Knowledge of database systems (SQL, NoSQL) - Familiarity with version control systems (Git) - Strong problem-solving skills and attention to detail - Excellent communication and teamwork skills """ try: # Generate the 'Why Hire Me' section why_hire_me_section = generate_why_hire_me_section(job_description) if why_hire_me_section: print("\nGenerated 'Why Hire Me' section:") print("-" * 80) print(why_hire_me_section) print("-" * 80) print("\nOpenAI integration test completed successfully!") else: print("\nFailed to generate 'Why Hire Me' section.") except Exception as e: print(f"\nOpenAI integration test failed: {str(e)}") if __name__ == "__main__": main()