33 lines
1.8 KiB
PHP
33 lines
1.8 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
require_once __DIR__ . '/../ai/LocalAIApi.php';
|
|
|
|
$keyword = $_GET['keyword'] ?? 'new process';
|
|
|
|
$prompt = "Generate a creative and concise name, a short description, and a list of detailed steps for a business process related to '" . htmlspecialchars($keyword) . "'. Each step should have a 'title' and a 'description'. Respond in JSON format with 'name', 'description', and 'steps' keys. Example: {"name": "Employee Onboarding Process", "description": "A systematic process to integrate new hires into the company.", "steps": [{"title": "Send welcome email", "description": "Automatically send a welcome email with company resources."}, {"title": "Setup IT access", "description": "Provision access to internal systems and tools."}]}";
|
|
|
|
$params = [
|
|
'input' => [
|
|
['role' => 'system', 'content' => 'You are a helpful assistant that generates process names and descriptions.'],
|
|
['role' => 'user', 'content' => $prompt],
|
|
],
|
|
'model' => 'gpt-5-mini', // Using the default model from ai/config.php
|
|
];
|
|
|
|
$response = LocalAIApi::createResponse($params);
|
|
|
|
if (!empty($response['success'])) {
|
|
$decoded = LocalAIApi::decodeJsonFromResponse($response);
|
|
if ($decoded && isset($decoded['name']) && isset($decoded['description']) && isset($decoded['steps'])) {
|
|
echo json_encode(['success' => true, 'data' => $decoded]);
|
|
} else {
|
|
// Fallback if AI didn't return valid JSON or missing keys
|
|
$text = LocalAIApi::extractText($response);
|
|
echo json_encode(['success' => false, 'error' => 'AI response not in expected JSON format: ' . substr($text, 0, 200)]);
|
|
}
|
|
} else {
|
|
$error_message = $response['error'] ?? 'Unknown AI error';
|
|
echo json_encode(['success' => false, 'error' => $error_message]);
|
|
}
|
|
?>
|