From dd6d4047e01f5b0d624160a68ec15ecdb8182951 Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Wed, 6 May 2026 13:57:02 +0700 Subject: [PATCH] Update Detect Log By AI --- BACKEND/app/models/prompt_ai.ts | 6 -- BACKEND/app/services/line_connection.ts | 28 +++++--- BACKEND/app/ultils/helper.ts | 21 +++--- BACKEND/providers/socket_io_provider.ts | 28 ++++---- .../src/components/Modal/ModalTerminal.tsx | 64 +++++++++---------- 5 files changed, 74 insertions(+), 73 deletions(-) diff --git a/BACKEND/app/models/prompt_ai.ts b/BACKEND/app/models/prompt_ai.ts index 72891f3..a15ac4a 100644 --- a/BACKEND/app/models/prompt_ai.ts +++ b/BACKEND/app/models/prompt_ai.ts @@ -11,15 +11,9 @@ export default class PromptAi extends BaseModel { @column() declare content: string - @column() - declare description: string | null - @column() declare type: string - @column() - declare is_active: boolean - @column.dateTime({ autoCreate: true }) declare createdAt: DateTime diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index 0ca9fe4..25fa4c1 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -606,7 +606,7 @@ export default class LineConnection { lineNumber: this.config.lineNumber, inventory: this.config.inventory, latestScenario: { - detectAI: detectLog, + detectAI: { issue: detectLog, summary: '', status: [] }, }, data, }) @@ -629,7 +629,10 @@ export default class LineConnection { // } if (this.config.latestScenario) - this.config.latestScenario = { ...this.config.latestScenario, detectAI: detectLog } + this.config.latestScenario = { + ...this.config.latestScenario, + detectAI: { issue: detectLog, summary: '', status: [] }, + } // if (result.sn) { // this.updateNote(result.sn, result) // } @@ -896,7 +899,11 @@ export default class LineConnection { messages: [ { role: 'user', - content: promptRecord + "\n Here's the log:\n" + log, + content: `${promptRecord.content} + + Return ONLY a valid JSON array of strings. + Here is the log: + ${log}`, }, ], } @@ -1283,7 +1290,7 @@ Ports Missing/Down: ${missing.length}\n\n` await this.sleep(3000) this.writeCommand(' show interfaces status\r\n') this.writeCommand(' \r\n') - await this.sleep(4000) + await this.sleep(6000) const statusOutput = this.outputPhysicalTest this.outputPhysicalTest = '' const lines = statusOutput.split('\n') @@ -1332,7 +1339,7 @@ Ports Missing/Down: ${missing.length}\n\n` ${reason}` : '' await sendMessageToMail( - `[ATC] - [${this.config.stationName} - Line: ${this.config.lineNumber}] - Physical Ports Test`, + `[ATC] - [${this.config.stationName} - Line: ${this.config.lineNumber}] - [${this.config.inventory?.pid}] - [${this.config.inventory?.sn}] - Physical Ports Test`, formReport + reasonSkipPhysical ) } @@ -1708,7 +1715,11 @@ Ports Missing/Down: ${missing.length}\n\n` messages: [ { role: 'user', - content: promptRecord + "\n Here's the log:\n" + log, + content: `${promptRecord.content} + + Return ONLY a valid JSON array of strings. + Here is the log: + ${log}`, }, ], } @@ -1844,8 +1855,7 @@ Ports Missing/Down: ${missing.length}\n\n` ?.join(', ') : '' }
- Summary: ${summary}
- Issues: ${issue?.length ? `
- ` + issue.join(`
- `) : 'No issues detected.'}

+ Detect from AI: ${issue?.length ? `
- ` + issue.join(`
`) : 'No issues detected.'}

Total Ports: ${portPhysical?.length}
@@ -1875,7 +1885,7 @@ Ports Missing/Down: ${missing.length}\n\n` this.updateNote(config?.inventory?.sn, this.dataDPELP as DataDPELP) await sendMessageToMail( - `[ATC] - [${config.stationName} - Line: ${config.lineNumber}] - Summary of Testing Results`, + `[ATC] - [${config.stationName} - Line: ${config.lineNumber}] - [${this.config.inventory?.pid}] - [${this.config.inventory?.sn}] - Summary of Testing Results`, body ) this.socketIO.emit('summary_tested', { diff --git a/BACKEND/app/ultils/helper.ts b/BACKEND/app/ultils/helper.ts index d04e4a0..69ec51c 100644 --- a/BACKEND/app/ultils/helper.ts +++ b/BACKEND/app/ultils/helper.ts @@ -11,13 +11,13 @@ import ConfigRam from '#models/config_ram' import Keyword from '#models/keywords' const mailTo = 'andrew.ng@apactech.io' -const mailCC = [ - 'ips@ipsupply.com.au', - 'kay@ipsupply.com.au', - 'joseph@apactech.io', - 'kiet.phan@apactech.io', -] -// const mailCC = '' +// const mailCC = [ +// 'ips@ipsupply.com.au', +// 'kay@ipsupply.com.au', +// 'joseph@apactech.io', +// 'kiet.phan@apactech.io', +// ] +const mailCC = '' type DetectAI = { status: string[] @@ -225,11 +225,8 @@ export function mapToLineFormat(input: InputData) { // const mode = dataPlatform && !dataPlatform.output?.includes('Incomplete') ? 'DPELP' : 'DPEL' // Issues - const issues = Array.isArray(input.latestScenario?.detectAI?.issue) - ? input.latestScenario.detectAI.issue - : input.latestScenario?.detectAI?.issue - ? [input.latestScenario.detectAI.issue] - : [] + const issues = Array.isArray(input.latestScenario?.detectAI) ? input.latestScenario?.detectAI : [] + // Issues const summary = input.latestScenario?.detectAI?.summary || '' diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts index 11ebbd5..8a8db14 100644 --- a/BACKEND/providers/socket_io_provider.ts +++ b/BACKEND/providers/socket_io_provider.ts @@ -668,10 +668,10 @@ export class WebSocketIo { const linkWiki = process.env.LINK_WIKI || 'https://logs.danielvu.com/api/wiki/page/insert?title=Dev_test' try { - await axios.post(linkWiki, { - data: tableHTML, - titleAuto: `[${scenarioName || 'DPELP'}] - ${stationName} - ` + dataFormat, - }) + // await axios.post(linkWiki, { + // data: tableHTML, + // titleAuto: `[${scenarioName || 'DPELP'}] - ${stationName} - ` + dataFormat, + // }) } catch (error) { console.error('Error sending wiki message:', error) } @@ -684,16 +684,16 @@ export class WebSocketIo { console.error('Error sending mail:', error) } try { - const contentZulip = - `\n\n---\n**[${scenarioName || 'DPELP'}] - ${stationName} - ${dataFormat}**\n\n` + - zulipMess - await sendMessageToZulip( - 'stream', - streamZulip || 'ATC_Report', - topicZulip, - contentZulip - ) - await sendMessageToZulip('stream', 'ATC_Report', station.name, contentZulip) + // const contentZulip = + // `\n\n---\n**[${scenarioName || 'DPELP'}] - ${stationName} - ${dataFormat}**\n\n` + + // zulipMess + // await sendMessageToZulip( + // 'stream', + // streamZulip || 'ATC_Report', + // topicZulip, + // contentZulip + // ) + // await sendMessageToZulip('stream', 'ATC_Report', station.name, contentZulip) } catch (error) { console.error('Error sending zulip message:', error) } diff --git a/FRONTEND/src/components/Modal/ModalTerminal.tsx b/FRONTEND/src/components/Modal/ModalTerminal.tsx index c8ae84c..0b78e91 100644 --- a/FRONTEND/src/components/Modal/ModalTerminal.tsx +++ b/FRONTEND/src/components/Modal/ModalTerminal.tsx @@ -177,7 +177,7 @@ const ModalTerminal = ({ const data = line?.latestScenario?.detectAI?.issue && Array.isArray(line?.latestScenario?.detectAI?.issue) - ? "- " + line?.latestScenario?.detectAI?.issue?.join("\n- ") + ? line?.latestScenario?.detectAI?.issue?.join("\n") : ""; setValueIssue(data); } else { @@ -221,8 +221,8 @@ const ModalTerminal = ({ data?.history && data?.id ? JSON.parse(data?.history) : latest?.length > 0 - ? [latest[0], latest[latest?.length - 1]] - : []; + ? [latest[0], latest[latest?.length - 1]] + : []; return (
{list.reverse().map((item: THistoryTicket, index: number) => ( @@ -241,10 +241,10 @@ const ModalTerminal = ({ index === 0 ? "#30d100" : item?.status === "closed" - ? "red" - : item?.status === "issue" - ? "#fab005" - : "inherit", + ? "red" + : item?.status === "issue" + ? "#fab005" + : "inherit", }} > @@ -259,10 +259,10 @@ const ModalTerminal = ({ index === 0 ? "#30d100" : item?.status === "closed" - ? "red" - : item?.status === "issue" - ? "#fab005" - : "dimmed" + ? "red" + : item?.status === "issue" + ? "#fab005" + : "dimmed" } fw={400} > @@ -351,8 +351,8 @@ const ModalTerminal = ({ description: dataTicket.description.trim() ? dataTicket.description.trim() : status === "closed" - ? "Closed" - : "", + ? "Closed" + : "", model: dataTicket.model.trim(), sn: dataTicket.sn.trim(), station_id: Number(stationItem?.id), @@ -365,7 +365,7 @@ const ModalTerminal = ({ try { const res = await axios.post( `${apiUrl + "api/ticket/update" + "/" + dataTicket.id}`, - payload + payload, ); if (res.status) { // if (res?.data?.status !== "closed") @@ -389,7 +389,7 @@ const ModalTerminal = ({ socket?.emit("update_ticket", { lineId: Number(line?.id), data: line?.tickets?.map((el) => - el.id === dataTicket.id ? res.data.data : el + el.id === dataTicket.id ? res.data.data : el, ), stationId: Number(stationItem?.id), }); @@ -470,7 +470,7 @@ const ModalTerminal = ({ const findSwitchPort = (portName: string): SwitchPortsProps | null => { if (listPorts?.length > 0) { const port = listPorts.find( - (el) => normalizePortName(el.name) === normalizePortName(portName) + (el) => normalizePortName(el.name) === normalizePortName(portName), ); if (port) return port; } @@ -503,7 +503,7 @@ const ModalTerminal = ({ const showVersion = dataTextfsm?.find( (d) => d.command?.trim()?.includes("show ver") || - d.command?.trim()?.includes("sh ver") + d.command?.trim()?.includes("sh ver"), ); return showVersion?.textfsm && showVersion?.textfsm?.[0] ? showVersion?.textfsm?.[0] @@ -514,7 +514,7 @@ const ModalTerminal = ({ const showLicense = dataTextfsm?.find( (d) => d.command?.trim()?.includes("show lic") || - d.command?.trim()?.includes("sh lic") + d.command?.trim()?.includes("sh lic"), ); return showLicense?.textfsm && Array.isArray(showLicense?.textfsm) ? showLicense?.textfsm @@ -525,15 +525,15 @@ const ModalTerminal = ({ const showEnv = dataTextfsm?.find( (d) => d.command?.trim()?.includes("show env") || - d.command?.trim()?.includes("sh env") + d.command?.trim()?.includes("sh env"), ); return showEnv?.dataAI && Array.isArray(showEnv?.dataAI) && showEnv?.dataAI?.length > 0 ? showEnv?.dataAI : showEnv?.textfsm && Array.isArray(showEnv?.textfsm) - ? showEnv?.textfsm - : null; + ? showEnv?.textfsm + : null; }; return ( @@ -648,7 +648,7 @@ const ModalTerminal = ({ if (!line) return; if (step === 0 && !isDisable) { const dpelp = scenarios?.find( - (el) => el.title.toUpperCase() === "DPELP" + (el) => el.title.toUpperCase() === "DPELP", ); socket?.emit( "run_scenario", @@ -662,7 +662,7 @@ const ModalTerminal = ({ timeout: 360000, body: JSON.stringify(bodyDPELP), }, - }) + }), ); socket?.emit("run_all_dpelp", { lineIds: [line?.id], @@ -895,7 +895,7 @@ const ModalTerminal = ({ e.stopPropagation(); if (!line?.inventory?.pid) return; navigator.clipboard.writeText( - line.inventory?.pid || "" + line.inventory?.pid || "", ); }} > @@ -999,8 +999,8 @@ const ModalTerminal = ({ ? findDataShowLicense() ?.filter((el: TextTSMLicense) => el.LICENSE_TYPE?.toLowerCase()?.includes( - "permanent" - ) + "permanent", + ), ) ?.map((v: TextTSMLicense) => v.FEATURE) ?.join(", ") @@ -1020,7 +1020,7 @@ const ModalTerminal = ({ - {v} - ) + ), ) : ""} @@ -1034,7 +1034,7 @@ const ModalTerminal = ({ {findDataShowVersion() && findDataShowVersion()?.MEMORY ? convertFromKilobytesString( - findDataShowVersion()?.MEMORY + findDataShowVersion()?.MEMORY, ) : ""} @@ -1047,7 +1047,7 @@ const ModalTerminal = ({ {findDataShowVersion() && findDataShowVersion()?.USB_FLASH ? convertFromKilobytesString( - findDataShowVersion()?.USB_FLASH + findDataShowVersion()?.USB_FLASH, ) : ""} @@ -1077,8 +1077,8 @@ const ModalTerminal = ({ ? findDataShowLicense() ?.filter((el: TextTSMLicense) => el.LICENSE_TYPE?.toLowerCase()?.includes( - "permanent" - ) + "permanent", + ), ) ?.map((v: TextTSMLicense) => v.FEATURE) : [], @@ -1488,7 +1488,7 @@ const ModalTerminal = ({ }, 10000); }} dataDPELP={scenarios?.find( - (el) => el.title.toUpperCase() === "DPELP" + (el) => el.title.toUpperCase() === "DPELP", )} />