Skip to content

Commit

Permalink
Merge pull request #6936 from ProcessMaker/bugfix/FOUR-15004-b
Browse files Browse the repository at this point in the history
Bugfix/FOUR-15004: PMQL in record list doesnt work with pm variables:
  • Loading branch information
ryancooley authored Jul 24, 2024
2 parents 288fbc2 + bb1abf4 commit 8675595
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions resources/js/components/shared/PmqlInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ export default {
promptTokens: 0,
totalTokens: 0,
},
promptSessionId: "",
currentNonce: "",
get,
};
},
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -395,19 +442,22 @@ 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;
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;
Expand Down

0 comments on commit 8675595

Please sign in to comment.