Update AI prompting

This commit is contained in:
o-psi 2024-02-21 18:13:10 +00:00
parent b31f1b4c49
commit 06ce12ba47
2 changed files with 11 additions and 3 deletions

View File

@ -14,7 +14,11 @@ document.getElementById('rewordButton').addEventListener('click', function() {
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text: textInput.value, description: ticketDescription.value }),
// Body with the text to reword and the ticket description
body: JSON.stringify({
text: textInput.value,
ticketDescription: ticketDescription.innerText.valueOf(),
}),
})
.then(response => response.json())
.then(data => {

View File

@ -12,14 +12,16 @@ if (isset($_GET['ai_reword'])) {
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE); // Convert JSON into array.
$promptText = "You are an experienced technician at a help desk, training a new technician. The system will tell them to reach out again if they need help, so dont mention that. Help me rewrite the following response for clarity and professionalism, but dont make it too wordy; Be sure to mention the issue in the response so the client feels heard:";
// Prefix the input text with "reword: "
$prefixedText = "You are a technician at a help desk, training another technician. This is a response to the following issue " . $input['description'] . " Help me reword this for clarity and proffesionalism: " . $input['text'];
$userText = $input['text'];
// Preparing the data for the OpenAI Chat API request.
$data = [
"model" => "$config_ai_model", // Specify the model
"messages" => [
["role" => "user", "content" => $prefixedText]
["role" => "system", "content" => $promptText],
["role" => "user", "content" => $userText],
],
"temperature" => 0.7
];
@ -45,6 +47,8 @@ if (isset($_GET['ai_reword'])) {
// Check if the response contains the expected data and return it.
if (isset($responseData['choices'][0]['message']['content'])) {
// Remove any square brackets and their contents from the response.
$responseData['choices'][0]['message']['content'] = preg_replace('/\[.*?\]/', '', $responseData['choices'][0]['message']['content']);
echo json_encode(['rewordedText' => trim($responseData['choices'][0]['message']['content'])]);
} else {
// Handle errors or unexpected response structure.