Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4872fd4
Added /extract and /summarize path
tahierhussain Feb 26, 2024
fe3b205
Handled the logic to toggle between extract and summarize
tahierhussain Feb 26, 2024
498b42a
Persist the evaluation data inside the output manager
tahierhussain Feb 26, 2024
f71c791
Handled summarize view, raw view, persistence of eval data, and outpu…
tahierhussain Feb 26, 2024
ec5c932
Merge remote-tracking branch 'origin/main' into feature/prompt-studio…
Deepak-Kesavan Feb 27, 2024
0f01042
UI improvements and bug fixes
tahierhussain Feb 27, 2024
f26639c
Handled the state updation for the form values in SelectLlmProfileModal
tahierhussain Feb 27, 2024
b76c75f
Merge branch 'feature/prompt-studio-summarize' of github.com:Zipstack…
Deepak-Kesavan Feb 27, 2024
d60d5cf
Fixed the popup issue to display the error message
tahierhussain Feb 27, 2024
c7c07ed
Merge branch 'feature/prompt-studio-summarize' of github.com:Zipstack…
Deepak-Kesavan Feb 27, 2024
ddfce88
Added migration files for summarize and eval
Deepak-Kesavan Feb 27, 2024
daef5ce
Added support for processor plugins
Deepak-Kesavan Feb 27, 2024
a48175f
Fixed scroll issue in the output analyzer
tahierhussain Feb 27, 2024
a1ef571
Merge branch 'main' into feature/prompt-studio-summarize
Deepak-Kesavan Feb 28, 2024
a41f5f8
Updated sdk version and resolved review comments
Deepak-Kesavan Feb 28, 2024
5c1e02d
Updated migrations
Deepak-Kesavan Feb 28, 2024
6744598
Added processor directory
Deepak-Kesavan Feb 28, 2024
9309da5
Updated sdk version to 0.12.1
Deepak-Kesavan Feb 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ $RECYCLE.BIN/
backend/plugins/authentication/*
!backend/plugins/authentication/auth_sample

# Processor Plugins
backend/plugins/processor/*

# Tool registry
unstract/tool-registry/src/unstract/tool_registry/*.json
unstract/tool-registry/tests/*.yaml
Expand All @@ -627,5 +630,3 @@ tools/*/sdks/
tools/*/data_dir/

docker/workflow_data/


Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.1 on 2024-02-28 09:03

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("adapter_processor", "0004_alter_adapterinstance_adapter_type"),
]

operations = [
migrations.AlterField(
model_name="adapterinstance",
name="adapter_type",
field=models.CharField(
choices=[
("UNKNOWN", "UNKNOWN"),
("LLM", "LLM"),
("EMBEDDING", "EMBEDDING"),
("VECTOR_DB", "VECTOR_DB"),
("OCR", "OCR"),
("X2TEXT", "X2TEXT"),
],
db_comment="Type of adapter LLM/EMBEDDING/VECTOR_DB",
),
),
]
8 changes: 6 additions & 2 deletions backend/file_management/file_management_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def fetch_file_contents(
elif file_content_type == "text/plain":
with fs.open(file_path, "r") as file:
FileManagerHelper.logger.info(f"Reading text file: {file_path}")
encoded_string = base64.b64encode(file.read())
return encoded_string
text_content = file.read()
Comment thread
nehabagdia marked this conversation as resolved.
return text_content
else:
raise InvalidFileType

Expand Down Expand Up @@ -246,9 +246,13 @@ def handle_sub_directory_for_tenants(
raise OrgIdNotValid()
base_path = Path(settings.PROMPT_STUDIO_FILE_PATH)
file_path: Path = base_path / org_id / user_id / tool_id
extract_file_path: Path = Path(file_path, "extract")
summarize_file_path: Path = Path(file_path, "summarize")
if is_create:
try:
os.makedirs(file_path, exist_ok=True)
os.makedirs(extract_file_path, exist_ok=True)
os.makedirs(summarize_file_path, exist_ok=True)
except OSError as e:
FileManagerHelper.logger.error(
f"Error while creating {file_path}: {e}"
Expand Down
1 change: 0 additions & 1 deletion backend/file_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def upload(self, request: HttpRequest) -> Response:

@action(detail=True, methods=["post"])
def upload_for_ide(self, request: HttpRequest) -> Response:
print(request.data)
serializer = FileUploadIdeSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
uploaded_files: Any = serializer.validated_data.get("file")
Expand Down
10 changes: 5 additions & 5 deletions backend/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
76 changes: 76 additions & 0 deletions backend/prompt_studio/processor_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import logging
import os
from importlib import import_module
from typing import Any

from django.apps import apps

logger = logging.getLogger(__name__)


class ProcessorConfig:
"""Loader config for processor plugins."""

PLUGINS_APP = "plugins"
PLUGIN_DIR = "processor"
MODULE = "module"
METADATA = "metadata"
METADATA_NAME = "name"
METADATA_SERVICE_CLASS = "service_class"
METADATA_IS_ACTIVE = "is_active"


def load_plugins() -> list[Any]:
"""Iterate through the processor plugins and register them."""
plugins_app = apps.get_app_config(ProcessorConfig.PLUGINS_APP)
package_path = plugins_app.module.__package__
processor_dir = os.path.join(plugins_app.path, ProcessorConfig.PLUGIN_DIR)
processor_package_path = f"{package_path}.{ProcessorConfig.PLUGIN_DIR}"
processor_plugins: list[Any] = []

for item in os.listdir(processor_dir):
# Loads a plugin if it is in a directory.
if os.path.isdir(os.path.join(processor_dir, item)):
processor_module_name = item
# Loads a plugin if it is a shared library.
# Module name is extracted from shared library name.
# `processor.platform_architecture.so` will be file name and
# `processor` will be the module name.
elif item.endswith(".so"):
processor_module_name = item.split(".")[0]
else:
continue
try:
full_module_path = (
f"{processor_package_path}.{processor_module_name}"
)
module = import_module(full_module_path)
metadata = getattr(module, ProcessorConfig.METADATA, {})

if metadata.get(ProcessorConfig.METADATA_IS_ACTIVE, False):
processor_plugins.append(
{
ProcessorConfig.MODULE: module,
ProcessorConfig.METADATA: module.metadata,
}
)
logger.info(
"Loaded processor plugin: %s, is_active: %s",
module.metadata[ProcessorConfig.METADATA_NAME],
module.metadata[ProcessorConfig.METADATA_IS_ACTIVE],
)
else:
logger.info(
"Processor plugin %s is not active.",
processor_module_name,
)
except ModuleNotFoundError as exception:
logger.error(
"Error while importing processor plugin: %s",
exception,
)

if len(processor_plugins) == 0:
logger.info("No processor plugins found.")

return processor_plugins
2 changes: 2 additions & 0 deletions backend/prompt_studio/prompt_studio_core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class ToolStudioPromptKeys:
EVAL_SETTINGS_EVALUATE = "evaluate"
EVAL_SETTINGS_MONITOR_LLM = "monitor_llm"
EVAL_SETTINGS_EXCLUDE_FAILED = "exclude_failed"
SUMMARIZE = "summarize"
SUMMARIZED_RESULT = "summarized_result"


class LogLevels:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 4.2.1 on 2024-02-27 05:43

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("prompt_profile_manager", "0006_alter_profilemanager_x2text"),
("prompt_studio_core", "0003_merge_20240125_1501"),
]

operations = [
migrations.AddField(
model_name="customtool",
name="summarize_as_source",
field=models.BooleanField(default=True),
),
migrations.AddField(
model_name="customtool",
name="summarize_context",
field=models.BooleanField(default=True),
),
migrations.AddField(
model_name="customtool",
name="summarize_llm_profile",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="summarize_llm_profile",
to="prompt_profile_manager.profilemanager",
),
),
migrations.AddField(
model_name="customtool",
name="summarize_prompt",
field=models.TextField(
blank=True, db_comment="Field to store the summarize prompt"
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 4.2.1 on 2024-02-28 09:03

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("prompt_profile_manager", "0006_alter_profilemanager_x2text"),
("prompt_studio_core", "0004_customtool_summarize_as_source_and_more"),
]

operations = [
migrations.AlterField(
model_name="customtool",
name="default_profile",
field=models.ForeignKey(
blank=True,
db_comment="Default LLM Profile used in prompt",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="default_profile",
to="prompt_profile_manager.profilemanager",
),
),
migrations.AlterField(
model_name="customtool",
name="summarize_as_source",
field=models.BooleanField(
db_comment="Flag to use summarized content as source",
default=True,
),
),
migrations.AlterField(
model_name="customtool",
name="summarize_context",
field=models.BooleanField(
db_comment="Flag to summarize content", default=True
),
),
migrations.AlterField(
model_name="customtool",
name="summarize_llm_profile",
field=models.ForeignKey(
blank=True,
db_comment="LLM Profile used for summarize",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="summarize_llm_profile",
to="prompt_profile_manager.profilemanager",
),
),
]
20 changes: 20 additions & 0 deletions backend/prompt_studio/prompt_studio_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ class CustomTool(BaseModel):
related_name="default_profile",
null=True,
blank=True,
db_comment="Default LLM Profile used in prompt",
)
summarize_llm_profile = models.ForeignKey(
Comment thread
Deepak-Kesavan marked this conversation as resolved.
ProfileManager,
on_delete=models.SET_NULL,
related_name="summarize_llm_profile",
null=True,
blank=True,
db_comment="LLM Profile used for summarize",
)
summarize_context = models.BooleanField(
default=True, db_comment="Flag to summarize content"
)
summarize_as_source = models.BooleanField(
default=True, db_comment="Flag to use summarized content as source"
)
summarize_prompt = models.TextField(
Comment thread
nehabagdia marked this conversation as resolved.
blank=True,
db_comment="Field to store the summarize prompt",
unique=False,
)
prompt_grammer = models.JSONField(
null=True, blank=True, db_comment="Synonymous words used in prompt"
Expand Down
Loading