From bb1abf4fad16c5a8e11efaef5694fe6ac1ab769c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Busso?= <90727999+agustinbusso@users.noreply.github.com> Date: Tue, 11 Jun 2024 13:44:38 -0300 Subject: [PATCH] Fix NL to PMQL to use microservice for select list PMQL --- resources/js/components/shared/PmqlInput.vue | 58 ++++++++++++++++++-- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/resources/js/components/shared/PmqlInput.vue b/resources/js/components/shared/PmqlInput.vue index 0c0c9c01e8..bda1093c1d 100755 --- a/resources/js/components/shared/PmqlInput.vue +++ b/resources/js/components/shared/PmqlInput.vue @@ -243,6 +243,8 @@ export default { promptTokens: 0, totalTokens: 0, }, + promptSessionId: "", + currentNonce: "", get, }; }, @@ -312,6 +314,9 @@ export default { this.filtersPmql = this.filtersValue; this.inputAriaLabel = this.ariaLabel; + this.promptSessionId = localStorage.promptSessionId; + this.currentNonce = localStorage.currentNonce; + this.$root.$on("bv::collapse::state", (collapseId, isJustShown) => { this.query = this.value; this.pmql = this.value; @@ -325,6 +330,48 @@ export default { }, methods: { + getNonce() { + const max = 999999999999999; + const nonce = Math.floor(Math.random() * max); + this.currentNonce = nonce; + localStorage.currentNonce = this.currentNonce; + }, + getPromptSession() { + const url = "/package-ai/getPromptSessionHistory"; + + let params = { + server: window.location.host, + }; + + if (this.promptSessionId?.startsWith("ss")) { + this.promptSessionId = ""; + } + + if ( + this.promptSessionId + && this.promptSessionId !== null + && this.promptSessionId !== "" + ) { + params = { + promptSessionId: this.promptSessionId, + }; + } + + ProcessMaker.apiClient + .post(url, params) + .then((response) => { + this.promptSessionId = response.data.promptSessionId; + localStorage.promptSessionId = response.data.promptSessionId; + this.runNLQToPMQL(); + }) + .catch((error) => { + if (error.response.status === 404) { + localStorage.promptSessionId = ""; + this.promptSessionId = ""; + this.getPromptSession(); + } + }); + }, onFiltersPmqlChange(value) { this.filtersPmql = value[0]; this.selectedFilters = value[1]; @@ -381,7 +428,7 @@ export default { this.$emit("submit", this.query); this.$emit("input", this.query); } else if (this.aiEnabledLocal) { - this.runNLQToPMQL(); + this.getPromptSession(); } else if (!this.query.isPMQL() && !this.aiEnabledLocal) { const fullTextSearch = `(fulltext LIKE "%${this.query}%")`; this.pmql = fullTextSearch; @@ -395,10 +442,13 @@ export default { this.runSearch(); }, runNLQToPMQL() { + this.getNonce(); const params = { - question: this.query, + search: this.query, type: this.searchType, classifySearch: false, + promptSessionId: this.promptSessionId, + nonce: this.currentNonce, }; this.aiLoading = true; @@ -406,8 +456,8 @@ export default { ProcessMaker.apiClient .post("/package-ai/naturalLanguageToPmql", params) .then((response) => { - this.pmql = response.data.result; - this.usage = response.data.usage; + this.pmql = response.data.result[0].result.pmql; + this.usage = response.data.result[0].usage; this.$emit("submit", this.pmql); this.$emit("input", this.pmql); this.aiLoading = false;