LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
UN-2239 [FEAT] Enable LLM adapter selection for summarization (#1474)
jagadeeswaran-zipstack5f3b3389177a
diff --git a/backend/prompt_studio/prompt_studio_core_v2/prompt_studio_helper.py b/backend/prompt_studio/prompt_studio_core_v2/prompt_studio_helper.pyindex 11f12532a..d627d7cbb 100644--- a/backend/prompt_studio/prompt_studio_core_v2/prompt_studio_helper.py+++ b/backend/prompt_studio/prompt_studio_core_v2/prompt_studio_helper.py@@ -50,6 +50,9 @@ from prompt_studio.prompt_studio_core_v2.exceptions import (PermissionError,ToolNotValid,)+from prompt_studio.prompt_studio_core_v2.migration_utils import (+ SummarizeMigrationUtils,+)from prompt_studio.prompt_studio_core_v2.models import CustomToolfrom prompt_studio.prompt_studio_core_v2.prompt_ide_base_tool import PromptIdeBaseToolfrom prompt_studio.prompt_studio_core_v2.prompt_variable_service import (@@ -321,7 +324,6 @@ class PromptStudioHelper:org_id: str,user_id: str,document_id: str,- is_summary: bool = False,run_id: str = None,) -> Any:"""Method to index a document.@@ -331,8 +333,6 @@ class PromptStudioHelper:file_name (str): File to parseorg_id (str): The ID of the organization to which the user belongs.user_id (str): The ID of the user who uploaded the document.- is_summary (bool, optional): Whether the document is a summary- or not. Defaults to False.Raises:ToolNotValid@@ -347,14 +347,35 @@ class PromptStudioHelper:)file_path = str(Path(file_path) / file_name)- if is_summary:- profile_manager: ProfileManager = ProfileManager.objects.get(- prompt_studio_tool=tool, is_summarize_llm=True- )- profile_manager.chunk_size == 0- default_profile = profile_manager- else:- default_profile = ProfileManager.get_default_llm_profile(tool)+ # Always get the default profile first+ default_profile = ProfileManager.get_default_llm_profile(tool)+ summary_profile = (+ default_profile # Constructed profile for summarization, not stored in DB+ )++ # Check if summarization is enabled and handle accordingly+ if tool.summarize_context:+ # Trigger migration if needed+ SummarizeMigrationUtils.migrate_tool_to_adapter_based(tool)++ if tool.summarize_llm_adapter:+ # For summarization with adapter-based approach, we'll use the default profile+ # but override the LLM when needed in the summarization process+ summary_profile = default_profile+ else:+ # Fallback to old profile-based approach+ try:+ profile_manager: ProfileManager = ProfileManager.objects.get(+ prompt_studio_tool=tool, is_summarize_llm=True+ )+ profile_manager.chunk_size = 0+ summary_profile = profile_manager+ except ProfileManager.DoesNotExist:+ # If no summarize profile exists, continue with default profile+ logger.warning(+ f"No summarize profile found for tool {tool_id}, using default profile"+ )+ summary_profile = default_profileif not tool:logger.error(f"No tool instance found for the ID {tool_id}")@@ -366,6 +387,11 @@ class PromptStudioHelper:# has access to adapters configured in profile managerPromptStudioHelper.validate_profile_manager_owner_access(default_profile)+ # Also validate summary profile if it's different from default+ if tool.summarize_context and summary_profile != default_profile:+ PromptStudioHelper.validate_adapter_status(summary_profile)+ PromptStudioHelper.validate_profile_manager_owner_access(summary_profile)+fs_instance = EnvHelper.get_storage(storage_type=StorageType.PERMANENT,env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,@@ -392,24 +418,24 @@ class PromptStudioHelper:doc_id=doc_id,reindex=True,)- if is_summary:+ if tool.summarize_context:summarize_file_path = PromptStudioHelper.summarize(- file_name, org_id, document_id, is_summary, run_id, tool, doc_id+ file_name, org_id, document_id, run_id, tool, doc_id)summarize_doc_id = IndexingUtils.generate_index_key(- vector_db=str(default_profile.vector_store.id),- embedding=str(default_profile.embedding_model.id),- x2text=str(default_profile.x2text.id),- chunk_size=str(default_profile.chunk_size),- chunk_overlap=str(default_profile.chunk_overlap),+ vector_db=str(summary_profile.vector_store.id),+ embedding=str(summary_profile.embedding_model.id),+ x2text=str(summary_profile.x2text.id),+ chunk_size="0", # Summarization always uses chunk_size=0+ chunk_overlap=str(summary_profile.chunk_overlap),file_path=summarize_file_path,fs=fs_instance,tool=util,)PromptStudioIndexHelper.handle_index_manager(document_id=document_id,- is_summary=is_summary,- profile_manager=profile_manager,+ is_summary=True,+ profile_manager=summary_profile,doc_id=summarize_doc_id,)start_time = time.time()@@ -450,9 +476,7 @@ class PromptStudioHelper:return doc_id@staticmethod- def summarize(- file_name, org_id, document_id, is_summary, run_id, tool, doc_id- ) -> str:+ def summarize(file_name, org_id, document_id, run_id, tool, doc_id) -> str:cls = get_plugin_class_by_name(name="summarizer",plugins=PromptStudioHelper.processor_plugins,@@ -471,17 +495,21 @@ class PromptStudioHelper:usage_kwargs=usage_kwargs.copy(),prompts=prompts,)- profile_manager: ProfileManager = ProfileManager.objects.get(- prompt_studio_tool=tool, is_summarize_llm=True- )- default_profile = profile_manager- default_profile.chunk_size = 0- PromptStudioIndexHelper.handle_index_manager(- document_id=document_id,- is_summary=is_summary,- profile_manager=default_profile,- doc_id=doc_id,- )+ # Trigger migration if needed+ SummarizeMigrationUtils.migrate_tool_to_adapter_based(tool)++ # Validate that summarization is properly configured+ if not tool.summarize_llm_adapter:+ # Fallback to old approach if no adapter - just validate it exists+ try:+ ProfileManager.objects.get(+ prompt_studio_tool=tool, is_summarize_llm=True+ )+ except ProfileManager.DoesNotExist:+ logger.warning(+ f"No summarize profile found for tool {tool.tool_id}, using default profile"+ )+return summarize_file_path@staticmethoddiff --git a/backend/prompt_studio/prompt_studio_core_v2/views.py b/backend/prompt_studio/prompt_studio_core_v2/views.pyindex 83a8e4866..f7273d817 100644--- a/backend/prompt_studio/prompt_studio_core_v2/views.py+++ b/backend/prompt_studio/prompt_studio_core_v2/views.py@@ -247,7 +247,6 @@ class PromptStudioCoreView(viewsets.ModelViewSet):file_name: str = document.document_name# Generate a run_idrun_id = CommonUtils.generate_uuid()- is_summary = tool.summarize_contextunique_id = PromptStudioHelper.index_document(tool_id=str(tool.tool_id),@@ -256,7 +255,6 @@ class PromptStudioCoreView(viewsets.ModelViewSet):user_id=tool.created_by.user_id,document_id=document_id,run_id=run_id,- is_summary=is_summary,)if unique_id:return Response(diff --git a/frontend/src/components/agency/agency/Agency.jsx b/frontend/src/components/agency/agency/Agency.jsxindex 6c38331fa..0e7fe06aa 100644--- a/frontend/src/components/agency/agency/Agency.jsx+++ b/frontend/src/components/agency/agency/Agency.jsx@@ -12,6 +12,8 @@ import {BugOutlined,SettingOutlined,PlayCircleOutlined,+ ClearOutlined,+ HistoryOutlined,} from "@ant-design/icons";import { useEffect, useState } from "react";import { Link } from "react-router-dom";@@ -400,6 +402,61 @@ function Agency() {return `Deploy as ${type}`;};+ // Get available deployment options based on source and destination types+ const getDeploymentOptions = () => {+ // If both source and destination are API, only show API option+ if (+ source?.connection_type === "API" &&+ destination?.connection_type === "API"+ ) {+ return [+ {+ value: "API",+ label: getDeploymentStatusText("API"),+ disabled: false,+ },+ ];+ }++ // If source is FILESYSTEM, determine options based on destination+ if (source?.connection_type === "FILESYSTEM") {+ const options = [];++ // If destination is Database or ManualReview → show ETL only+ if (+ destination?.connection_type === "DATABASE" ||+ destination?.connection_type === "MANUALREVIEW"+ ) {+ options.push({+ value: "ETL",+ label: getDeploymentStatusText("ETL"),+ disabled: false,+ });+ }+ // If destination is FileSystem → show TASK only+ else if (destination?.connection_type === "FILESYSTEM") {+ options.push({+ value: "TASK",+ label: getDeploymentStatusText("TASK"),+ disabled: false,+ });+ }+ // If destination is API → show API only+ else if (destination?.connection_type === "API") {+ options.push({+ value: "API",+ label: getDeploymentStatusText("API"),+ disabled: false,+ });+ }++ return options;+ }++ // Default case - return empty array if no valid combination+ return [];+ };+// Generate deployment alert message contentconst generateDeploymentMessage = () => {if (deploymentInfo) {@@ -976,10 +1033,12 @@ function Agency() {{key: "clear-cache",label: "Clear Cache",+ icon: <ClearOutlined />,},{key: "clear-history",label: "Clear Processed File History",+ icon: <HistoryOutlined />,},];@@ -1162,28 +1221,7 @@ function Agency() {!source?.connection_type ||!destination?.connection_type}- options={- apiOpsPresent- ? [- {- value: "API",- label: getDeploymentStatusText("API"),- disabled: false,- },- ]- : [- {- value: "ETL",- label: getDeploymentStatusText("ETL"),- disabled: false,- },- {- value: "TASK",- label: getDeploymentStatusText("TASK"),- disabled: false,- },- ]- }+ options={getDeploymentOptions()}/><Buttontype="primary"diff --git a/frontend/src/components/agency/ds-settings-card/DsSettingsCard.css b/frontend/src/components/agency/ds-settings-card/DsSettingsCard.cssindex c1af18e8a..bbfca93af 100644--- a/frontend/src/components/agency/ds-settings-card/DsSettingsCard.css+++ b/frontend/src/components/agency/ds-settings-card/DsSettingsCard.css@@ -6,10 +6,14 @@z-index: 20;}-.ds-set-card-select{+.ds-set-card-select {width: 200px !important;}-.ds-set-card-btn{+.ds-set-card-btn {align-self: flex-end;}++.ds-set-card-message {+ margin-bottom: 0px !important;+}diff --git a/frontend/src/components/agency/ds-settings-card/DsSettingsCard.jsx b/frontend/src/components/agency/ds-settings-card/DsSettingsCard.jsxindex c42e37c58..7299fa16f 100644--- a/frontend/src/components/agency/ds-settings-card/DsSettingsCard.jsx+++ b/frontend/src/components/agency/ds-settings-card/DsSettingsCard.jsx@@ -338,11 +338,41 @@ function DsSettingsCard({ type, endpointDetails, message }) {return "";};+ // Check if connector is configured+ const isConnectorConfigured = () => {+ // For API connections, connector_instance is not required+ if (endpointDetails?.connection_type === "API") {+ return true;+ }++ // For other connection types (Database, etc.), check if connector instance is configured+ // connector_instance represents the actual configured connector with credentials+ return !!endpointDetails?.connector_instance;+ };++ // Get configure button text based on configuration status+ const getConfigureButtonText = () => {+ if (!endpointDetails?.connection_type) {+ return "Configure";+ }++ return isConnectorConfigured() ? "Configured" : "Configure";+ };+return (<><Row className="ds-set-card-row"><Col span={12} className="ds-set-card-col2"><SpaceWrapper>+ {message && (+ <Typography.Paragraph+ ellipsis={{ rows: 2, expandable: false }}+ className="font-size-12 ds-set-card-message"+ type="secondary"+ >+ {message}+ </Typography.Paragraph>+ )}<Space><Tooltiptitle={@@ -376,21 +406,12 @@ function DsSettingsCard({ type, endpointDetails, message }) {connType === "APPDEPLOYMENT"}>- Configure+ {getConfigureButtonText()}</Button></Tooltip></Space></SpaceWrapper></Col>- <Col span={8} className="ds-set-card-col3">- <Typography.Paragraph- ellipsis={{ rows: 2, expandable: false }}- className="font-size-12"- type="secondary"- >- {message}- </Typography.Paragraph>- </Col></Row><ConfigureConnectorModalopen={openModal}diff --git a/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.css b/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.cssindex 87ec096da..386dfbd47 100644--- a/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.css+++ b/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.css@@ -18,3 +18,18 @@.manage-docs-div {margin: 0;}++.summarization-status-circle {+ width: 8px;+ height: 8px;+ border-radius: 50%;+ display: inline-block;+}++.summarization-status-enabled {+ background-color: #52c41a;+}++.summarization-status-disabled {+ background-color: #ff4d4f;+}diff --git a/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.jsx b/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.jsxindex d6b358664..310447e25 100644--- a/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.jsx+++ b/frontend/src/components/custom-tools/manage-docs-modal/ManageDocsModal.jsx@@ -75,6 +75,7 @@ function ManageDocsModal({const [rawLlmProfile, setRawLlmProfile] = useState(null);const [isRawDataLoading, setIsRawDataLoading] = useState(false);const [summarizeLlmProfile, setSummarizeLlmProfile] = useState(null);+ const [summarizeLlmAdapter, setSummarizeLlmAdapter] = useState(null);const [isSummarizeDataLoading, setIsSummarizeDataLoading] = useState(false);const [indexMessages, setIndexMessages] = useState({});const [isModalVisible, setIsModalVisible] = useState(false);@@ -98,6 +99,7 @@ function ManageDocsModal({summarizeIndexStatus,isSinglePassExtractLoading,isPublicSource,+ adapters = [],} = useCustomToolStore();const { messages } = useSocketCustomToolStore();const axiosPrivate = useAxiosPrivate();@@ -158,6 +160,12 @@ function ManageDocsModal({useEffect(() => {setRawLlmProfile(defaultLlmProfile);setSummarizeLlmProfile(details?.summarize_llm_profile);+ setSummarizeLlmAdapter(+ details?.summarize_llm_adapter?.adapter_id ??+ details?.summarize_llm_adapter?.id ??+ details?.summarize_llm_adapter ??+ null+ );}, [defaultLlmProfile, details]);useEffect(() => {@@ -172,8 +180,19 @@ function ManageDocsModal({return;}- handleGetIndexStatus(summarizeLlmProfile, indexTypes.summarize);- }, [indexDocs, summarizeLlmProfile, open]);+ // For index status, we always need a profile ID, not adapter ID+ // If using new adapter approach, use default profile for index status+ // If using old approach, use the summarize profile+ const summarizeProfileId =+ summarizeLlmProfile || (summarizeLlmAdapter ? defaultLlmProfile : null);+ handleGetIndexStatus(summarizeProfileId, indexTypes.summarize);+ }, [+ indexDocs,+ summarizeLlmAdapter,+ summarizeLlmProfile,+ defaultLlmProfile,+ open,+ ]);useEffect(() => {// Reverse the array to have the latest logs at the beginning@@ -304,6 +323,35 @@ function ManageDocsModal({return llmProfileName?.profile_name || "No LLM Profile Selected";};+ const isSummarizationConfigured = () =>+ !!(summarizeLlmAdapter || summarizeLlmProfile);++ const isSummarizationEnabled = () =>+ isSummarizationConfigured() && details?.summarize_context;++ const getSummarizeLlmDisplayName = () => {+ // Check if new adapter approach is used+ if (summarizeLlmAdapter) {+ const selectedAdapterId =+ typeof summarizeLlmAdapter === "object"+ ? summarizeLlmAdapter?.adapter_id ?? summarizeLlmAdapter?.id+ : summarizeLlmAdapter;+ const adapter = adapters?.find(+ (item) =>+ item?.adapter_id === selectedAdapterId ||+ item?.id === selectedAdapterId+ );+ return adapter?.adapter_name || adapter?.name || "No adapter selected";+ }++ // Fall back to profile approach+ if (summarizeLlmProfile) {+ return getLlmProfileName(summarizeLlmProfile);+ }++ return "Summarization Not Configured";+ };+const columns = [{title: "Document Variants",@@ -347,10 +395,35 @@ function ManageDocsModal({if (SummarizeStatusTitle) {columns.splice(2, 0, {title: (- <SummarizeStatusTitle- profileName={"(" + getLlmProfileName(summarizeLlmProfile) + ")"}- isLoading={isSummarizeDataLoading}- />+ <Space className="w-100">+ <Typography.Text>Summary View</Typography.Text>+ <Typography.Text type="secondary">+ {"(" + getSummarizeLlmDisplayName() + ")"}+ </Typography.Text>+ {isSummarizeDataLoading && <SpinnerLoader />}+ {isSummarizationConfigured() && (+ <Tooltip+ title={+ isSummarizationEnabled()+ ? "Summarization enabled"+ : "Summarization disabled"+ }+ >+ <span+ className={`summarization-status-circle ${+ isSummarizationEnabled()+ ? "summarization-status-enabled"+ : "summarization-status-disabled"+ }`}+ aria-label={+ isSummarizationEnabled()+ ? "Summarization enabled"+ : "Summarization disabled"+ }+ />+ </Tooltip>+ )}+ </Space>),dataIndex: "summary",key: "summary",@@ -470,6 +543,9 @@ function ManageDocsModal({indexDocs,messages,isSinglePassExtractLoading,+ adapters,+ summarizeLlmAdapter,+ summarizeLlmProfile,]);const beforeUpload = (file) => {