mirror of
https://github.com/itflow-org/itflow
synced 2026-03-21 21:15:38 +00:00
Update AI prompting
This commit is contained in:
@@ -14,7 +14,11 @@ document.getElementById('rewordButton').addEventListener('click', function() {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'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(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
|||||||
@@ -12,14 +12,16 @@ if (isset($_GET['ai_reword'])) {
|
|||||||
$inputJSON = file_get_contents('php://input');
|
$inputJSON = file_get_contents('php://input');
|
||||||
$input = json_decode($inputJSON, TRUE); // Convert JSON into array.
|
$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: "
|
// 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.
|
// Preparing the data for the OpenAI Chat API request.
|
||||||
$data = [
|
$data = [
|
||||||
"model" => "$config_ai_model", // Specify the model
|
"model" => "$config_ai_model", // Specify the model
|
||||||
"messages" => [
|
"messages" => [
|
||||||
["role" => "user", "content" => $prefixedText]
|
["role" => "system", "content" => $promptText],
|
||||||
|
["role" => "user", "content" => $userText],
|
||||||
],
|
],
|
||||||
"temperature" => 0.7
|
"temperature" => 0.7
|
||||||
];
|
];
|
||||||
@@ -45,6 +47,8 @@ if (isset($_GET['ai_reword'])) {
|
|||||||
|
|
||||||
// Check if the response contains the expected data and return it.
|
// Check if the response contains the expected data and return it.
|
||||||
if (isset($responseData['choices'][0]['message']['content'])) {
|
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'])]);
|
echo json_encode(['rewordedText' => trim($responseData['choices'][0]['message']['content'])]);
|
||||||
} else {
|
} else {
|
||||||
// Handle errors or unexpected response structure.
|
// Handle errors or unexpected response structure.
|
||||||
|
|||||||
Reference in New Issue
Block a user