Back

Data Science

Network and Spend Management

‘No input received. Make sure the request sends JSON.’]);
exit;
}

$promptFile = __DIR__ . ‘/review-prompt.txt’;
if (!file_exists($promptFile)) {
http_response_code(500);
echo json_encode([‘error’ => ‘review-prompt.txt not found. Upload it in the same folder as this file.’]);
exit;
}
$promptTemplate = file_get_contents($promptFile);

$systemPrompt = str_replace(
[‘{{business_name}}’,'{{business_category}}’,'{{business_city}}’,
‘{{seo_keywords}}’,'{{rating}}’,'{{service_used}}’,'{{highlight}}’,
‘{{staff_name}}’,'{{tone}}’,'{{language}}’],
[$BUSINESS_NAME, $BUSINESS_CATEGORY, $BUSINESS_CITY,
$SEO_KEYWORDS, $input[‘rating’] ?? ‘5’, $input[‘service’] ?? ”,
$input[‘highlight’] ?? ”, ”, ‘friendly’, ‘Hinglish’],
$promptTemplate
);

// ✅ CURRENT Groq free-tier model (llama-3.3-70b-versatile was retired Aug 2026 — do not use it)
$MODEL = “openai/gpt-oss-120b”;

$ch = curl_init(‘https://api.groq.com/openai/v1/chat/completions’);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
‘Authorization: Bearer ‘ . $API_KEY,
‘Content-Type: application/json’
],
CURLOPT_POSTFIELDS => json_encode([
‘model’ => $MODEL,
‘messages’ => [[‘role’ => ‘system’, ‘content’ => $systemPrompt]]
])
]);
$rawResponse = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
curl_close($ch);

if ($curlError) {
http_response_code(500);
echo json_encode([‘error’ => ‘Connection error: ‘ . $curlError]);
exit;
}

$response = json_decode($rawResponse, true);

if ($httpCode !== 200) {
http_response_code(500);
echo json_encode([
‘error’ => ‘Groq API error (HTTP ‘ . $httpCode . ‘): ‘ . ($response[‘error’][‘message’] ?? $rawResponse)
]);
exit;
}

$text = $response[‘choices’][0][‘message’][‘content’] ?? ”;

if (trim($text) === ”) {
http_response_code(500);
echo json_encode([‘error’ => ‘Empty response from AI. Raw: ‘ . $rawResponse]);
exit;
}

$drafts = preg_split(‘/\n(?=\d\.\s)/’, trim($text));
$drafts = array_values(array_filter(array_map(function ($d) {
return trim(preg_replace(‘/^\d\.\s*/’, ”, $d));
}, $drafts)));

echo json_encode([‘drafts’ => $drafts]);

Quick Connect

Contact Us

Download brochure