-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Zipstack/feature/prompt-studio-summarize
Prompt Studio - Summarize, Output Analyzer and other UI Improvements
- Loading branch information
Showing
46 changed files
with
1,458 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
backend/adapter_processor/migrations/0005_alter_adapterinstance_adapter_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ompt_studio/prompt_studio_core/migrations/0004_customtool_summarize_as_source_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
), | ||
), | ||
] |
53 changes: 53 additions & 0 deletions
53
...pt_studio/prompt_studio_core/migrations/0005_alter_customtool_default_profile_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.