Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

Render Components Only If Available (#57)

Tahier Hussain80f439908d01
diff --git a/.gitignore b/.gitignore
index 8a520edfa..2d898d1b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -610,6 +610,9 @@ backend/plugins/authentication/*
# Processor Plugins
backend/plugins/processor/*
+# FE Plugins
+frontend/src/plugins/*
+
# Tool registry
unstract/tool-registry/src/unstract/tool_registry/*.json
unstract/tool-registry/tests/*.yaml
diff --git a/frontend/src/components/custom-tools/document-manager/DocumentManager.jsx b/frontend/src/components/custom-tools/document-manager/DocumentManager.jsx
index fae7e91d1..754589098 100644
--- a/frontend/src/components/custom-tools/document-manager/DocumentManager.jsx
+++ b/frontend/src/components/custom-tools/document-manager/DocumentManager.jsx
@@ -19,42 +19,51 @@ import {
import { DocumentViewer } from "../document-viewer/DocumentViewer";
import { TextViewer } from "../text-viewer/TextViewer";
+const items = [
+ {
+ key: "1",
+ label: "Doc View",
+ },
+ {
+ key: "2",
+ label: "Raw View",
+ },
+];
+
const viewTypes = {
pdf: "PDF",
extract: "EXTRACT",
- summarize: "SUMMARIZE",
};
+let SummarizeView = null;
+try {
+ SummarizeView =
+ require("../../../plugins/summarize-view/SummarizeView").SummarizeView;
+ const tabLabel =
+ require("../../../plugins/summarize-tab/SummarizeTab").tabLabel;
+ if (tabLabel) {
+ items.push({
+ key: 3,
+ label: tabLabel,
+ });
+ }
+} catch {
+ // The component will remain null of it is not available
+}
+
function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
const [openManageDocsModal, setOpenManageDocsModal] = useState(false);
const [page, setPage] = useState(1);
const [activeKey, setActiveKey] = useState("1");
const [fileUrl, setFileUrl] = useState("");
const [extractTxt, setExtractTxt] = useState("");
- const [summaryTxt, setSummaryTxt] = useState("");
const [isDocLoading, setIsDocLoading] = useState(false);
const [isExtractLoading, setIsExtractLoading] = useState(false);
- const [isSummaryLoading, setIsSummaryLoading] = useState(false);
const { selectedDoc, listOfDocs, disableLlmOrDocChange, details } =
useCustomToolStore();
const { sessionDetails } = useSessionStore();
const axiosPrivate = useAxiosPrivate();
- const items = [
- {
- key: "1",
- label: "Doc View",
- },
- {
- key: "2",
- label: "Raw View",
- },
- {
- key: "3",
- label: "Summarize View",
- },
- ];
-
useEffect(() => {
const fileNameTxt = removeFileExtension(selectedDoc);
const files = [
@@ -66,15 +75,10 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
fileName: `extract/${fileNameTxt}.txt`,
viewType: viewTypes.extract,
},
- {
- fileName: `summarize/${fileNameTxt}.txt`,
- viewType: viewTypes.summarize,
- },
];
setFileUrl("");
setExtractTxt("");
- setSummaryTxt("");
files.forEach((item) => {
handleFetchContent(item);
});
@@ -84,7 +88,6 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
if (!selectedDoc) {
setFileUrl("");
setExtractTxt("");
- setSummaryTxt("");
return;
}
@@ -107,10 +110,6 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
if (fileDetails?.viewType === viewTypes?.extract) {
setExtractTxt(data);
}
-
- if (fileDetails?.viewType === viewTypes.summarize) {
- setSummaryTxt(data);
- }
})
.catch((err) => {})
.finally(() => {
@@ -126,10 +125,6 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
if (viewType === viewTypes.extract) {
setIsExtractLoading(value);
}
-
- if (viewType === viewTypes.summarize) {
- setIsSummaryLoading(value);
- }
};
const handleActiveKeyChange = (key) => {
@@ -234,15 +229,8 @@ function DocumentManager({ generateIndex, handleUpdateTool, handleDocChange }) {
<TextViewer text={extractTxt} />
</DocumentViewer>
)}
- {activeKey === "3" && (
- <DocumentViewer
- doc={selectedDoc}
- isLoading={isSummaryLoading}
- isContentAvailable={summaryTxt?.length > 0}
- setOpenManageDocsModal={setOpenManageDocsModal}
- >
- <TextViewer text={summaryTxt} />
- </DocumentViewer>
+ {SummarizeView && activeKey === 3 && (
+ <SummarizeView setOpenManageDocsModal={setOpenManageDocsModal} />
)}
<ManageDocsModal
open={openManageDocsModal}
diff --git a/frontend/src/components/custom-tools/eval-metric-tag/EvalMetricTag.css b/frontend/src/components/custom-tools/eval-metric-tag/EvalMetricTag.css
deleted file mode 100644
index 1f3328f50..000000000
--- a/frontend/src/components/custom-tools/eval-metric-tag/EvalMetricTag.css
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Styles for EvalMetricTag */
-
-.eval-metric-tag {
- border: none;
- margin-top: 1px;
- margin-bottom: 2px;
- margin-right: 5px;
- padding-inline: 0px;
-}
-
-.eval-metric-tag .eval-metric-tag-part {
- margin: 0px;
- border-top: 2px solid;
- border-bottom: 2px solid;
- border-radius: 0px;
- background-color: white;
-}
-
-.eval-metric-tag .eval-metric-tag-begin {
- border-left: 2px solid;
- border-top-left-radius: 4px;
- border-bottom-left-radius: 4px;
-}
-
-.eval-metric-tag .eval-metric-tag-end {
- border-right: 2px solid;
- border-top-right-radius: 4px;
- border-bottom-right-radius: 4px;
-}
-
-.eval-metric-tag .eval-metric-tag-name {
- border-left: 2px solid;
- border-right: 2px solid;
- cursor: default;
-}
-
-.eval-metric-tag .eval-metric-tag-type-quality {
- border-color: #B471DE;
-}
-
-.eval-metric-tag .eval-metric-tag-type-security {
- border-color: #E8A400;
-}
-
-.eval-metric-tag .eval-metric-tag-type-guidance {
- border-color: #0097D8;
-}
-
-.eval-metric-tag .eval-metric-tag-value {
- color: white;
- font-weight: 600;
- cursor: default;
-}
-
-.eval-metric-tag .eval-metric-tag-value-pass {
- background-color: #99C633;
- border-color: #99C633;
-}
-
-.eval-metric-tag .eval-metric-tag-value-fail {
- background-color: #FF718A;
- border-color: #FF718A;
-}
-
-.eval-metric-tag .eval-metric-tag-value-disabled {
- background-color: #B4C2CF;
- border-color: #B4C2CF;
-}
\ No newline at end of file
diff --git a/frontend/src/components/custom-tools/eval-metric-tag/EvalMetricTag.jsx b/frontend/src/components/custom-tools/eval-metric-tag/EvalMetricTag.jsx
deleted file mode 100644
index 9d34f9142..000000000
--- a/frontend/src/components/custom-tools/eval-metric-tag/EvalMetricTag.jsx
+++ /dev/null
@@ -1,68 +0,0 @@
-import { ExperimentOutlined } from "@ant-design/icons";
-import { Tag, Tooltip } from "antd";
-import PropTypes from "prop-types";
-
-import "./EvalMetricTag.css";
-
-/*
- e.g.
- {
- "release": "stable",
- "id": "correctness",
- "type": "quality",
- "name": "Correctness",
- "value": "4.72 / 5",
- "status": "pass|failed|disabled"
- }
- */
-function EvalMetricTag({ metric }) {
- if (!metric?.name) {
- return <></>;
- }
-
- return (
- // overlayStyle is required for adding line breaks in tooltip text
- <Tooltip overlayStyle={{ whiteSpace: "pre-line" }} title={metric?.feedback}>
- <Tag className="eval-metric-tag">
- <Tag
- className={
- "eval-metric-tag-part eval-metric-tag-name eval-metric-tag-begin eval-metric-tag-type-" +
- metric?.type
- }
- >
- {metric?.release === "stable" ? (
- ""
- ) : (
- <>
- <Tooltip
- title={
- metric?.release[0].toUpperCase() +
- metric?.release.slice(1) +
- " release"
- }
- >
- <ExperimentOutlined />
- </Tooltip>
- &nbsp;
- </>
- )}
- {metric?.name}
- </Tag>
- <Tag
- className={
- "eval-metric-tag-part eval-metric-tag-end eval-metric-tag-value eval-metric-tag-value-" +
- (metric.status ? metric.status : "disabled")
- }
- >
- {metric?.status !== "disabled" ? metric?.value : "--"}
- </Tag>
- </Tag>
- </Tooltip>
- );
-}
-
-EvalMetricTag.propTypes = {
- metric: PropTypes.object.isRequired,
-};
-
-export { EvalMetricTag };
diff --git a/frontend/src/components/custom-tools/eval-modal/EvalModal.jsx b/frontend/src/components/custom-tools/eval-modal/EvalModal.jsx
deleted file mode 100644
index 662a4ac04..000000000
--- a/frontend/src/components/custom-tools/eval-modal/EvalModal.jsx
+++ /dev/null
@@ -1,155 +0,0 @@
-import { InfoCircleOutlined } from "@ant-design/icons";
-import {
- Checkbox,
- Form,
- Modal,
- Space,
- Switch,
- Tooltip,
- Typography,
-} from "antd";
-import PropTypes from "prop-types";
-import SpaceWrapper from "../../widgets/space-wrapper/SpaceWrapper";
-
-function EvalModal({ open, setOpen, promptDetails, handleChange }) {
- return (
- <Modal
- open={open}
- onCancel={() => setOpen(false)}
- maskClosable={false}
- footer={null}
- centered
- >
- <SpaceWrapper>
- <Typography.Text className="add-cus-tool-header">
- Evaluation Settings
- </Typography.Text>
- <Form>
- <SpaceWrapper>
- <Space>
- <Switch
- size="small"
- checked={promptDetails?.evaluate}
- onChange={(value) => {
- handleChange(value, promptDetails?.prompt_id, "evaluate");
- }}
- />
- <Typography.Text>Enable evaluation</Typography.Text>
- <Tooltip title="Evaluate the prompt response for production readiness.">
- <InfoCircleOutlined />
- </Tooltip>
- </Space>
- <div style={{ marginBottom: "4px" }} />
- <SpaceWrapper>
- <Typography.Text strong>Quality Metrics</Typography.Text>
- <Space>
- <Space>
- <Checkbox
- disabled={!promptDetails?.evaluate}
- checked={promptDetails?.eval_quality_faithfulness}
- onChange={(e) => {
- handleChange(
- e.target.checked,
- promptDetails?.prompt_id,
- "eval_quality_faithfulness"
- );
- }}
- />
- <Typography.Text>Faithfulness</Typography.Text>
- <Tooltip title="Evaluate if the prompt response is relevant to the retrieved context.">
- <InfoCircleOutlined />
- </Tooltip>
- </Space>
- <Space>
- <Checkbox
- disabled={!promptDetails?.evaluate}
- checked={promptDetails?.eval_quality_relevance}
- onChange={(e) => {
- handleChange(
- e.target.checked,
- promptDetails?.prompt_id,
- "eval_quality_relevance"
- );
- }}
- />
- <Typography.Text>Relevance</Typography.Text>
- <Tooltip title="Evaluate if the prompt is relevant to the retrieved context and generated response.">
- <InfoCircleOutlined />
- </Tooltip>
- </Space>
- </Space>
- </SpaceWrapper>
- <div style={{ marginBottom: "4px" }} />
- <SpaceWrapper>
- <Typography.Text strong>Security Metrics</Typography.Text>
- <Space>
- <Checkbox
- disabled={!promptDetails?.evaluate}
- checked={promptDetails?.eval_security_pii}
- onChange={(e) => {
- handleChange(
- e.target.checked,
- promptDetails?.prompt_id,
- "eval_security_pii"
- );
- }}
- />
- <Typography.Text>PII</Typography.Text>
- <Tooltip title="Evaluate if the prompt response contains Personally Identifiable Information (PII).">
- <InfoCircleOutlined />
- </Tooltip>
- </Space>
- </SpaceWrapper>
- <div style={{ marginBottom: "4px" }} />
- <SpaceWrapper>
- <Typography.Text strong>Guidance Metrics</Typography.Text>
- <Space>
- <Checkbox
- disabled={!promptDetails?.evaluate}
- checked={promptDetails?.eval_guidance_toxicity}
- onChange={(e) => {
- handleChange(
- e.target.checked,
- promptDetails?.prompt_id,
- "eval_guidance_toxicity"
- );
- }}
- />
- <Typography.Text>Toxicity</Typography.Text>
- <Tooltip title="Evaluate if the prompt response contains any toxic phrases.">
- <InfoCircleOutlined />
- </Tooltip>
- </Space>
- <Space>
- <Checkbox
- disabled={!promptDetails?.evaluate}
- checked={promptDetails?.eval_guidance_completeness}
- onChange={(e) => {
- handleChange(
- e.target.checked,
- promptDetails?.prompt_id,
- "eval_guidance_completeness"
- );
- }}
- />
- <Typography.Text>Completeness</Typography.Text>
- <Tooltip title="Evaluate if the response is complete as per requirements in prompt.">
- <InfoCircleOutlined />
- </Tooltip>
- </Space>
- </SpaceWrapper>
- </SpaceWrapper>
- </Form>
- </SpaceWrapper>
- </Modal>
- );
-}
-
-EvalModal.propTypes = {
- open: PropTypes.bool.isRequired,
- setOpen: PropTypes.func.isRequired,
- promptDetails: PropTypes.object.isRequired,
- handleChange: PropTypes.func.isRequired,
-};
-
-export { EvalModal };
diff --git a/frontend/src/components/custom-tools/header/Header.jsx b/frontend/src/components/custom-tools/header/Header.jsx
index 35fd8cc66..7b80b7892 100644
--- a/frontend/src/components/custom-tools/header/Header.jsx
+++ b/frontend/src/components/custom-tools/header/Header.jsx
@@ -22,6 +22,15 @@ import { CustomButton } from "../../widgets/custom-button/CustomButton";
import { PreAndPostAmbleModal } from "../pre-and-post-amble-modal/PreAndPostAmbleModal";
import { SelectLlmProfileModal } from "../select-llm-profile-modal/SelectLlmProfileModal";
+let SummarizeHeader = null;
+
+try {
+ SummarizeHeader =
+ require("../../../plugins/summarize-header/SummarizeHeader").SummarizeHeader;
+} catch {
+ // The component will remain null of it is not available
+}
+
function Header({
setOpenCusSynonymsModal,
setOpenManageLlmModal,
@@ -105,17 +114,12 @@ function Header({
</Button>
</div>
<div className="custom-tools-header-btns">
- <div>
- <Button
- className="doc-manager-btn"
- onClick={() => setOpenSummLlmProfileModal(true)}
- icon={<FileTextOutlined />}
- >
- <Typography.Text ellipsis>
- Summarize: {summarizeLlmBtnText || "Select LLM"}
- </Typography.Text>
- </Button>
- </div>
+ {SummarizeHeader && (
+ <SummarizeHeader
+ setOpen={setOpenSummLlmProfileModal}
+ btnText={summarizeLlmBtnText}
+ />
+ )}
<div>
<Button
onClick={() => setOpenCusSynonymsModal(true)}
diff --git a/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx b/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx
index bd0e4a80c..dc5e2f887 100644
--- a/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx
+++ b/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx
@@ -43,11 +43,31 @@ import { ConfirmModal } from "../../widgets/confirm-modal/ConfirmModal";
import SpaceWrapper from "../../widgets/space-wrapper/SpaceWrapper";
import { SpinnerLoader } from "../../widgets/spinner-loader/SpinnerLoader";
import { EditableText } from "../editable-text/EditableText";
-import { EvalMetricTag } from "../eval-metric-tag/EvalMetricTag";
-import { EvalModal } from "../eval-modal/EvalModal";
import { OutputForDocModal } from "../output-for-doc-modal/OutputForDocModal";
import "./PromptCard.css";
+let EvalBtn = null;
+let EvalMetrics = null;
+let EvalModal = null;
+let sortEvalMetricsByType = (param) => {
+ return [];
+};
+let getEvalMetrics = (param1, param2, param3) => {
+ return [];
+};
+try {
+ EvalBtn = require("../../../plugins/eval-btn/EvalBtn").EvalBtn;
+ EvalMetrics =
+ require("../../../plugins/eval-metrics/EvalMetrics").EvalMetrics;
+ EvalModal = require("../../../plugins/eval-modal/EvalModal").EvalModal;
+ sortEvalMetricsByType =
+ require("../../../plugins/eval-helper/EvalHelper").sortEvalMetricsByType;
+ getEvalMetrics =
+ require("../../../plugins/eval-helper/EvalHelper").getEvalMetrics;
+} catch {
+ // The components will remain null of it is not available
+}
+
function PromptCard({
promptDetails,
handleChange,
@@ -67,7 +87,6 @@ function PromptCard({
const [result, setResult] = useState({
promptOutputId: null,
output: "",
- evalMetrics: [],
});
const [outputIds, setOutputIds] = useState([]);
const [coverage, setCoverage] = useState(0);
@@ -196,24 +215,6 @@ function PromptCard({
setPage(newPage);
};
- const sortEvalMetricsByType = (metrics) => {
- const sieve = {};
- for (const metric of metrics) {
- if (!sieve[metric.type]) {
- sieve[metric.type] = [metric];
- } else {
- sieve[metric.type].push(metric);
- }
- }
-
- let sortedMetrics = [];
- for (const type of Object.keys(sieve)) {
- sortedMetrics = sortedMetrics.concat(sieve[type]);
- }
-
- return sortedMetrics;
- };
-
const handleTypeChange = (value) => {
handleChange(value, promptDetails?.prompt_id, "enforce_type", true).then(
() => {
@@ -276,10 +277,11 @@ function PromptCard({
}
// Handle Eval
- let evalMetrics = [];
- if (promptDetails?.evaluate) {
- evalMetrics = data[`${promptDetails?.prompt_key}__evaluation`] || [];
- }
+ const evalMetrics = getEvalMetrics(
+ promptDetails?.evaluate,
+ promptDetails?.prompt_key,
+ data
+ );
handleUpdateOutput(value, selectedDoc, evalMetrics, method, url);
})
.catch((err) => {
@@ -323,11 +325,11 @@ function PromptCard({
}
// Handle Eval
- let evalMetrics = [];
- if (promptDetails?.evaluate) {
- evalMetrics =
- data[`${promptDetails?.prompt_key}__evaluation`] || [];
- }
+ const evalMetrics = getEvalMetrics(
+ promptDetails?.evaluate,
+ promptDetails?.prompt_key,
+ data
+ );
handleUpdateOutput(outputValue, item, evalMetrics, method, url);
})
.catch((err) => {
@@ -429,7 +431,6 @@ function PromptCard({
setResult({
promptOutputId: null,
output: "",
- evalMetrics: [],
});
return;
}
@@ -441,7 +442,6 @@ function PromptCard({
setResult({
promptOutputId: null,
output: "",
- evalMetrics: [],
});
return;
}
@@ -726,21 +726,13 @@ function PromptCard({
>
<div className="prompt-card-llm-profiles">
<Space direction="horizontal">
- <div>
- <Button
- size="small"
- onClick={() => setOpenEval(true)}
- disabled={disableLlmOrDocChange.includes(
- promptDetails?.prompt_id
- )}
- >
- <Space>
- <Typography.Text className="font-size-12">
- Eval: {promptDetails?.evaluate ? "On" : "Off"}
- </Typography.Text>
- </Space>
- </Button>
- </div>
+ {EvalBtn && (
+ <EvalBtn
+ btnText={promptDetails?.evaluate ? "On" : "Off"}
+ promptId={promptDetails.prompt_id}
+ setOpenEval={setOpenEval}
+ />
+ )}
<Button
size="small"
type="link"
@@ -816,13 +808,7 @@ function PromptCard({
</Button>
</div>
</div>
- {result?.evalMetrics?.length > 0 && (
- <div>
- {result?.evalMetrics.map((evalMetric) => (
- <EvalMetricTag key={evalMetric.id} metric={evalMetric} />
- ))}
- </div>
- )}
+ {EvalMetrics && <EvalMetrics result={result} />}
</Space>
</>
{(isRunLoading ||
@@ -841,12 +827,14 @@ function PromptCard({
</>
)}
</Card>
- <EvalModal
- open={openEval}
- setOpen={setOpenEval}
- promptDetails={promptDetails}
- handleChange={handleChange}
- />
+ {EvalModal && (
+ <EvalModal
+ open={openEval}
+ setOpen={setOpenEval}
+ promptDetails={promptDetails}
+ handleChange={handleChange}
+ />
+ )}
<OutputForDocModal
open={openOutputForDoc}
setOpen={setOpenOutputForDoc}