feature: chatbot pimpinan
This commit is contained in:
@@ -88,9 +88,42 @@ class ChatbotController extends Controller
|
||||
|
||||
try {
|
||||
// Panggil service untuk generate text
|
||||
$response = $this->openAIService->mainGenerateText($request->input('prompt'));
|
||||
$classifyResponse = $this->openAIService->classifyMainGenerateText($request->input('prompt'));
|
||||
info($classifyResponse);
|
||||
|
||||
// Pastikan hasil klasifikasi valid sebelum melanjutkan
|
||||
$validCategories = [
|
||||
'reklame', 'business_or_industries', 'customers',
|
||||
'pbg', 'retribusi', 'spatial_plannings',
|
||||
'tourisms', 'umkms'
|
||||
];
|
||||
|
||||
if (!in_array($classifyResponse, $validCategories)) {
|
||||
return response()->json([
|
||||
'error' => ''
|
||||
], 400);
|
||||
}
|
||||
|
||||
$queryResponse = $this->openAIService->createMainQuery($classifyResponse, $request->input('prompt'));
|
||||
info($queryResponse);
|
||||
|
||||
$firstValidation = $this->openAIService->validateSyntaxQuery($queryResponse);
|
||||
$secondValidation = $this->openAIService->validateSyntaxQuery($queryResponse);
|
||||
|
||||
$formattedResultQuery = "[]";
|
||||
|
||||
return response()->json(['response' => $response]);
|
||||
if($firstValidation === "VALID" && $secondValidation === "VALID")
|
||||
{
|
||||
$queryResponse = str_replace(['```sql', '```'], '', $queryResponse);
|
||||
$queryResult = DB::select($queryResponse);
|
||||
info($queryResult);
|
||||
$formattedResultQuery = json_encode($queryResult, JSON_PRETTY_PRINT);
|
||||
info($formattedResultQuery);
|
||||
}
|
||||
$nlpResult = $this->openAIService->generateNLPFromQuery($request->input('prompt'), $formattedResultQuery);
|
||||
$finalGeneratedText =$this->openAIService->generateFinalText($nlpResult);
|
||||
|
||||
return response()->json(['response' => $finalGeneratedText]);
|
||||
} catch (\Exception $e) {
|
||||
// Tangani error dan log exception
|
||||
\Log::error("Error generating text: " . $e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user