diff --git a/backend/prompt_studio/prompt_studio_core/exceptions.py b/backend/prompt_studio/prompt_studio_core/exceptions.py index 1d553603f..1d3d1dda2 100644 --- a/backend/prompt_studio/prompt_studio_core/exceptions.py +++ b/backend/prompt_studio/prompt_studio_core/exceptions.py @@ -29,9 +29,11 @@ class AnswerFetchError(APIException): class DefaultProfileError(APIException): - status_code = 400 - default_detail = "Default profile is not selected. \ - Please select one from Profile manager." + status_code = 500 + default_detail = ( + "Default LLM profile is not configured." + "Please set an LLM profile as default to continue." + ) class EnvRequired(APIException): diff --git a/backend/prompt_studio/prompt_studio_core/models.py b/backend/prompt_studio/prompt_studio_core/models.py index 4dbf94358..9dbda4a6d 100644 --- a/backend/prompt_studio/prompt_studio_core/models.py +++ b/backend/prompt_studio/prompt_studio_core/models.py @@ -1,7 +1,9 @@ import uuid from account.models import User +from django.core.exceptions import ObjectDoesNotExist from django.db import models +from prompt_studio.prompt_studio_core.exceptions import DefaultProfileError from utils.models.base_model import BaseModel @@ -68,3 +70,10 @@ class CustomTool(BaseModel): blank=True, editable=False, ) + + # TODO: Add ProfileManager to return type + def get_default_llm_profile(self): # type: ignore + try: + return self.profilemanager_set.filter(is_default=True).first() + except ObjectDoesNotExist: + raise DefaultProfileError 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.py index a2e42b6f9..384573f6f 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 @@ -12,7 +12,7 @@ from unstract.tool_registry.dto import Properties, Spec, Tool from .constants import JsonSchemaKey -from .exceptions import InternalError, ProfileErrors, ToolSaveError +from .exceptions import InternalError, ToolSaveError from .models import PromptStudioRegistry from .serializers import PromptStudioRegistrySerializer @@ -180,11 +180,10 @@ def frame_export_json( llm = "" embedding_model = "" + default_llm_profile = tool.get_default_llm_profile() # type: ignore for prompt in prompts: - if not tool.default_profile: - raise ProfileErrors() if not prompt.profile_manager: - prompt.profile_manager = tool.default_profile + prompt.profile_manager = default_llm_profile vector_db = str(prompt.profile_manager.vector_store.id) embedding_model = str(prompt.profile_manager.embedding_model.id) diff --git a/tools/structure/requirements.txt b/tools/structure/requirements.txt index e7658f93e..a852e5f35 100644 --- a/tools/structure/requirements.txt +++ b/tools/structure/requirements.txt @@ -1,4 +1,4 @@ # Add your dependencies here # Required for all unstract tools -unstract-sdk~=0.15.0 +unstract-sdk~=0.15.1 diff --git a/tools/structure/src/config/properties.json b/tools/structure/src/config/properties.json index e1c52bda3..903a649b4 100644 --- a/tools/structure/src/config/properties.json +++ b/tools/structure/src/config/properties.json @@ -2,7 +2,7 @@ "schemaVersion": "0.0.1", "displayName": "Structure Tool", "functionName": "structure_tool", - "toolVersion": "0.0.3", + "toolVersion": "0.0.4", "description": "This is a template tool which can answer set of input prompts designed in the Prompt Studio", "input": { "description": "File that needs to be indexed and parsed for answers"