Skip to content

Commit

Permalink
feat: Removed assertion logic in prompt service and other fixes (#325)
Browse files Browse the repository at this point in the history
* Removed assertion logic in prompt service, dead code removed, set default log level for prompt service

* Used constants for log level in prompt service

* Reverted flask service name for prompt service

* Update prompt-service/src/unstract/prompt_service/main.py

Signed-off-by: Chandrasekharan M <117059509+chandrasekharan-zipstack@users.noreply.github.com>

* Removed Code Related to Assertion in the FE (#327)

Removed code related to assertion in the FE

Co-authored-by: Deepak K <89829542+Deepak-Kesavan@users.noreply.github.com>

---------

Signed-off-by: Chandrasekharan M <117059509+chandrasekharan-zipstack@users.noreply.github.com>
Co-authored-by: Tahier Hussain <89440263+tahierhussain@users.noreply.github.com>
Co-authored-by: Deepak K <89829542+Deepak-Kesavan@users.noreply.github.com>
Co-authored-by: Neha <115609453+nehabagdia@users.noreply.github.com>
  • Loading branch information
4 people committed May 10, 2024
1 parent 3b787e8 commit 1454d90
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 383 deletions.
6 changes: 0 additions & 6 deletions backend/prompt_studio/prompt_studio/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,3 @@ class AnswerFetchError(APIException):
class ToolNotValid(APIException):
status_code = 400
default_detail = "Custom tool is not valid."


class PromptNotValid(APIException):
status_code = 400
default_detail = "Input prompt instance is not valid.\
Seems it is either empty or no prompt is mapped."
6 changes: 0 additions & 6 deletions backend/prompt_studio/prompt_studio_core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ class ToolNotValid(APIException):
default_detail = "Custom tool is not valid."


class PromptNotValid(APIException):
status_code = 400
default_detail = "Input prompt instance is not valid.\
Seems it is either empty or no prompt is mapped."


class IndexingAPIError(APIException):
status_code = 500
default_detail = "Error while indexing file"
Expand Down
20 changes: 10 additions & 10 deletions backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
IndexingAPIError,
NoPromptsFound,
PermissionError,
PromptNotValid,
ToolNotValid,
)
from prompt_studio.prompt_studio_core.models import CustomTool
Expand Down Expand Up @@ -310,7 +309,6 @@ def prompt_responder(
id (Optional[str]): ID of the prompt
Raises:
PromptNotValid: If a prompt could not be queried from the DB
AnswerFetchError: Error from prompt-service
Returns:
Expand All @@ -329,13 +327,10 @@ def prompt_responder(

if id:
prompt_instance = PromptStudioHelper._fetch_prompt_from_id(id)
if not prompt_instance:
logger.error(f"[{tool_id or 'NA'}] Invalid prompt id: {id}")
raise PromptNotValid()

prompt_name = prompt_instance.prompt_key
logger.info(f"[{tool_id}] Executing single prompt {id}")
PromptStudioHelper._publish_log(
{"tool_id": tool_id, "prompt_id": id, "doc_name": doc_name},
{"tool_id": tool_id, "prompt_key": prompt_name, "doc_name": doc_name},
LogLevels.INFO,
LogLevels.RUN,
"Executing single prompt",
Expand All @@ -355,7 +350,7 @@ def prompt_responder(

logger.info(f"[{tool.tool_id}] Invoking prompt service for prompt {id}")
PromptStudioHelper._publish_log(
{"tool_id": tool_id, "prompt_id": id, "doc_name": doc_name},
{"tool_id": tool_id, "prompt_key": prompt_name, "doc_name": doc_name},
LogLevels.DEBUG,
LogLevels.RUN,
"Invoking prompt service",
Expand All @@ -382,7 +377,11 @@ def prompt_responder(
f"[{tool.tool_id}] Error while fetching response for prompt {id}: {e}" # noqa: E501
)
PromptStudioHelper._publish_log(
{"tool_id": tool_id, "prompt_id": id},
{
"tool_id": tool_id,
"prompt_key": prompt_name,
"doc_name": doc_name,
},
LogLevels.ERROR,
LogLevels.RUN,
f"Failed to fetch prompt response. {e}",
Expand All @@ -393,7 +392,7 @@ def prompt_responder(
f"[{tool.tool_id}] Response fetched successfully for prompt {id}" # noqa: E501
)
PromptStudioHelper._publish_log(
{"tool_id": tool_id, "prompt_id": id},
{"tool_id": tool_id, "prompt_key": prompt_name, "doc_name": doc_name},
LogLevels.INFO,
LogLevels.RUN,
"Single prompt execution completed",
Expand Down Expand Up @@ -539,6 +538,7 @@ def _fetch_response(
)

output: dict[str, Any] = {}
# TODO: Deprecate and remove assertion related elements
output[TSPKeys.ASSERTION_FAILURE_PROMPT] = prompt.assertion_failure_prompt
output[TSPKeys.ASSERT_PROMPT] = prompt.assert_prompt
output[TSPKeys.IS_ASSERT] = prompt.is_assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ def frame_export_json(

if invalidated_prompts:
raise InValidCustomToolError(
f"Cannot export tool. Prompt(s) : {invalidated_prompts} "
"are not valid. Please enter a valid prompt."
f"Cannot export tool. Prompt(s): {', '.join(invalidated_prompts)} "
"are empty. Please enter a valid prompt."
)
if invalidated_outputs:
raise InValidCustomToolError(
f"Cannot export tool. Prompt(s) : {invalidated_outputs} "
f"Cannot export tool. Prompt(s): {', '.join(invalidated_outputs)} "
"were not run. Please run them before exporting."
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.1 on 2024-05-08 12:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("tenant_account", "0005_organizationmember_is_onboarding_msg_and_more"),
]

operations = [
migrations.AlterField(
model_name="organizationmember",
name="is_login_onboarding_msg",
field=models.BooleanField(
db_comment="Flag to indicate whether the onboarding messages are shown",
default=True,
),
),
migrations.AlterField(
model_name="organizationmember",
name="is_prompt_studio_onboarding_msg",
field=models.BooleanField(
db_comment="Flag to indicate whether the prompt studio messages are shown",
default=True,
),
),
]
2 changes: 0 additions & 2 deletions frontend/src/assets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { ReactComponent as ListOfWfStepsPlaceholder } from "./list-of-wf-steps-p
import { ReactComponent as ListOfToolsPlaceholder } from "./list-of-tools-placeholder.svg";
import { ReactComponent as ApiDeployments } from "./api-deployments.svg";
import { ReactComponent as StepIcon } from "./steps.svg";
import { ReactComponent as AssertionIcon } from "./assertion.svg";
import { ReactComponent as CombinedOutputIcon } from "./combined-output.svg";
import { ReactComponent as EmptyPlaceholder } from "./empty.svg";
import { ReactComponent as Desktop } from "./desktop.svg";
Expand Down Expand Up @@ -52,7 +51,6 @@ export {
ApiDeployments,
StepIcon,
EmptyPlaceholder,
AssertionIcon,
CombinedOutputIcon,
Desktop,
ReachOut,
Expand Down
27 changes: 0 additions & 27 deletions frontend/src/components/custom-tools/prompt-card/PromptCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,37 +91,10 @@
margin-bottom: 2px;
}

.assert-p-l-4 {
padding-left: 4px;
}

.assert-p-r-4 {
padding-right: 4px;
}

.assertion-comp {
background-color: #eceff3;
border-end-end-radius: 0px;
border-end-start-radius: 0px;
}

.assertion-comp .ant-collapse-header {
display: none !important;
padding: 0 !important;
}

.assertion-comp .ant-collapse-content-box {
padding: 0px !important;
}

.prompt-card-action-button.ant-btn-text:disabled > .prompt-card-actions-head {
color: rgba(0, 0, 0, 0.25);
}

.prompt-card-action-button.ant-btn-text:disabled > .assertion-icon > path {
fill: rgba(0, 0, 0, 0.25);
}

.tag-max-width {
max-width: 150px;
}

0 comments on commit 1454d90

Please sign in to comment.