Skip to content

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

Handling multi-prompt run (#331)

Gayathriad1879286625
diff --git a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py
index f3864c10f..530293c57 100644
--- a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py
+++ b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py
@@ -675,7 +675,7 @@ class PromptStudioHelper:
doc_id=doc_id,
)
return doc_id
- except IndexingError as e:
+ except (IndexingError, IndexingAPIError) as e:
doc_name = os.path.split(file_path)[1]
PromptStudioHelper._publish_log(
{"tool_id": tool_id, "doc_name": doc_name},
diff --git a/backend/prompt_studio/prompt_studio_index_manager/prompt_studio_index_helper.py b/backend/prompt_studio/prompt_studio_index_manager/prompt_studio_index_helper.py
index 82a768e94..b66796a19 100644
--- a/backend/prompt_studio/prompt_studio_index_manager/prompt_studio_index_helper.py
+++ b/backend/prompt_studio/prompt_studio_index_manager/prompt_studio_index_helper.py
@@ -1,8 +1,8 @@
import json
import logging
-from typing import Optional
from prompt_studio.prompt_profile_manager.models import ProfileManager
+from prompt_studio.prompt_studio_core.exceptions import IndexingAPIError
from prompt_studio.prompt_studio_document_manager.models import DocumentManager
from .models import IndexManager
@@ -24,32 +24,40 @@ class PromptStudioIndexHelper:
if is_summary:
index_id = "summarize_index_id"
- try:
- index_manager: Optional[IndexManager] = IndexManager.objects.get(
- document_manager=document, profile_manager=profile_manager
- )
- except IndexManager.DoesNotExist:
- index_manager = None
+ args: dict[str, str] = dict()
+ args["document_manager"] = document
+ args["profile_manager"] = profile_manager
+ args[index_id] = doc_id
- args: dict[str, str] = {f"{index_id}": doc_id}
+ try:
+ # Create or get the existing record for this document and
+ # profile combo
+ index_manager, success = IndexManager.objects.get_or_create(**args)
+
+ if success:
+ logger.info(
+ f"Index manager doc_id: {doc_id} for "
+ f"profile {profile_manager.profile_id} created"
+ )
+ else:
+ logger.info(
+ f"Index manager doc_id: {doc_id} for "
+ f"profile {profile_manager.profile_id} updated"
+ )
- index_ids_list = []
- if index_manager:
index_ids = index_manager.index_ids_history
index_ids_list = json.loads(index_ids) if index_ids else []
if doc_id not in index_ids:
index_ids_list.append(doc_id)
- else:
- index_ids_list.append(doc_id)
- args["index_ids_history"] = json.dumps(index_ids_list)
+ args["index_ids_history"] = json.dumps(index_ids_list)
- if index_manager:
+ # Update the record with the index id
result: IndexManager = IndexManager.objects.filter(
index_manager_id=index_manager.index_manager_id
).update(**args)
- else:
- args["document_manager"] = document
- args["profile_manager"] = profile_manager
- result = IndexManager.objects.create(**args)
+
+ except Exception as e:
+ raise IndexingAPIError("Error updating indexing status") from e
+
return result
diff --git a/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx b/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx
index cb8afc4fa..3a8afe8ef 100644
--- a/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx
+++ b/frontend/src/components/custom-tools/prompt-card/PromptCard.jsx
@@ -631,7 +631,9 @@ function PromptCard({
(updateStatus?.promptId === promptDetails?.prompt_id &&
updateStatus?.status ===
promptStudioUpdateStatus.isUpdating) ||
- disableLlmOrDocChange?.length > 0 ||
+ disableLlmOrDocChange.includes(
+ promptDetails?.prompt_id
+ ) ||
indexDocs.includes(selectedDoc?.document_id)
}
>