Overview
TheAIAnalyzer class provides integration with OpenAI’s GPT models to generate structured summaries of job postings. It analyzes extracted skills and requirements to produce professional insights about the role.
AIAnalyzer
Class Definition
Constructor
- Loads environment variables from
.envfile usingdotenv - Retrieves
OPENAI_API_KEYfrom environment variables - Initializes OpenAI client if API key is found
- Sets
self.clienttoNoneif no API key is configured
Methods
generar_resumen()
Generates a structured professional summary of a job posting by analyzing the title and extracted skills using GPT.The job posting title (e.g., “Senior Python Developer”)
List of cleaned skills and requirements extracted from the job description. Should be pre-cleaned using
TextCleaner.limpiar_habilidades().Markdown-formatted summary containing:
- Objetivo del Rol: One-sentence description of what the role seeks
- Stack Tecnológico Principal: Top 5 most important technologies mentioned
- Skills Blandas: Soft skills and personal attributes required
- Nivel de Experiencia: Inferred seniority level (Junior, Mid, Senior)
- OpenAI API key is not configured
- Skills list is empty
- API call fails (network error, quota exceeded, etc.)
- Model:
gpt-3.5-turbo(can be changed togpt-4o-miniorgpt-4) - Temperature:
0.7(balanced creativity) - Max Tokens:
500(concise responses) - Token Optimization: Only the first 30 skills are sent to the API to reduce costs
Prompt Engineering
The analyzer uses a carefully crafted prompt that instructs GPT to act as an expert technical recruiter. The prompt structure:System Message
Error Handling
The class implements graceful error handling for common scenarios:Missing API Key
Missing API Key
Returns:
"⚠️ No se ha configurado la API Key de OpenAI. Crea un archivo .env con OPENAI_API_KEY=..."Empty Skills List
Empty Skills List
Returns:
"⚠️ No se encontraron habilidades para analizar."API Call Failure
API Call Failure
Returns:
"❌ Error al consultar ChatGPT: {error_details}"Common causes:- Network connectivity issues
- Rate limit exceeded
- Insufficient API credits
- Invalid API key
Dependencies
Requires
openai and python-dotenv packages. Install with:Best Practices
API Key Security
Never hardcode API keys. Always use environment variables stored in
.env files that are excluded from version control.Cost Optimization
The analyzer limits skills to the first 30 items to reduce token usage and API costs while maintaining analysis quality.
Pre-clean Data
Always clean skills with
TextCleaner before passing to generar_resumen() to improve GPT analysis quality.Model Selection
Use
gpt-3.5-turbo for speed and cost-effectiveness. Upgrade to gpt-4 for higher quality analysis if needed.