false, 'message' => 'API key is not configured.']); exit; } $request_body = file_get_contents('php://input'); $form_data = json_decode($request_body, true); // --- PROMPT ENGINEERING --- // $prompt = "Please generate a professional resume based on the following details. Format the output as clean, semantic HTML suitable for direct display on a web page. The design should be modern and professional. Use a single-column layout. Do not include any CSS or ```html markers, only the raw HTML body content."; $prompt .= "\n\n---\n\n"; // Personal Details $prompt .= "**Personal Details:**\n"; $prompt .= "- Name: " . ($form_data['fullName'] ?? 'N/A') . "\n"; $prompt .= "- Email: " . ($form_data['email'] ?? 'N/A') . "\n"; $prompt .= "- Phone: " . ($form_data['phone'] ?? 'N/A') . "\n"; $prompt .= "- LinkedIn: " . ($form_data['linkedin'] ?? 'N/A') . "\n\n"; // Summary if (!empty($form_data['summary'])) { $prompt .= "**Professional Summary:**\n" . $form_data['summary'] . "\n\n"; } // Work Experience if (!empty($form_data['experience'])) { $prompt .= "**Work Experience:**\n"; foreach ($form_data['experience'] as $exp) { $prompt .= "- Job Title: " . ($exp['title'] ?? 'N/A') . " at " . ($exp['company'] ?? 'N/A') . "\n"; $prompt .= " (From: " . ($exp['startDate'] ?? 'N/A') . " to " . ($exp['endDate'] ?? 'Present') . ")\n"; if (!empty($exp['responsibilities'])) { $prompt .= " Responsibilities: " . $exp['responsibilities'] . "\n"; } } $prompt .= "\n"; } // Education if (!empty($form_data['education'])) { $prompt .= "**Education:**\n"; foreach ($form_data['education'] as $edu) { $prompt .= "- Degree: " . ($edu['degree'] ?? 'N/A') . " from " . ($edu['school'] ?? 'N/A') . "\n"; $prompt .= " (From: " . ($edu['startDate'] ?? 'N/A') . " to " . ($edu['endDate'] ?? 'Present') . ")\n"; } $prompt .= "\n"; } // Skills if (!empty($form_data['skills'])) { $prompt .= "**Skills:**\n" . $form_data['skills'] . "\n"; } // Call the Gemini API $api_response = callGeminiApi($prompt, $apiKey); header('Content-Type: application/json'); if (isset($api_response['error'])) { http_response_code(500); echo json_encode(['success' => false, 'message' => $api_response['error'], 'details' => $api_response['response'] ?? null]); exit; } $_SESSION['generated_resume'] = $api_response['html']; $_SESSION['resume_prompt'] = $prompt; // Storing for debug or retry purposes echo json_encode(['success' => true, 'message' => 'Resume generated successfully.']); } else { header('HTTP/1.1 405 Method Not Allowed'); echo json_encode(['success' => false, 'message' => 'Invalid request method.']); }