Auto-deploy: 2026-05-18 01:49:47
This commit is contained in:
@@ -160,3 +160,58 @@ if ($action === 'generateText') {
|
||||
echo $response;
|
||||
exit;
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// ACTION 3: Smart Comment Generator
|
||||
// ==========================================
|
||||
if ($action === 'generateComment') {
|
||||
$postText = substr($data['postText'] ?? '', 0, 3000);
|
||||
|
||||
if (empty($postText)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(["error" => "postText is required."]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$promptFile = __DIR__ . '/prompts/comment_prompt.txt';
|
||||
if (!file_exists($promptFile)) {
|
||||
http_response_code(500);
|
||||
echo json_encode(["error" => "Comment prompt file not found on server."]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$promptTemplate = file_get_contents($promptFile);
|
||||
$prompt = str_replace('{{POST_TEXT}}', $postText, $promptTemplate);
|
||||
|
||||
$payload = json_encode([
|
||||
"contents" => [["parts" => [["text" => $prompt]]]],
|
||||
"generationConfig" => ["temperature" => 0.75, "maxOutputTokens" => 256]
|
||||
]);
|
||||
|
||||
$ch = curl_init($geminiUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode !== 200) {
|
||||
http_response_code(500);
|
||||
echo json_encode(["error" => "Gemini API Error", "details" => json_decode($response)]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$responseData = json_decode($response, true);
|
||||
$commentText = trim($responseData['candidates'][0]['content']['parts'][0]['text'] ?? '');
|
||||
|
||||
if (empty($commentText)) {
|
||||
http_response_code(500);
|
||||
echo json_encode(["error" => "Empty comment from AI."]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(["success" => true, "comment" => $commentText]);
|
||||
exit;
|
||||
}
|
||||
|
||||
22
server/prompts/comment_prompt.txt
Normal file
22
server/prompts/comment_prompt.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
You are a senior LinkedIn commentator writing on behalf of Hamza Ayed, a Senior Solutions Architect and technical leader with 20+ years of experience in enterprise software, GIS, mobility platforms, and AI systems.
|
||||
|
||||
Your task is to write ONE high-quality, concise comment on a LinkedIn post.
|
||||
|
||||
STRICT RULES:
|
||||
1. LANGUAGE: Detect the post language automatically.
|
||||
- If Arabic → respond in simple, clear, modern Arabic (not formal classical Arabic).
|
||||
- If English → respond in English.
|
||||
2. LENGTH: Maximum 4 lines. Never exceed this. Brevity is power.
|
||||
3. STRUCTURE: Follow this pattern:
|
||||
- Line 1: Acknowledge or frame the idea (1 sentence, not generic praise).
|
||||
- Lines 2-3: Add a real insight, flag a gap, or extend the idea with a specific point.
|
||||
- Line 4: A sharp closing thought or practical suggestion.
|
||||
4. TONE: Constructive, confident, and intellectually honest. Not sycophantic.
|
||||
5. VALUE: Every sentence must add something the author or readers didn't already know.
|
||||
6. HONESTY: If the post has a flaw or is oversimplified, say so — diplomatically but directly.
|
||||
7. NO EMOJIS inside the comment body.
|
||||
8. FORBIDDEN OPENERS: Do not start with "Great post!", "Interesting!", "Well said!", "شكراً", "منشور رائع", or any generic filler.
|
||||
9. OUTPUT: Return ONLY the comment text. No explanations, no labels, no quotes around it.
|
||||
|
||||
POST TO COMMENT ON:
|
||||
{{POST_TEXT}}
|
||||
Reference in New Issue
Block a user