Skip to content

Commit

Permalink
Fix/prompt studio bugs (#55)
Browse files Browse the repository at this point in the history
* UI Bug fixes

* Fix/prompt-studio UN-714

---------

Co-authored-by: Hari John Kuriakose <[email protected]>
  • Loading branch information
athul-rs and hari-kuriakose authored Mar 4, 2024
1 parent fa650e9 commit 3069bce
Showing 1 changed file with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,44 +130,58 @@ function CustomSynonyms({ setOpen }) {
setSynonyms(updatedSynonyms);
};

function isEmpty(obj) {
if (typeof obj !== "object" || obj === null) {
return true;
}
return Object.values(obj).every(
(arr) => Array.isArray(arr) && arr.length === 0
);
}

const handleSave = () => {
const promptGrammar = {};
[...synonyms].forEach((item) => {
promptGrammar[item?.word] = item?.synonyms || [];
});
if (promptGrammar && !isEmpty(promptGrammar)) {
const body = {
prompt_grammer: promptGrammar,
};
const requestOptions = {
method: "PATCH",
url: `/api/v1/unstract/${sessionDetails?.orgId}/prompt-studio/${details?.tool_id}/`,
headers: {
"X-CSRFToken": sessionDetails?.csrfToken,
"Content-Type": "application/json",
},
data: body,
};

const body = {
prompt_grammer: promptGrammar,
};

const requestOptions = {
method: "PATCH",
url: `/api/v1/unstract/${sessionDetails?.orgId}/prompt-studio/${details?.tool_id}/`,
headers: {
"X-CSRFToken": sessionDetails?.csrfToken,
"Content-Type": "application/json",
},
data: body,
};

setIsLoading(true);
axiosPrivate(requestOptions)
.then((res) => {
const grammar = res?.data?.prompt_grammer;
const updatedDetails = { ...details };
updatedDetails["prompt_grammer"] = grammar;
updateCustomTool(updatedDetails);
setAlertDetails({
type: "success",
content: "Saved synonyms successfully",
setIsLoading(true);
axiosPrivate(requestOptions)
.then((res) => {
const grammar = res?.data?.prompt_grammer;
const updatedDetails = { ...details };
updatedDetails["prompt_grammer"] = grammar;
updateCustomTool(updatedDetails);
setAlertDetails({
type: "success",
content: "Saved synonyms successfully",
});
})
.catch((err) => {
setAlertDetails(handleException(err, "Failed to update"));
})
.finally(() => {
setIsLoading(false);
});
})
.catch((err) => {
setAlertDetails(handleException(err, "Failed to update"));
})
.finally(() => {
setIsLoading(false);
} else {
setAlertDetails({
type: "warning",
content: "Please add synonyms to save",
});
}
};

return (
Expand Down

0 comments on commit 3069bce

Please sign in to comment.