add validation topic on send prompt if not relevan
This commit is contained in:
@@ -27,6 +27,11 @@ class OpenAIService
|
||||
return "Template prompt tidak ditemukan.";
|
||||
}
|
||||
|
||||
$validationResponse = $this->validatePromptTopic($prompt);
|
||||
if ($validationResponse !== 'VALID') {
|
||||
return "Prompt yang Anda masukkan tidak relevan dengan data PUPR/SIMBG/DPUTR atau pekerjaan sejenis.";
|
||||
}
|
||||
|
||||
// Ambil template berdasarkan kategori
|
||||
$promptTemplate = $jsonData[$mainContent]['prompt'];
|
||||
|
||||
@@ -273,4 +278,26 @@ class OpenAIService
|
||||
|
||||
// return trim($response['choices'][0]['message']['content'] ?? 'No response');
|
||||
// }
|
||||
|
||||
public function validatePromptTopic($prompt)
|
||||
{
|
||||
$messages = [
|
||||
[
|
||||
'role' => 'system',
|
||||
'content' => "You are a classification expert. Determine if the user's request is related to the Indonesian Ministry of Public Works and Public Housing (PUPR), DPUTR, SIMBG, or construction-related tasks managed by these institutions.
|
||||
|
||||
Only respond with:
|
||||
- VALID → if it's relevant to those topics
|
||||
- INVALID → if not related at all"
|
||||
],
|
||||
['role' => 'user', 'content' => $prompt],
|
||||
];
|
||||
|
||||
$response = $this->client->chat()->create([
|
||||
'model' => 'gpt-4o-mini',
|
||||
'messages' => $messages,
|
||||
]);
|
||||
|
||||
return trim($response['choices'][0]['message']['content'] ?? 'INVALID');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user