LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
Default profile creation for prompt studio project (#353)
Rahul Johny3024f43ac39d
diff --git a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.pyindex 43410c10c..00d8d4309 100644--- a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py+++ b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py@@ -1,12 +1,16 @@import jsonimport loggingimport os+import uuidfrom pathlib import Pathfrom typing import Any, Optionalfrom account.constants import Common+from account.models import User+from adapter_processor.constants import AdapterKeysfrom adapter_processor.models import AdapterInstancefrom django.conf import settings+from django.db.models.manager import BaseManagerfrom file_management.file_management_helper import FileManagerHelperfrom prompt_studio.prompt_profile_manager.models import ProfileManagerfrom prompt_studio.prompt_studio.models import ToolStudioPrompt@@ -48,6 +52,62 @@ logger = logging.getLogger(__name__)class PromptStudioHelper:"""Helper class for Custom tool operations."""+ @staticmethod+ def create_default_profile_manager(user: User, tool_id: uuid) -> None:+ """Create a default profile manager for a given user and tool.++ Args:+ user (User): The user for whom the default profile manager is+ created.+ tool_id (uuid): The ID of the tool for which the default profile+ manager is created.++ Raises:+ AdapterInstance.DoesNotExist: If no suitable adapter instance is+ found for creating the default profile manager.++ Returns:+ None+ """+ try:+ AdapterInstance.objects.get(+ is_friction_less=True,+ is_usable=True,+ adapter_type=AdapterKeys.LLM,+ )++ default_adapters: BaseManager[AdapterInstance] = (+ AdapterInstance.objects.filter(is_friction_less=True)+ )++ profile_manager = ProfileManager(+ prompt_studio_tool=CustomTool.objects.get(pk=tool_id),+ is_default=True,+ created_by=user,+ modified_by=user,+ chunk_size=0,+ profile_name="sample profile",+ chunk_overlap=0,+ section="Default",+ retrieval_strategy="simple",+ similarity_top_k=3,+ )++ for adapter in default_adapters:+ if adapter.adapter_type == AdapterKeys.LLM:+ profile_manager.llm = adapter+ elif adapter.adapter_type == AdapterKeys.VECTOR_DB:+ profile_manager.vector_store = adapter+ elif adapter.adapter_type == AdapterKeys.X2TEXT:+ profile_manager.x2text = adapter+ elif adapter.adapter_type == AdapterKeys.EMBEDDING:+ profile_manager.embedding_model = adapter++ profile_manager.save()++ except AdapterInstance.DoesNotExist:+ logger.info("skipping default profile creation")+@staticmethoddef validate_adapter_status(profile_manager: ProfileManager,diff --git a/backend/prompt_studio/prompt_studio_core/views.py b/backend/prompt_studio/prompt_studio_core/views.pyindex 1b0f2b19c..235e266b4 100644--- a/backend/prompt_studio/prompt_studio_core/views.py+++ b/backend/prompt_studio/prompt_studio_core/views.py@@ -88,6 +88,9 @@ class PromptStudioCoreView(viewsets.ModelViewSet):f"{ToolStudioErrors.TOOL_NAME_EXISTS}, \{ToolStudioErrors.DUPLICATE_API}")+ PromptStudioHelper.create_default_profile_manager(+ request.user, serializer.data["tool_id"]+ )return Response(serializer.data, status=status.HTTP_201_CREATED)def perform_destroy(self, instance: CustomTool) -> None: