LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
Prompt studio fixes (#497)
jagadeeswaran-zipstack64861dce79c7
diff --git a/backend/prompt_studio/prompt_profile_manager/serializers.py b/backend/prompt_studio/prompt_profile_manager/serializers.pyindex fc83aaab4..4d4753561 100644--- a/backend/prompt_studio/prompt_profile_manager/serializers.py+++ b/backend/prompt_studio/prompt_profile_manager/serializers.py@@ -2,7 +2,6 @@ import loggingfrom adapter_processor.adapter_processor import AdapterProcessorfrom prompt_studio.prompt_profile_manager.constants import ProfileManagerKeys-from prompt_studio.prompt_studio_core.exceptions import MaxProfilesReachedErrorfrom backend.serializers import AuditSerializer@@ -39,15 +38,3 @@ class ProfileManagerSerializer(AuditSerializer):AdapterProcessor.get_adapter_instance_by_id(x2text))return rep-- def validate(self, data):- prompt_studio_tool = data.get(ProfileManagerKeys.PROMPT_STUDIO_TOOL)-- profile_count = ProfileManager.objects.filter(- prompt_studio_tool=prompt_studio_tool- ).count()-- if profile_count >= ProfileManagerKeys.MAX_PROFILE_COUNT:- raise MaxProfilesReachedError()-- return datadiff --git a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.pyindex 5750e789c..c5513b7e6 100644--- a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py+++ b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py@@ -498,7 +498,11 @@ class PromptStudioHelper:doc_path, tool_id, org_id, user_id, document_id, run_id):prompts = PromptStudioHelper.fetch_prompt_from_tool(tool_id)- prompts = [prompt for prompt in prompts if prompt.prompt_type != TSPKeys.NOTES]+ prompts = [+ prompt+ for prompt in prompts+ if prompt.prompt_type != TSPKeys.NOTES and prompt.active+ ]if not prompts:logger.error(f"[{tool_id or 'NA'}] No prompts found for id: {id}")raise NoPromptsFound()diff --git a/backend/prompt_studio/prompt_studio_core/views.py b/backend/prompt_studio/prompt_studio_core/views.pyindex 8db0a3ef5..18915ac24 100644--- a/backend/prompt_studio/prompt_studio_core/views.py+++ b/backend/prompt_studio/prompt_studio_core/views.py@@ -10,7 +10,10 @@ from file_management.exceptions import FileNotFoundfrom file_management.file_management_helper import FileManagerHelperfrom permissions.permission import IsOwner, IsOwnerOrSharedUserfrom prompt_studio.processor_loader import ProcessorConfig, load_plugins-from prompt_studio.prompt_profile_manager.constants import ProfileManagerErrors+from prompt_studio.prompt_profile_manager.constants import (+ ProfileManagerErrors,+ ProfileManagerKeys,+)from prompt_studio.prompt_profile_manager.models import ProfileManagerfrom prompt_studio.prompt_profile_manager.serializers import ProfileManagerSerializerfrom prompt_studio.prompt_studio.constants import ToolStudioPromptErrors@@ -26,6 +29,7 @@ from prompt_studio.prompt_studio_core.document_indexing_service import ()from prompt_studio.prompt_studio_core.exceptions import (IndexingAPIError,+ MaxProfilesReachedError,ToolDeleteError,)from prompt_studio.prompt_studio_core.prompt_studio_helper import PromptStudioHelper@@ -345,6 +349,16 @@ class PromptStudioCoreView(viewsets.ModelViewSet):serializer = ProfileManagerSerializer(data=request.data, context=context)serializer.is_valid(raise_exception=True)+ # Check for the maximum number of profiles constraint+ prompt_studio_tool = serializer.validated_data[+ ProfileManagerKeys.PROMPT_STUDIO_TOOL+ ]+ profile_count = ProfileManager.objects.filter(+ prompt_studio_tool=prompt_studio_tool+ ).count()++ if profile_count >= ProfileManagerKeys.MAX_PROFILE_COUNT:+ raise MaxProfilesReachedError()try:self.perform_create(serializer)except IntegrityError:diff --git a/backend/prompt_studio/prompt_studio_output_manager/constants.py b/backend/prompt_studio/prompt_studio_output_manager/constants.pyindex a9c046aae..1cee0b394 100644--- a/backend/prompt_studio/prompt_studio_output_manager/constants.py+++ b/backend/prompt_studio/prompt_studio_output_manager/constants.py@@ -5,3 +5,8 @@ class PromptStudioOutputManagerKeys:DOCUMENT_MANAGER = "document_manager"IS_SINGLE_PASS_EXTRACT = "is_single_pass_extract"NOTES = "NOTES"+++class PromptOutputManagerErrorMessage:+ TOOL_VALIDATION = "tool_id parameter is required"+ TOOL_NOT_FOUND = "Tool not found"diff --git a/backend/prompt_studio/prompt_studio_output_manager/urls.py b/backend/prompt_studio/prompt_studio_output_manager/urls.pyindex 45af0ccee..61ec8540f 100644--- a/backend/prompt_studio/prompt_studio_output_manager/urls.py+++ b/backend/prompt_studio/prompt_studio_output_manager/urls.py@@ -4,9 +4,17 @@ from rest_framework.urlpatterns import format_suffix_patternsfrom .views import PromptStudioOutputViewprompt_doc_list = PromptStudioOutputView.as_view({"get": "list"})+get_output_for_tool_default = PromptStudioOutputView.as_view(+ {"get": "get_output_for_tool_default"}+)urlpatterns = format_suffix_patterns([path("prompt-output/", prompt_doc_list, name="prompt-doc-list"),+ path(+ "prompt-output/prompt-default-profile/",+ get_output_for_tool_default,+ name="prompt-default-profile-outputs",+ ),])diff --git a/backend/prompt_studio/prompt_studio_output_manager/views.py b/backend/prompt_studio/prompt_studio_output_manager/views.pyindex 3be3c5888..e1ef58296 100644--- a/backend/prompt_studio/prompt_studio_output_manager/views.py+++ b/backend/prompt_studio/prompt_studio_output_manager/views.py@@ -1,14 +1,20 @@import logging-from typing import Optional+from typing import Any, Optional+from django.core.exceptions import ObjectDoesNotExistfrom django.db.models import QuerySet+from django.http import HttpRequest+from prompt_studio.prompt_studio.models import ToolStudioPromptfrom prompt_studio.prompt_studio_output_manager.constants import (+ PromptOutputManagerErrorMessage,PromptStudioOutputManagerKeys,)from prompt_studio.prompt_studio_output_manager.serializers import (PromptStudioOutputSerializer,)-from rest_framework import viewsets+from rest_framework import status, viewsets+from rest_framework.exceptions import APIException+from rest_framework.response import Responsefrom rest_framework.versioning import URLPathVersioningfrom utils.common_utils import CommonUtilsfrom utils.filtering import FilterHelper@@ -49,3 +55,51 @@ class PromptStudioOutputView(viewsets.ModelViewSet):queryset = PromptStudioOutputManager.objects.filter(**filter_args)return queryset++ def get_output_for_tool_default(self, request: HttpRequest) -> Response:+ # Get the tool_id from request parameters+ # Get the tool_id from request parameters+ tool_id = request.GET.get("tool_id")+ document_manager_id = request.GET.get("document_manager")+ tool_validation_message = PromptOutputManagerErrorMessage.TOOL_VALIDATION+ tool_not_found = PromptOutputManagerErrorMessage.TOOL_NOT_FOUND+ if not tool_id:+ raise APIException(detail=tool_validation_message, code=400)++ try:+ # Fetch ToolStudioPrompt records based on tool_id+ tool_studio_prompts = ToolStudioPrompt.objects.filter(tool_id=tool_id)+ except ObjectDoesNotExist:+ raise APIException(detail=tool_not_found, code=400)++ # Initialize the result dictionary+ result: dict[str, Any] = {}++ # Iterate over ToolStudioPrompt records+ for tool_prompt in tool_studio_prompts:+ prompt_id = str(tool_prompt.prompt_id)+ profile_manager_id = str(tool_prompt.profile_manager.profile_id)++ # If profile_manager is not set, skip this record+ if not profile_manager_id:+ result[tool_prompt.prompt_key] = ""+ continue++ try:+ queryset = PromptStudioOutputManager.objects.filter(+ prompt_id=prompt_id,+ profile_manager=profile_manager_id,+ is_single_pass_extract=False,+ document_manager_id=document_manager_id,+ )++ if not queryset.exists():+ result[tool_prompt.prompt_key] = ""+ continue++ for output in queryset:+ result[tool_prompt.prompt_key] = output.output+ except ObjectDoesNotExist:+ result[tool_prompt.prompt_key] = ""++ return Response(result, status=status.HTTP_200_OK)diff --git a/backend/prompt_studio/prompt_studio_registry/prompt_studio_registry_helper.py b/backend/prompt_studio/prompt_studio_registry/prompt_studio_registry_helper.pyindex ef8ecd4aa..33c253205 100644--- a/backend/prompt_studio/prompt_studio_registry/prompt_studio_registry_helper.py+++ b/backend/prompt_studio/prompt_studio_registry/prompt_studio_registry_helper.py@@ -268,6 +268,8 @@ class PromptStudioRegistryHelper:tool_settings[JsonSchemaKey.ENABLE_HIGHLIGHT] = tool.enable_highlightfor prompt in prompts:+ if prompt.prompt_type == JsonSchemaKey.NOTES or not prompt.active:+ continueif not prompt.prompt:invalidated_prompts.append(prompt.prompt_key)@@ -283,8 +285,6 @@ class PromptStudioRegistryHelper:invalidated_outputs.append(prompt.prompt_key)continue- if prompt.prompt_type == JsonSchemaKey.NOTES:- continueif not prompt.profile_manager:prompt.profile_manager = default_llm_profilediff --git a/frontend/src/components/custom-tools/combined-output/CombinedOutput.jsx b/frontend/src/components/custom-tools/combined-output/CombinedOutput.jsxindex 57d4d08a8..7985dad14 100644--- a/frontend/src/components/custom-tools/combined-output/CombinedOutput.jsx+++ b/frontend/src/components/custom-tools/combined-output/CombinedOutput.jsx@@ -76,6 +76,16 @@ function CombinedOutput({ docId, setFilledFields }) {.then((res) => {const data = res?.data || [];const prompts = details?.prompts;+ if (activeKey === "0") {+ const output = {};+ for (const key in data) {+ if (Object.hasOwn(data, key)) {+ output[key] = displayPromptResult(data[key], false);+ }+ }+ setCombinedOutput(output);+ return;+ }const output = {};prompts.forEach((item) => {if (item?.prompt_type === promptType.notes) {@@ -83,10 +93,7 @@ function CombinedOutput({ docId, setFilledFields }) {}output[item?.prompt_key] = "";- let profileManager = selectedProfile || item?.profile_manager;- if (singlePassExtractMode) {- profileManager = defaultLlmProfile;- }+ const profileManager = selectedProfile || item?.profile_manager;const outputDetails = data.find((outputValue) =>outputValue?.prompt_id === item?.prompt_id &&@@ -147,6 +154,9 @@ function CombinedOutput({ docId, setFilledFields }) {}&document_manager=${docId}&is_single_pass_extract=${singlePassExtractMode}&profile_manager=${selectedProfile || defaultLlmProfile}`;+ if (activeKey === "0") {+ url = `/api/v1/unstract/${sessionDetails?.orgId}/prompt-studio/prompt-output/prompt-default-profile/?tool_id=${details?.tool_id}&document_manager=${docId}`;+ }}const requestOptions = {method: "GET",@@ -198,6 +208,7 @@ function CombinedOutput({ docId, setFilledFields }) {llmProfiles={llmProfiles}activeKey={activeKey}adapterData={adapterData}+ isSinglePass={singlePassExtractMode}/>);}diff --git a/frontend/src/components/custom-tools/combined-output/JsonView.jsx b/frontend/src/components/custom-tools/combined-output/JsonView.jsxindex d78bbe77c..9b48af632 100644--- a/frontend/src/components/custom-tools/combined-output/JsonView.jsx+++ b/frontend/src/components/custom-tools/combined-output/JsonView.jsx@@ -12,6 +12,7 @@ function JsonView({activeKey,selectedProfile,llmProfiles,+ isSinglePass,}) {useEffect(() => {Prism.highlightAll();@@ -21,8 +22,10 @@ function JsonView({<div className="combined-op-layout"><div className="combined-op-header"><Tabs activeKey={activeKey} onChange={handleTabChange} moreIcon={<></>}>- <TabPane tab={<span>Default</span>} key={"0"}></TabPane>- {[...(adapterData || [])].map((adapter, index) => (+ {!isSinglePass && (+ <TabPane tab={<span>Default</span>} key={"0"}></TabPane>+ )}+ {adapterData.map((adapter, index) => (<TabPanetab={<span>{adapter.llm_model}</span>}key={(index + 1)?.toString()}@@ -54,6 +57,7 @@ JsonView.propTypes = {selectedProfile: PropTypes.string,llmProfiles: PropTypes.array,activeKey: PropTypes.string,+ isSinglePass: PropTypes.bool,};export { JsonView };diff --git a/frontend/src/components/custom-tools/manage-llm-profiles/ManageLlmProfiles.jsx b/frontend/src/components/custom-tools/manage-llm-profiles/ManageLlmProfiles.jsxindex 643abe2e3..31e9f5304 100644--- a/frontend/src/components/custom-tools/manage-llm-profiles/ManageLlmProfiles.jsx+++ b/frontend/src/components/custom-tools/manage-llm-profiles/ManageLlmProfiles.jsx@@ -1,5 +1,5 @@import { DeleteOutlined, EditOutlined } from "@ant-design/icons";-import { Button, Radio, Table, Typography } from "antd";+import { Button, Radio, Table, Tooltip, Typography } from "antd";import { useEffect, useState } from "react";import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate";@@ -75,6 +75,8 @@ function ManageLlmProfiles() {const { setAlertDetails } = useAlertStore();const handleException = useExceptionHandler();const { setPostHogCustomEvent } = usePostHogEvents();+ const MAX_PROFILE_COUNT = 4;+ const isMaxProfile = llmProfiles.length >= MAX_PROFILE_COUNT;const handleDefaultLlm = (profileId) => {try {@@ -239,13 +241,21 @@ function ManageLlmProfiles() {</div></SpaceWrapper><div className="display-flex-right">- <CustomButton- type="primary"- disabled={isPublicSource}- onClick={handleAddNewLlmProfileBtnClick}+ <Tooltip+ title={+ isMaxProfile+ ? `Max profile count(${MAX_PROFILE_COUNT})`+ : "Add New LLM Profile"+ }>- Add New LLM Profile- </CustomButton>+ <CustomButton+ type="primary"+ onClick={handleAddNewLlmProfileBtnClick}+ disabled={isMaxProfile}+ >+ Add New LLM Profile+ </CustomButton>+ </Tooltip></div></div>);diff --git a/frontend/src/components/custom-tools/output-for-doc-modal/OutputForDocModal.jsx b/frontend/src/components/custom-tools/output-for-doc-modal/OutputForDocModal.jsxindex 0d053e4f3..446a9ffb3 100644--- a/frontend/src/components/custom-tools/output-for-doc-modal/OutputForDocModal.jsx+++ b/frontend/src/components/custom-tools/output-for-doc-modal/OutputForDocModal.jsx@@ -31,25 +31,6 @@ try {} catch {// The component will remain null of it is not available}-const columns = [- {- title: "Document",- dataIndex: "document",- key: "document",- },- {- title: "Token Count",- dataIndex: "token_count",- key: "token_count",- width: 200,- },- {- title: "Value",- dataIndex: "value",- key: "value",- width: 600,- },-];const outputStatus = {yet_to_process: "YET_TO_PROCESS",@@ -75,13 +56,14 @@ function OutputForDocModal({details,listOfDocs,selectedDoc,- defaultLlmProfile,disableLlmOrDocChange,singlePassExtractMode,isSinglePassExtractLoading,isPublicSource,llmProfiles,+ defaultLlmProfile,} = useCustomToolStore();+ const [selectedProfile, setSelectedProfile] = useState(defaultLlmProfile);const { sessionDetails } = useSessionStore();const axiosPrivate = useAxiosPrivate();const navigate = useNavigate();@@ -89,13 +71,12 @@ function OutputForDocModal({const { setAlertDetails } = useAlertStore();const handleException = useExceptionHandler();const { tokenUsage } = useTokenUsageStore();- const [selectedProfile, setSelectedProfile] = useState(defaultLlmProfile);useEffect(() => {if (!open) {return;}- handleGetOutputForDocs();+ handleGetOutputForDocs(selectedProfile || profileManagerId);getAdapterInfo();}, [open, singlePassExtractMode, isSinglePassExtractLoading]);@@ -139,34 +120,6 @@ function OutputForDocModal({// If data is provided, use it; otherwise, create a copy of the previous stateconst updatedPromptOutput = data || [...prev];- // Get the keys of docOutputs- const keys = Object.keys(docOutputs);-- keys.forEach((key) => {- // Find the index of the prompt output corresponding to the document manager key- const index = updatedPromptOutput.findIndex(- (promptOutput) => promptOutput?.document_manager === key- );-- let promptOutputInstance = {};- // If the prompt output for the current key doesn't exist, skip it- if (index > -1) {- promptOutputInstance = updatedPromptOutput[index];- promptOutputInstance["output"] = docOutputs[key]?.output;- }-- // Update output and isLoading properties based on docOutputs- promptOutputInstance["document_manager"] = key;- promptOutputInstance["isLoading"] = docOutputs[key]?.isLoading || false;-- // Update the prompt output instance in the array- if (index > -1) {- updatedPromptOutput[index] = promptOutputInstance;- } else {- updatedPromptOutput.push(promptOutputInstance);- }- });-return updatedPromptOutput;});};@@ -181,10 +134,6 @@ function OutputForDocModal({};const handleGetOutputForDocs = (profile = profileManagerId) => {- if (singlePassExtractMode) {- profile = defaultLlmProfile;- }-if (!profile) {setRows([]);return;@@ -243,10 +192,14 @@ function OutputForDocModal({const result = {key: item?.document_id,document: item?.document_name,- token_count: (+ token_count: !singlePassExtractMode && (<TokenUsagetokenUsageId={- promptId + "__" + item?.document_id + "__" + profileManagerId+ promptId ++ "__" ++ item?.document_id ++ "__" ++ (selectedProfile || profileManagerId)}/>),@@ -286,6 +239,26 @@ function OutputForDocModal({}};+ const columns = [+ {+ title: "Document",+ dataIndex: "document",+ key: "document",+ },+ !singlePassExtractMode && {+ title: "Token Count",+ dataIndex: "token_count",+ key: "token_count",+ width: 200,+ },+ {+ title: "Value",+ dataIndex: "value",+ key: "value",+ width: 600,+ },+ ].filter(Boolean);+return (<ModalclassName="pre-post-amble-modal"@@ -313,7 +286,10 @@ function OutputForDocModal({></TabPane>))}</Tabs>{" "}- <ProfileInfoBar profileId={selectedProfile} profiles={llmProfiles} />+ <ProfileInfoBar+ profileId={selectedProfile || profileManagerId}+ profiles={llmProfiles}+ /></div><div className="display-flex-right"><Buttondiff --git a/frontend/src/components/custom-tools/prompt-card/Header.jsx b/frontend/src/components/custom-tools/prompt-card/Header.jsxindex 119576992..41826f5df 100644--- a/frontend/src/components/custom-tools/prompt-card/Header.jsx+++ b/frontend/src/components/custom-tools/prompt-card/Header.jsx@@ -180,12 +180,13 @@ function Header({</Tooltip></>)}- <Checkbox- checked={isDisablePrompt}- className="prompt-card-action-button"- onChange={handleDisablePrompt}- disabled={isPublicSource}- />+ <Tooltip title={isDisablePrompt ? "Disable Prompt" : "Enable Prompt"}>+ <Checkbox+ checked={isDisablePrompt}+ className="prompt-card-action-button"+ onChange={handleDisablePrompt}+ />+ </Tooltip><Divider type="vertical" className="header-delete-divider" /><ConfirmModalhandleConfirm={() => handleDelete(promptDetails?.prompt_id)}diff --git a/frontend/src/components/custom-tools/prompt-card/PromptCard.css b/frontend/src/components/custom-tools/prompt-card/PromptCard.cssindex d190564f2..6331b11dd 100644--- a/frontend/src/components/custom-tools/prompt-card/PromptCard.css+++ b/frontend/src/components/custom-tools/prompt-card/PromptCard.css@@ -203,3 +203,8 @@border-color: #00000026 !important;color: #000 !important;}++.prompt-not-ran {+ color: #575859;+ font-size: 13px;+}diff --git a/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx b/frontend/src/components/custom-tools/prompt-card/PromptCard.jsxindex 889a03d9f..c945faec7 100644--- a/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx+++ b/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx@@ -61,7 +61,7 @@ function PromptCard({const [isCoverageLoading, setIsCoverageLoading] = useState(false);const [openOutputForDoc, setOpenOutputForDoc] = useState(false);const [progressMsg, setProgressMsg] = useState({});- const [docOutputs, setDocOutputs] = useState({});+ const [docOutputs, setDocOutputs] = useState([]);const [timers, setTimers] = useState({});const {getDropdownItems,@@ -138,6 +138,7 @@ function PromptCard({listOfDocs,singlePassExtractMode,isSinglePassExtractLoading,+ defaultLlmProfile,]);useEffect(() => {@@ -201,17 +202,28 @@ function PromptCard({handleChange(value, promptDetails?.prompt_id, "enforce_type", true);};- const handleDocOutputs = (docId, isLoading, output) => {+ const handleDocOutputs = (docId, promptId, profileId, isLoading, output) => {if (isSimplePromptStudio) {return;}setDocOutputs((prev) => {- const updatedDocOutputs = { ...prev };+ const updatedDocOutputs = [...prev];+ const key = `${promptId}__${docId}__${profileId}`;// Update the entry for the provided docId with isLoading and output- updatedDocOutputs[docId] = {+ const newData = {+ key,isLoading,output,};+ const index = updatedDocOutputs.findIndex((item) => item.key === key);++ if (index !== -1) {+ // Update the existing object+ updatedDocOutputs[index] = newData;+ } else {+ // Append the new object+ updatedDocOutputs.push(newData);+ }return updatedDocOutputs;});};@@ -279,16 +291,9 @@ function PromptCard({if (validateInputs(profileManagerId, selectedLlmProfiles, coverAllDoc)) {return;}-- handleIsRunLoading(- selectedDoc?.document_id,- profileManagerId || selectedLlmProfileId,- true- );setIsCoverageLoading(true);setCoverage(0);setCoverageTotal(0);- setDocOutputs({});resetInfoMsgs();const docId = selectedDoc?.document_id;@@ -312,7 +317,6 @@ function PromptCard({return;}- handleDocOutputs(docId, true, null);if (runAllLLM) {let selectedProfiles = llmProfiles;if (!coverAllDoc && selectedLlmProfiles?.length > 0) {@@ -321,6 +325,13 @@ function PromptCard({);}for (const profile of selectedProfiles) {+ handleDocOutputs(+ docId,+ promptDetails?.prompt_id,+ profile?.profile_id,+ true,+ null+ );setIsCoverageLoading(true);handleIsRunLoading(selectedDoc?.document_id, profile?.profile_id, true);@@ -331,22 +342,29 @@ function PromptCard({if (value || value === 0) {setCoverage((prev) => prev + 1);}- handleDocOutputs(docId, false, value);+ handleDocOutputs(+ docId,+ promptDetails?.prompt_id,+ profile?.profile_id,+ false,+ value+ );handleGetOutput(profile?.profile_id);updateDocCoverage(- coverage,promptDetails?.prompt_id,profile?.profile_id,docId);}).catch((err) => {- handleIsRunLoading(- selectedDoc?.document_id,+ handleIsRunLoading(docId, profile?.profile_id, false);+ handleDocOutputs(+ docId,+ promptDetails?.prompt_id,profile?.profile_id,- false+ false,+ null);- handleDocOutputs(docId, false, null);setAlertDetails(handleException(err, `Failed to generate output for ${docId}`));@@ -357,19 +375,32 @@ function PromptCard({runCoverageForAllDoc(coverAllDoc, profile.profile_id);}} else {+ handleIsRunLoading(selectedDoc?.document_id, profileManagerId, true);+ handleDocOutputs(+ docId,+ promptDetails?.prompt_id,+ profileManagerId,+ true,+ null+ );handleRunApiRequest(docId, profileManagerId).then((res) => {const data = res?.data?.output;const value = data[promptDetails?.prompt_key];if (value || value === 0) {updateDocCoverage(- coverage,promptDetails?.prompt_id,profileManagerId,docId);}- handleDocOutputs(docId, false, value);+ handleDocOutputs(+ docId,+ promptDetails?.prompt_id,+ profileManagerId,+ false,+ value+ );handleGetOutput();setCoverageTotal(1);})@@ -379,7 +410,13 @@ function PromptCard({selectedLlmProfileId,false);- handleDocOutputs(docId, false, null);+ handleDocOutputs(+ docId,+ promptDetails?.prompt_id,+ profileManagerId,+ false,+ null+ );setAlertDetails(handleException(err, `Failed to generate output for ${docId}`));@@ -433,23 +470,40 @@ function PromptCard({}setIsCoverageLoading(true);- handleDocOutputs(docId, true, null);+ handleDocOutputs(+ docId,+ promptDetails?.prompt_id,+ profileManagerId,+ true,+ null+ );handleRunApiRequest(docId, profileManagerId).then((res) => {const data = res?.data?.output;const outputValue = data[promptDetails?.prompt_key];if (outputValue || outputValue === 0) {updateDocCoverage(- coverage,promptDetails?.prompt_id,profileManagerId,docId);}- handleDocOutputs(docId, false, outputValue);+ handleDocOutputs(+ docId,+ promptDetails?.prompt_id,+ profileManagerId,+ false,+ outputValue+ );}).catch((err) => {- handleDocOutputs(docId, false, null);+ handleDocOutputs(+ docId,+ promptDetails?.prompt_id,+ profileManagerId,+ false,+ null+ );setAlertDetails(handleException(err, `Failed to generate output for ${docId}`));@@ -465,23 +519,33 @@ function PromptCard({});};- const updateDocCoverage = (coverage, promptId, profileManagerId, docId) => {- const key = `${promptId}_${profileManagerId}`;- const counts = { ...coverage };- // If the key exists in the counts object, increment the count- if (counts[key]) {- if (!counts[key]?.docs_covered?.includes(docId)) {- counts[key]?.docs_covered?.push(docId);+ const updateDocCoverage = (promptId, profileManagerId, docId) => {+ setCoverage((prevCoverage) => {+ const keySuffix = `${promptId}_${profileManagerId}`;+ const key = singlePassExtractMode ? `singlepass_${keySuffix}` : keySuffix;++ // Create a shallow copy of the previous coverage state+ const updatedCoverage = { ...prevCoverage };++ // If the key exists in the updated coverage object, update the docs_covered array+ if (updatedCoverage[key]) {+ if (!updatedCoverage[key].docs_covered.includes(docId)) {+ updatedCoverage[key].docs_covered = [+ ...updatedCoverage[key].docs_covered,+ docId,+ ];+ }+ } else {+ // Otherwise, add the key to the updated coverage object with the new entry+ updatedCoverage[key] = {+ prompt_id: promptId,+ profile_manager: profileManagerId,+ docs_covered: [docId],+ };}- } else {- // Otherwise, add the key to the counts object with an initial count of 1- counts[key] = {- prompt_id: promptId,- profile_manager: profileManagerId,- docs_covered: [docId],- };- }- setCoverage(counts);++ return updatedCoverage;+ });};const handleRunApiRequest = async (docId, profileManagerId) => {@@ -678,7 +742,7 @@ function PromptCard({const data = res?.data || [];if (singlePassExtractMode) {- const tokenUsageId = `single_pass__${selectedDoc?.document_id}`;+ const tokenUsageId = `single_pass__${defaultLlmProfile}__${selectedDoc?.document_id}`;const usage = data?.find((item) => item?.run_id !== undefined);if (!tokenUsage[tokenUsageId] && usage) {@@ -703,7 +767,6 @@ function PromptCard({const handleGetCoverageData = (data) => {data?.forEach((item) => {updateDocCoverage(- coverage,item?.prompt_id,item?.profile_manager,item?.document_manager@@ -771,7 +834,7 @@ function PromptCard({setOpen={setOpenOutputForDoc}promptId={promptDetails?.prompt_id}promptKey={promptDetails?.prompt_key}- profileManagerId={promptDetails?.profile_manager}+ profileManagerId={selectedLlmProfileId}docOutputs={docOutputs}/></>diff --git a/frontend/src/components/custom-tools/prompt-card/PromptCardItems.jsx b/frontend/src/components/custom-tools/prompt-card/PromptCardItems.jsxindex dbd2a472c..5fd5ff0ec 100644--- a/frontend/src/components/custom-tools/prompt-card/PromptCardItems.jsx+++ b/frontend/src/components/custom-tools/prompt-card/PromptCardItems.jsx@@ -4,6 +4,7 @@ import {CheckCircleOutlined,DatabaseOutlined,ExclamationCircleFilled,+ InfoCircleFilled,InfoCircleOutlined,PlayCircleFilled,PlayCircleOutlined,@@ -78,12 +79,14 @@ function PromptCardItems({isSimplePromptStudio,isPublicSource,adapters,+ defaultLlmProfile,} = useCustomToolStore();const [isEditingPrompt, setIsEditingPrompt] = useState(false);const [isEditingTitle, setIsEditingTitle] = useState(false);const [expandCard, setExpandCard] = useState(true);const [llmProfileDetails, setLlmProfileDetails] = useState([]);const [openIndexProfile, setOpenIndexProfile] = useState(null);+ const [coverageCount, setCoverageCount] = useState(0);const [enabledProfiles, setEnabledProfiles] = useState(llmProfiles.map((profile) => profile.profile_id));@@ -220,6 +223,14 @@ function PromptCardItems({}return <></>;};+ const getCoverageData = () => {+ const profileId = singlePassExtractMode+ ? defaultLlmProfile+ : selectedLlmProfileId;+ const keySuffix = `${promptDetails?.prompt_id}_${profileId}`;+ const key = singlePassExtractMode ? `singlepass_${keySuffix}` : keySuffix;+ return coverage[key]?.docs_covered?.length || 0;+ };useEffect(() => {setExpandCard(true);@@ -229,7 +240,8 @@ function PromptCardItems({if (singlePassExtractMode) {setExpandedProfiles([]);}- }, [singlePassExtractMode]);+ setCoverageCount(getCoverageData());+ }, [singlePassExtractMode, coverage]);useEffect(() => {getAdapterInfo(adapters);@@ -311,11 +323,8 @@ function PromptCardItems({<SearchOutlined className="font-size-12" />)}<Typography.Link className="font-size-12">- Coverage:{" "}- {coverage[- `${promptDetails?.prompt_id}_${selectedLlmProfileId}`- ]?.docs_covered?.length || 0}{" "}- of {listOfDocs?.length || 0} docs+ Coverage: {coverageCount} of{" "}+ {listOfDocs?.length || 0} docs</Typography.Link></Space></Button>@@ -490,11 +499,24 @@ function PromptCardItems({: "collapsed-output"}>- {displayPromptResult(- result.find(- (r) => r?.profileManager === profileId- )?.output,- true+ {!result.find(+ (r) => r?.profileManager === profileId+ )?.output ? (+ <Typography.Text className="prompt-not-ran">+ <span>+ <InfoCircleFilled+ style={{ color: "#F0AD4E" }}+ />+ </span>{" "}+ Yet to run+ </Typography.Text>+ ) : (+ displayPromptResult(+ result.find(+ (r) => r?.profileManager === profileId+ )?.output,+ true+ ))}</div></Typography.Paragraph>