Overview
TheAIClient class is the main interface for AI-powered interview operations. It handles question generation and feedback analysis by coordinating with AI providers through the provider manager.
Initialization
Provider manager instance that handles AI provider coordination and failover
Methods
generate_first_question()
Generates the opening interview question based on the candidate’s CV and job details.The candidate’s CV/resume text content
The job description text
The position title being interviewed for
The hiring company name
A clean, professional opening interview question without prefixes or formatting
- Uses
PromptTemplates.first_question_generation()to create the prompt - Strips common prefixes like “Question:” or “Here’s a question:”
- Raises
AIServiceErrorif the response is empty - Located at:
client/ai_client.py:17
generate_followup_question()
Generates follow-up questions based on conversation history and context.List of conversation messages with
role and content keysThe candidate’s CV text for context
The job description for context
Current number of questions asked so far
Maximum number of questions in the interview
A contextual follow-up question that builds on the conversation
- Formats conversation history using
PromptTemplates.format_conversation_history() - Strips prefixes like “Question:”, “Follow-up:”, or “Here’s a question:”
- Raises
AIServiceErrorif the response is empty - Located at:
client/ai_client.py:37
generate_feedback()
Analyzes the complete interview and returns structured performance feedback.Complete conversation history with all questions and answers
The candidate’s CV text
The job description
The position title
- Parses JSON response with retry logic (3 attempts with exponential backoff)
- Validates required keys:
score,strengths,weaknesses,cv_improvements - Validates score is an integer between 1 and 10
- Raises
AIServiceErrorfor missing keys or invalid score - Located at:
client/ai_client.py:59
Error Handling
All methods may raiseAIServiceError in the following cases:
- Empty AI responses
- Invalid JSON in feedback generation
- Missing required feedback fields
- Invalid score values
- Provider failures
Internal Methods
_generate()
Internal helper that callsprovider_manager.generate_text() and wraps exceptions.
_parse_json()
Internal JSON parser with retry logic:- 3 retry attempts with exponential backoff (2-10 seconds)
- Strips markdown code block markers
- Validates JSON structure type (object or array)
- Located at:
client/ai_client.py:86