37701-vm/api/ai_helper.php
Flatlogic Bot de914e6037 Catatan
2026-01-22 10:08:05 +00:00

33 lines
1.1 KiB
PHP

<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../ai/LocalAIApi.php';
$data = json_decode(file_get_contents('php://input'), true);
$prompt = $data['prompt'] ?? '';
$action = $data['action'] ?? 'summarize';
if (!$prompt) {
echo json_encode(['success' => false, 'error' => 'Prompt kosong']);
exit;
}
$systemPrompt = "Anda adalah asisten AI untuk aplikasi catatan. Bantu pengguna dengan catatan mereka dalam bahasa Indonesia. Jika disuruh meringkas, berikan ringkasan singkat. Jika disuruh memperbaiki tata bahasa, perbaiki teksnya.";
if ($action === 'organize') {
$systemPrompt .= " Sarankan label atau kategori untuk catatan ini.";
}
$resp = LocalAIApi::createResponse([
'input' => [
['role' => 'system', 'content' => $systemPrompt],
['role' => 'user', 'content' => $prompt],
],
]);
if (!empty($resp['success'])) {
$text = LocalAIApi::extractText($resp);
echo json_encode(['success' => true, 'text' => $text]);
} else {
echo json_encode(['success' => false, 'error' => $resp['error'] ?? 'Gagal menghubungi AI']);
}