From ebae80bb7ec04368f35a4017ca47100e921de246 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 6 Sep 2025 19:31:44 -0400 Subject: [PATCH] Ticket Summeries are now in HTML form wit ha breakdown of the Main Issue, Actions Taken and Resolution or Next Steps. It also takes into consideration of the current ticket status and Who replyied for the ticket replys / comments --- post/ai.php | 52 ++++++++++++++++++++++++++++++++++++------------- user/ticket.php | 4 ++-- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/post/ai.php b/post/ai.php index 8343c98e..e14fd74e 100644 --- a/post/ai.php +++ b/post/ai.php @@ -31,7 +31,7 @@ if (isset($_GET['ai_reword'])) { ["role" => "system", "content" => $promptText], ["role" => "user", "content" => $userText], ], - "temperature" => 0.7 + "temperature" => 0.5 ]; // Initialize cURL session to the OpenAI Chat API. @@ -90,19 +90,22 @@ if (isset($_GET['ai_ticket_summary'])) { // Query the database for ticket details $sql = mysqli_query($mysqli, " - SELECT ticket_subject, ticket_details + SELECT ticket_subject, ticket_details, ticket_status_name FROM tickets + LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id WHERE ticket_id = $ticket_id LIMIT 1 "); $row = mysqli_fetch_assoc($sql); $ticket_subject = $row['ticket_subject']; $ticket_details = strip_tags($row['ticket_details']); // strip HTML for cleaner prompt + $ticket_status = $row['ticket_status_name']; // Get ticket replies $sql_replies = mysqli_query($mysqli, " - SELECT ticket_reply, ticket_reply_type + SELECT ticket_reply, ticket_reply_type, user_name FROM ticket_replies + LEFT JOIN users ON ticket_reply_by = user_id WHERE ticket_reply_ticket_id = $ticket_id AND ticket_reply_archived_at IS NULL ORDER BY ticket_reply_id ASC @@ -112,17 +115,40 @@ if (isset($_GET['ai_ticket_summary'])) { while ($reply = mysqli_fetch_assoc($sql_replies)) { $reply_type = $reply['ticket_reply_type']; $reply_text = strip_tags($reply['ticket_reply']); - $all_replies_text .= "\n[$reply_type]: $reply_text"; + $reply_by = $reply['user_name']; + $all_replies_text .= "\nReply Type: $reply_type Reply By: $reply_by: Reply Text: $reply_text"; } $prompt = " - Summarize the following IT ticket and its responses in a concise and clear manner. Your summary should highlight the main issue, actions taken, and resolution steps. Please avoid extra wording or irrelevant details. +Summarize the following IT support ticket and its responses in a concise, clear, and professional manner. +The summary should include: - Ticket Subject: $ticket_subject - Ticket Details: $ticket_details - Replies: $all_replies_text +1. Main Issue: What was the problem reported by the user? +2. Actions Taken: What steps were taken to address the issue? +3. Resolution or Next Steps: Was the issue resolved or is it ongoing? - Please make the summary as short as possible. Only provide the summary with no additional explanation."; +Please ensure: +- If there are multiple issues, summarize each separately. +- Urgency: If the ticket or replies express urgency or escalation, highlight it. +- Attachments: If mentioned in the ticket, note any relevant attachments or files. +- Avoid extra explanations or unnecessary information. + +Ticket Data: +- Current Ticket Status: $ticket_status +- Ticket Subject: $ticket_subject +- Ticket Details: $ticket_details +- Replies: +$all_replies_text + +Formatting instructions: +- Use valid HTML tags only. +- Use

for section headers (Main Issue, Actions Taken, Resolution). +- Use