LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
FIX: Improvements and Bug Fixes in the Custom Synonyms Feature in Prompt Studio (#610)
Tahier Hussain068d9be959fe
diff --git a/frontend/src/components/custom-tools/custom-synonyms-modal/CustomSynonymsModal.css b/frontend/src/components/custom-tools/custom-synonyms-modal/CustomSynonymsModal.cssdeleted file mode 100644index befbfd4a8..000000000--- a/frontend/src/components/custom-tools/custom-synonyms-modal/CustomSynonymsModal.css+++ /dev/null@@ -1 +0,0 @@-/* Styles for CustomSynonymsModal */diff --git a/frontend/src/components/custom-tools/custom-synonyms-modal/CustomSynonymsModal.jsx b/frontend/src/components/custom-tools/custom-synonyms-modal/CustomSynonymsModal.jsxdeleted file mode 100644index 6037d7f60..000000000--- a/frontend/src/components/custom-tools/custom-synonyms-modal/CustomSynonymsModal.jsx+++ /dev/null@@ -1,27 +0,0 @@-import { Modal } from "antd";-import PropTypes from "prop-types";--import { CustomSynonyms } from "../custom-synonyms/CustomSynonyms";--function CustomSynonymsModal({ open, setOpen }) {- return (- <Modal- className="pre-post-amble-modal"- open={open}- onCancel={() => setOpen(false)}- centered- footer={null}- width={800}- maskClosable={false}- >- <CustomSynonyms setOpen={setOpen} />- </Modal>- );-}--CustomSynonymsModal.propTypes = {- open: PropTypes.bool.isRequired,- setOpen: PropTypes.func.isRequired,-};--export { CustomSynonymsModal };diff --git a/frontend/src/components/custom-tools/custom-synonyms/CustomSynonyms.jsx b/frontend/src/components/custom-tools/custom-synonyms/CustomSynonyms.jsxindex e6422218b..09472271d 100644--- a/frontend/src/components/custom-tools/custom-synonyms/CustomSynonyms.jsx+++ b/frontend/src/components/custom-tools/custom-synonyms/CustomSynonyms.jsx@@ -32,12 +32,21 @@ const columns = [},];+const PAGE_SIZE = 10;+const SYNONYMS_LIMIT = 200;++const actionTypes = {+ save: "SAVE",+ delete: "DELETE",+};+function CustomSynonyms() {const [synonyms, setSynonyms] = useState([]);const [rows, setRows] = useState([]);const [isLoading, setIsLoading] = useState(false);+ const [currentPage, setCurrentPage] = useState(1);const { sessionDetails } = useSessionStore();- const { details, updateCustomTool, isPublicSource } = useCustomToolStore();+ const { details, isPublicSource } = useCustomToolStore();const { setAlertDetails } = useAlertStore();const axiosPrivate = useAxiosPrivate();const handleException = useExceptionHandler();@@ -84,7 +93,7 @@ function CustomSynonyms() {synonyms: (<Selectmode="tags"- placeholder="Please select"+ placeholder="Please enter synonyms"value={listOfSynonyms}className="cus-syn-select"variant="borderless"@@ -95,6 +104,7 @@ function CustomSynonyms() {<ConfirmModalhandleConfirm={() => handleDelete(index)}content="The word, along with its corresponding synonyms, will be permanently deleted."+ isDisabled={listOfSynonyms?.length === 0}><Button size="small" disabled={isPublicSource} type="text"><DeleteOutlined className="cus-syn-del" />@@ -114,7 +124,11 @@ function CustomSynonyms() {};const handleAddRow = () => {- const length = synonyms.length || 0;+ const length = synonyms?.length;+ if (length >= SYNONYMS_LIMIT) {+ return;+ }+const data = {key: length,word: "",@@ -123,25 +137,22 @@ function CustomSynonyms() {const updatedSynonyms = [...synonyms];updatedSynonyms.push(data);setSynonyms(updatedSynonyms);- };- const handleDelete = (key) => {- const updatedSynonyms = [...synonyms].filter((item) => item?.key !== key);- setSynonyms(updatedSynonyms);+ const newPage = updatedSynonyms?.length / PAGE_SIZE;+ if (newPage + 1 > currentPage) {+ setCurrentPage((prev) => prev + 1);+ }};- function isEmpty(obj) {- if (typeof obj !== "object" || obj === null) {- return true;- }- return Object.values(obj).every(- (arr) => Array.isArray(arr) && arr.length === 0- );- }+ const handleDelete = (index) => {+ const updatedSynonyms = [...synonyms];+ updatedSynonyms.splice(index, 1);+ updateSynonyms(updatedSynonyms, actionTypes.delete);+ };- const handleSave = () => {+ const updateSynonyms = (listOfSynonyms, actionType) => {const promptGrammar = {};- [...synonyms].forEach((item) => {+ [...listOfSynonyms].forEach((item) => {if (!item?.word ||!item?.synonyms?.length ||@@ -151,53 +162,69 @@ function CustomSynonyms() {}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,- };- setIsLoading(true);- axiosPrivate(requestOptions)- .then((res) => {- const grammar = res?.data?.prompt_grammer;- const updatedDetails = { ...details };- updatedDetails["prompt_grammer"] = grammar;- updateCustomTool({ details: updatedDetails });- setAlertDetails({- type: "success",- content: "Saved synonyms successfully",- });- })- .catch((err) => {- setAlertDetails(handleException(err, "Failed to update"));- })- .finally(() => {- setIsLoading(false);- });+ let successMsg = "";+ let failureMsg = "";+ if (actionType === actionTypes.save) {+ successMsg = "Saved synonyms successfully";+ failureMsg = "Failed to save synonyms";} else {- setAlertDetails({- type: "warning",- content: "Please add synonyms to save",- });+ successMsg = "Deleted synonyms successfully";+ failureMsg = "Failed to delete synonyms";}++ 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(() => {+ if (actionType === actionTypes.delete) {+ setSynonyms(listOfSynonyms);+ }+ setAlertDetails({+ type: "success",+ content: successMsg,+ });+ })+ .catch((err) => {+ setAlertDetails(handleException(err, failureMsg));+ })+ .finally(() => {+ setIsLoading(false);+ });};return (<div className="settings-body-pad-top"><SpaceWrapper>- <div>- <Typography.Text className="add-cus-tool-header">- Custom Synonyms- </Typography.Text>+ <div className="display-flex-space-between">+ <div>+ <Typography.Text className="add-cus-tool-header">+ Custom Synonyms+ </Typography.Text>+ </div>+ <div>+ <CustomButton+ type="primary"+ icon={<PlusOutlined />}+ onClick={handleAddRow}+ disabled={isPublicSource || synonyms?.length >= SYNONYMS_LIMIT}+ >+ Rows+ </CustomButton>+ </div></div><div><Table@@ -205,24 +232,18 @@ function CustomSynonyms() {dataSource={rows}size="small"bordered- pagination={{ position: [] }}+ pagination={{+ pageSize: PAGE_SIZE,+ current: currentPage,+ onChange: (page) => setCurrentPage(page),+ }}/></div>- <div>- <CustomButton- type="primary"- icon={<PlusOutlined />}- onClick={handleAddRow}- disabled={isPublicSource}- >- Rows- </CustomButton>- </div><div className="display-flex-right"><Space><CustomButtontype="primary"- onClick={handleSave}+ onClick={() => updateSynonyms(synonyms, actionTypes.save)}loading={isLoading}disabled={isPublicSource}>diff --git a/frontend/src/components/custom-tools/tool-ide/ToolIde.jsx b/frontend/src/components/custom-tools/tool-ide/ToolIde.jsxindex f0d9110db..a4ec9c89d 100644--- a/frontend/src/components/custom-tools/tool-ide/ToolIde.jsx+++ b/frontend/src/components/custom-tools/tool-ide/ToolIde.jsx@@ -7,7 +7,6 @@ import { useExceptionHandler } from "../../../hooks/useExceptionHandler";import { useAlertStore } from "../../../store/alert-store";import { useCustomToolStore } from "../../../store/custom-tool-store";import { useSessionStore } from "../../../store/session-store";-import { CustomSynonymsModal } from "../custom-synonyms-modal/CustomSynonymsModal";import { DisplayLogs } from "../display-logs/DisplayLogs";import { DocumentManager } from "../document-manager/DocumentManager";import { Header } from "../header/Header";@@ -47,7 +46,6 @@ try {function ToolIde() {const [showLogsModal, setShowLogsModal] = useState(false);const [activeKey, setActiveKey] = useState([]);- const [openCusSynonymsModal, setOpenCusSynonymsModal] = useState(false);const [openSettings, setOpenSettings] = useState(false);const {details,@@ -280,10 +278,6 @@ function ToolIde() {</Modal></div></div>- <CustomSynonymsModal- open={openCusSynonymsModal}- setOpen={setOpenCusSynonymsModal}- /><SettingsModalopen={openSettings}setOpen={setOpenSettings}diff --git a/frontend/src/components/widgets/confirm-modal/ConfirmModal.jsx b/frontend/src/components/widgets/confirm-modal/ConfirmModal.jsxindex aed7c54e8..ae1ca889a 100644--- a/frontend/src/components/widgets/confirm-modal/ConfirmModal.jsx+++ b/frontend/src/components/widgets/confirm-modal/ConfirmModal.jsx@@ -8,10 +8,16 @@ function ConfirmModal({content,okText,cancelText,+ isDisabled,}) {const [modal, contextHolder] = Modal.useModal();const handleConfirmModal = () => {+ if (isDisabled) {+ handleConfirm();+ return;+ }+modal.confirm({title: title || "Are you sure?",content: content || "",@@ -30,6 +36,10 @@ function ConfirmModal({);}+ConfirmModal.defaultProps = {+ isDisabled: false,+};+ConfirmModal.propTypes = {children: PropTypes.any.isRequired,handleConfirm: PropTypes.func.isRequired,@@ -37,6 +47,7 @@ ConfirmModal.propTypes = {content: PropTypes.string,okText: PropTypes.string,cancelText: PropTypes.string,+ isDisabled: PropTypes.bool,};export { ConfirmModal };