Files
biiproject-kit-v1/app/Http/Controllers/AI/AiAssistantController.php
T

90 lines
2.4 KiB
PHP

<?php
/**
* ============================================================
*
* @project biiproject
*
* @author Andika Debi Putra
*
* @email andikadebiputra@gmail.com
*
* @website https://biiproject.com
*
* @copyright Copyright (c) 2026 Andika Debi Putra
* @license Proprietary - All Rights Reserved
*
* @version 1.0.0
*
* @created 2026-05-01
* ============================================================
*/
namespace App\Http\Controllers\AI;
use App\Http\Controllers\Controller;
use App\Services\AI\AiAssistantService;
use Illuminate\Http\Request;
/**
* @OA\Tag(
* name="AI Intelligence",
* description="API Endpoints for AI-powered system features"
* )
*/
class AiAssistantController extends Controller
{
public function __construct(
protected AiAssistantService $assistantService
) {}
/**
* @OA\Post(
* path="/api/v1/ai/assistant/ask",
* summary="Ask the AI Assistant",
* description="Sends a natural language query to the AI assistant for system guidance.",
* operationId="askAiAssistant",
* tags={"AI Intelligence"},
* security={{"sanctum":{}}},
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(
* required={"question"},
*
* @OA\Property(property="question", type="string", example="How do I change the maintenance mode secret?")
* )
* ),
*
* @OA\Response(
* response=200,
* description="AI Response",
*
* @OA\JsonContent(
*
* @OA\Property(property="status", type="string", example="success"),
* @OA\Property(property="answer", type="string", example="To change the secret, go to Global Settings > Maintenance.")
* )
* ),
*
* @OA\Response(response=401, description="Unauthenticated"),
* @OA\Response(response=422, description="Validation Error")
* )
*/
public function ask(Request $request)
{
$this->authorize('use ai assistant');
$request->validate([
'question' => 'required|string|max:500',
]);
$answer = $this->assistantService->answer($request->question);
return response()->json([
'status' => 'success',
'answer' => $answer,
]);
}
}