Skip to content

Commit

Permalink
Multitenancy V2 porting of Table settings enhancements (#751)
Browse files Browse the repository at this point in the history
* V2 porting of Table settings enhancements

* V2 porting of Table settings enhancements

---------

Co-authored-by: Neha <[email protected]>
  • Loading branch information
harini-venkataraman and nehabagdia authored Oct 1, 2024
1 parent 1507085 commit e36941f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions backend/prompt_studio/prompt_studio_core_v2/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class ToolStudioPromptKeys:
PLATFORM_POSTAMBLE = "platform_postamble"
SUMMARIZE_AS_SOURCE = "summarize_as_source"
VARIABLE_MAP = "variable_map"
RECORD = "record"


class FileViewTypes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

logger = logging.getLogger(__name__)

modifier_loader = load_modifier_plugins()
modifier_plugins = load_modifier_plugins()


class PromptStudioHelper:
Expand Down Expand Up @@ -262,6 +262,11 @@ def get_select_fields() -> dict[str, Any]:
choices = f.read()
f.close()
response: dict[str, Any] = json.loads(choices)
for modifier_plugin in modifier_plugins:
cls = modifier_plugin[ModifierConfig.METADATA][
ModifierConfig.METADATA_SERVICE_CLASS
]
response = cls.update_select_choices(default_choices=response)
return response

@staticmethod
Expand Down Expand Up @@ -451,7 +456,10 @@ def _execute_single_prompt(
):
prompt_instance = PromptStudioHelper._fetch_prompt_from_id(id)

if prompt_instance.enforce_type == TSPKeys.TABLE and not modifier_loader:
if (
prompt_instance.enforce_type == TSPKeys.TABLE
or prompt_instance.enforce_type == TSPKeys.RECORD
) and not modifier_plugins:
raise OperationNotSupported()

prompt_name = prompt_instance.prompt_key
Expand Down Expand Up @@ -547,6 +555,7 @@ def _execute_prompts_in_single_pass(
if prompt.prompt_type != TSPKeys.NOTES
and prompt.active
and prompt.enforce_type != TSPKeys.TABLE
and prompt.enforce_type != TSPKeys.RECORD
]
if not prompts:
logger.error(f"[{tool_id or 'NA'}] No prompts found for id: {id}")
Expand Down Expand Up @@ -841,13 +850,16 @@ def fetch_table_settings_if_enabled(
output: dict[str, Any],
) -> dict[str, Any]:

if prompt.enforce_type == TSPKeys.TABLE:
if (
prompt.enforce_type == TSPKeys.TABLE
or prompt.enforce_type == TSPKeys.RECORD
):
extract_doc_path: str = (
PromptStudioHelper._get_extract_or_summary_document_path(
org_id, user_id, tool_id, doc_name, TSPKeys.EXTRACT
)
)
for modifier_plugin in modifier_loader:
for modifier_plugin in modifier_plugins:
cls = modifier_plugin[ModifierConfig.METADATA][
ModifierConfig.METADATA_SERVICE_CLASS
]
Expand All @@ -857,6 +869,7 @@ def fetch_table_settings_if_enabled(
prompt_id=str(prompt.prompt_id),
prompt=prompt.prompt,
input_file=extract_doc_path,
clean_pages=True,
)

return output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"date":"date",
"boolean":"boolean",
"json":"json",
"table":"table"
"table":"table",
"record":"record"
},
"output_processing":{
"DEFAULT":"Default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PromptStudioRegistryKeys:
FILE_NAME = "file_name"
UNDEFINED = "undefined"
TABLE = "table"
RECORD = "record"


class PromptStudioRegistryErrors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .serializers import PromptStudioRegistrySerializer

logger = logging.getLogger(__name__)
modifier_loader = load_modifier_plugins()
modifier_plugins = load_modifier_plugins()


class PromptStudioRegistryHelper:
Expand Down Expand Up @@ -337,8 +337,11 @@ def frame_export_json(
output[JsonSchemaKey.REINDEX] = prompt.profile_manager.reindex
output[JsonSchemaKey.EMBEDDING_SUFFIX] = embedding_suffix

if prompt.enforce_type == PromptStudioRegistryKeys.TABLE:
for modifier_plugin in modifier_loader:
if (
prompt.enforce_type == PromptStudioRegistryKeys.TABLE
or prompt.enforce_type == PromptStudioRegistryKeys.RECORD
):
for modifier_plugin in modifier_plugins:
cls = modifier_plugin[ModifierConfig.METADATA][
ModifierConfig.METADATA_SERVICE_CLASS
]
Expand Down
6 changes: 6 additions & 0 deletions backend/prompt_studio/prompt_studio_v2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class EnforceType(models.TextChoices):
BOOLEAN = "boolean", "Response sent as boolean"
JSON = "json", "Response sent as json"
TABLE = "table", "Response sent as table"
RECORD = "record", (
"Response sent for records. "
"Entries of records are list of "
"logical and organized individual "
"entities with distint values"
)

class PromptType(models.TextChoices):
PROMPT = "PROMPT", "Response sent as Text"
Expand Down

0 comments on commit e36941f

Please sign in to comment.