Enhancing CV Generation: AI Context Extraction and User-Provided Nuance with PHP
The devlog-ist/landing project focuses on enhancing user experience, and a recent update significantly improves our CV generation feature. This update streamlines how job context is captured and used to create tailored CVs, leveraging AI to extract key details and allowing users to provide additional, nuanced information.
The Challenge with Manual Context
Previously, our CV generation form required explicit inputs for company_name, role_name, and language. While functional, this approach was rigid and prone to user error or omission. It also didn't fully leverage the rich information often available within a complete job description. We needed a more intelligent and flexible way to understand the job context for better-personalized CVs.
Introducing AI-Driven Context Extraction
To address this, we integrated an AI model to automatically derive essential job details directly from the provided job description. Our CvGenerationService now includes an extractJobContext method, which utilizes a dedicated Gemini model. This method processes the raw job description text and intelligently returns structured data, specifically the language, company, and role. This not only reduces manual input but also ensures consistency and accuracy.
class CvGenerationService
{
// ... other methods ...
public function extractJobContext(string $jobDescription): array
{
// Simulate AI model call for extraction
// In a real application, this would involve API calls to a Gemini model
$extractedContext = [
'language' => 'English', // Example: 'English'
'company' => 'TechCorp', // Example: 'TechCorp Innovations'
'role' => 'Senior Developer' // Example: 'Senior Full-Stack Developer'
];
return $extractedContext;
}
// ... generate and buildSystemPrompt methods will use this ...
}
This extractJobContext method is a pivotal addition, transforming raw text into actionable structured data that informs the rest of the CV generation process.
Empowering Users with Additional Context
Beyond automated extraction, we recognized the value of specific, nuanced user input. To this end, an optional additional_context textarea (labeled in Spanish to cater to our diverse user base) was added to the CV form. This field allows users to provide up to 2000 characters of extra information, which is then dynamically injected into the system prompt for the CV generation AI.
The CvGenerationService::generate() and buildSystemPrompt() methods were updated to accept this additionalContext. If present, it creates an "ADDITIONAL USER CONTEXT" block within the AI's system prompt, ensuring the generated CV is even more finely tuned to the user's specific needs and the job's requirements.
class CvGenerationService
{
// ... extractJobContext method ...
public function generate(
string $jobDescription,
?string $additionalContext = null
): string {
$extracted = $this->extractJobContext($jobDescription);
$language = $extracted['language'];
$company = $extracted['company'];
$role = $extracted['role'];
$systemPrompt = $this->buildSystemPrompt(
$language,
$company,
$role,
$additionalContext
);
// ... AI call with systemPrompt to generate CV ...
return "Generated CV HTML based on context";
}
protected function buildSystemPrompt(
string $language,
string $company,
string $role,
?string $additionalContext = null
): string {
$prompt = "Generate a CV in {$language} for a {$role} position at {$company}.";
if ($additionalContext) {
$prompt .= "\n\nADDITIONAL USER CONTEXT:\n{$additionalContext}";
}
return $prompt;
}
}
This code snippet demonstrates how additionalContext is passed through the generation pipeline and conditionally included in the AI's system prompt, providing a flexible way for users to guide the AI.
The Combined Benefit
By combining AI-driven context extraction with direct user input, we've created a more robust and user-friendly CV generation process. Users no longer need to manually replicate details from a job description, and they gain the power to guide the AI with specific instructions. This results in higher quality, more personalized CVs generated with less effort. This approach exemplifies how AI can augment, rather than replace, intelligent user interaction, leading to a superior product experience.