Skip to content

Commit

Permalink
Version update for adapters, sdk and llama-index for safety_settings …
Browse files Browse the repository at this point in the history
…for Vertex (#408)

* Version update for adapters to 0.19.0, sdk to 0.32.0 and llama-index to 0.10.38 for safety_support

* Rol version on tool properties

* Add comment

* Add a comment
  • Loading branch information
gaya3-zipstack authored Jun 17, 2024
1 parent 10e2148 commit 883ff9c
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 257 deletions.
11 changes: 8 additions & 3 deletions backend/adapter_processor/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import uuid
from typing import Any

Expand All @@ -9,13 +10,15 @@
from django.db.models import QuerySet
from unstract.adapters.adapterkit import Adapterkit
from unstract.adapters.enums import AdapterTypes
from unstract.adapters.llm.llm_adapter import LLMAdapter
from unstract.adapters.exceptions import AdapterError
from utils.models.base_model import BaseModel

ADAPTER_NAME_SIZE = 128
VERSION_NAME_SIZE = 64
ADAPTER_ID_LENGTH = 128

logger = logging.getLogger(__name__)


class AdapterInstanceModelManager(models.Manager):
def get_queryset(self) -> QuerySet[Any]:
Expand Down Expand Up @@ -146,9 +149,11 @@ def get_context_window_size(self) -> int:
adapter_metadata = self.get_adapter_meta_data()
# Get the adapter_instance
adapter_class = Adapterkit().get_adapter_class_by_adapter_id(self.adapter_id)
adapter_instance = adapter_class(adapter_metadata)
if isinstance(adapter_instance, LLMAdapter):
try:
adapter_instance = adapter_class(adapter_metadata)
return adapter_instance.get_context_window_size()
except AdapterError as e:
logger.warning(f"Unable to retrieve context window size - {e}")
return 0


Expand Down
10 changes: 7 additions & 3 deletions backend/adapter_processor/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rest_framework import serializers
from rest_framework.serializers import ModelSerializer
from unstract.adapters.constants import Common as common
from unstract.adapters.enums import AdapterTypes

from backend.constants import FieldLengthConstants as FLC
from backend.serializers import AuditSerializer
Expand Down Expand Up @@ -63,9 +64,12 @@ def to_representation(self, instance: AdapterInstance) -> dict[str, str]:

adapter_metadata = instance.get_adapter_meta_data()
rep[AdapterKeys.ADAPTER_METADATA] = adapter_metadata
adapter_metadata[AdapterKeys.ADAPTER_CONTEXT_WINDOW_SIZE] = (
instance.get_context_window_size()
)
# Retrieve context window if adapter is a LLM
# For other adapter types, context_window is not relevant.
if instance.adapter_type == AdapterTypes.LLM.value:
adapter_metadata[AdapterKeys.ADAPTER_CONTEXT_WINDOW_SIZE] = (
instance.get_context_window_size()
)

rep[common.ICON] = AdapterProcessor.get_adapter_data_with_key(
instance.adapter_id, common.ICON
Expand Down
132 changes: 66 additions & 66 deletions backend/pdm.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ dependencies = [
"python-socketio==5.9.0", # For log_events
"social-auth-app-django==5.3.0", # For OAuth
"social-auth-core==4.4.2", # For OAuth
"unstract-sdk~=0.31.1",
"unstract-adapters~=0.18.0",
"unstract-sdk~=0.32.0",
"unstract-adapters~=0.19.0",
# ! IMPORTANT!
# Indirect local dependencies usually need to be added in their own projects
# as: https://pdm-project.org/latest/usage/dependency/#local-dependencies.
Expand Down
4 changes: 2 additions & 2 deletions backend/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ PROMPT_PORT=3003
PROMPT_STUDIO_FILE_PATH=/app/prompt-studio-data

# Structure Tool
STRUCTURE_TOOL_IMAGE_URL="docker:unstract/tool-structure:0.0.24"
STRUCTURE_TOOL_IMAGE_URL="docker:unstract/tool-structure:0.0.25"
STRUCTURE_TOOL_IMAGE_NAME="unstract/tool-structure"
STRUCTURE_TOOL_IMAGE_TAG="0.0.24"
STRUCTURE_TOOL_IMAGE_TAG="0.0.25"

# Feature Flags
EVALUATION_SERVER_IP=localhost
Expand Down
132 changes: 66 additions & 66 deletions pdm.lock

Large diffs are not rendered by default.

195 changes: 101 additions & 94 deletions prompt-service/pdm.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions prompt-service/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ dependencies = [
"peewee~=3.16",
"nltk~=3.8",
"flask~=3.0",
"llama-index==0.10.28",
"llama-index==0.10.38",
"python-dotenv==1.0.0",
"unstract-sdk~=0.31.1",
"unstract-sdk~=0.32.0",
"unstract-adapters~=0.19.0",
"redis>=5.0.3",
"unstract-core @ file:///${PROJECT_ROOT}/../unstract/core",
]
Expand Down
9 changes: 6 additions & 3 deletions prompt-service/src/unstract/prompt_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ def prompt_processor() -> Any:
f"JSON format error : {answer}", LogLevel.ERROR
)
app.logger.info(
f"Error parsing response (to json): {e}", LogLevel.ERROR
f"Error parsing response (to json): {e}",
LogLevel.ERROR,
)
structured_output[output[PSKeys.NAME]] = {}

Expand Down Expand Up @@ -749,10 +750,12 @@ def _retrieve_context(output, doc_id, vector_index, answer) -> str:
nodes = retriever.retrieve(answer)
text = ""
for node in nodes:
if node.score > 0.6:
# ToDo: May have to fine-tune this value for node score or keep it
# configurable at the adapter level
if node.score > 0:
text += node.get_content() + "\n"
else:
app.logger.info("Node score is less than 0.6. " f"Ignored: {node.score}")
app.logger.info("Node score is less than 0. " f"Ignored: {node.score}")
return text


Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ hook-check-django-migrations = [
"psycopg2-binary==2.9.9",
"python-dotenv==1.0.0",
"python-magic==0.4.27",
"unstract-sdk~=0.31.1",
"unstract-adapters~=0.18.0",
"unstract-sdk~=0.32.0",
"unstract-adapters~=0.19.0",
"-e unstract-connectors @ file:///${PROJECT_ROOT}/unstract/connectors",
"-e unstract-core @ file:///${PROJECT_ROOT}/unstract/core",
"-e unstract-flags @ file:///${PROJECT_ROOT}/unstract/flags",
Expand Down
2 changes: 1 addition & 1 deletion tools/classifier/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Add your dependencies here

# Required for all unstract tools
unstract-sdk~=0.31.1
unstract-sdk~=0.32.0
2 changes: 1 addition & 1 deletion tools/classifier/src/config/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": "0.0.1",
"displayName": "File Classifier",
"functionName": "classify",
"toolVersion": "0.0.20",
"toolVersion": "0.0.21",
"description": "Classifies a file into a bin based on its contents",
"input": {
"description": "File to be classified"
Expand Down
2 changes: 1 addition & 1 deletion tools/structure/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Add your dependencies here

# Required for all unstract tools
unstract-sdk~=0.31.1
unstract-sdk~=0.32.0
2 changes: 1 addition & 1 deletion tools/structure/src/config/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": "0.0.1",
"displayName": "Structure Tool",
"functionName": "structure_tool",
"toolVersion": "0.0.24",
"toolVersion": "0.0.25",
"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"
Expand Down
2 changes: 1 addition & 1 deletion tools/text_extractor/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Add your dependencies here

# Required for all unstract tools
unstract-sdk~=0.31.1
unstract-sdk~=0.32.0
2 changes: 1 addition & 1 deletion tools/text_extractor/src/config/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": "0.0.1",
"displayName": "Text Extractor",
"functionName": "text_extractor",
"toolVersion": "0.0.19",
"toolVersion": "0.0.20",
"description": "The Text Extractor is a powerful tool designed to convert documents to its text form or Extract texts from documents",
"input": {
"description": "Document"
Expand Down
2 changes: 1 addition & 1 deletion unstract/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = [
dependencies = [
"boto3~=1.28.17",
"botocore~=1.31.17",
"llama-index==0.10.28",
"llama-index==0.10.38",
"llama-index-llms-azure-openai==0.1.5",
"redis~=5.0.1",
"requests==2.31.0",
Expand Down
2 changes: 1 addition & 1 deletion unstract/tool-registry/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies = [
"docker~=6.1.3",
"jsonschema~=4.18.2",
"PyYAML~=6.0.1",
"unstract-adapters~=0.18.0",
"unstract-adapters~=0.19.0",
# ! IMPORTANT!
# Local dependencies usually need to be added as:
# https://pdm-project.org/latest/usage/dependency/#local-dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"schemaVersion": "0.0.1",
"displayName": "File Classifier",
"functionName": "classify",
"toolVersion": "0.0.20",
"toolVersion": "0.0.21",
"description": "Classifies a file into a bin based on its contents",
"input": {
"description": "File to be classified"
Expand Down Expand Up @@ -139,17 +139,17 @@
}
},
"icon": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<svg\n enable-background=\"new 0 0 20 20\"\n height=\"48\"\n viewBox=\"0 0 20 20\"\n width=\"48\"\n fill=\"#000000\"\n version=\"1.1\"\n id=\"svg8109\"\n sodipodi:docname=\"folder_copy_black_48dp.svg\"\n xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:svg=\"http://www.w3.org/2000/svg\">\n <defs\n id=\"defs8113\" />\n <sodipodi:namedview\n id=\"namedview8111\"\n pagecolor=\"#ffffff\"\n bordercolor=\"#000000\"\n borderopacity=\"0.25\"\n inkscape:showpageshadow=\"2\"\n inkscape:pageopacity=\"0.0\"\n inkscape:pagecheckerboard=\"0\"\n inkscape:deskcolor=\"#d1d1d1\"\n showgrid=\"false\" />\n <g\n id=\"g8099\">\n <rect\n fill=\"none\"\n height=\"20\"\n width=\"20\"\n x=\"0\"\n id=\"rect8097\"\n y=\"0\" />\n </g>\n <g\n id=\"g8107\"\n style=\"fill:#ff4d6d;fill-opacity:1\">\n <g\n id=\"g8105\"\n style=\"fill:#ff4d6d;fill-opacity:1\">\n <path\n d=\"M 2.5,5 H 1 V 15.5 C 1,16.33 1.67,17 2.5,17 H 15.68 V 15.5 H 2.5 Z\"\n id=\"path8101\"\n style=\"fill:#ff4d6d;fill-opacity:1\" />\n <path\n d=\"M 16.5,4 H 11 L 9,2 H 5.5 C 4.67,2 4,2.67 4,3.5 v 9 C 4,13.33 4.67,14 5.5,14 h 11 c 0.83,0 1.5,-0.67 1.5,-1.5 v -7 C 18,4.67 17.33,4 16.5,4 Z m 0,8.5 h -11 v -9 h 2.88 l 2,2 h 6.12 z\"\n id=\"path8103\"\n style=\"fill:#ff4d6d;fill-opacity:1\" />\n </g>\n </g>\n</svg>\n",
"image_url": "docker:unstract/tool-classifier:0.0.20",
"image_url": "docker:unstract/tool-classifier:0.0.21",
"image_name": "unstract/tool-classifier",
"image_tag": "0.0.20"
"image_tag": "0.0.21"
},
"text_extractor": {
"tool_uid": "text_extractor",
"properties": {
"schemaVersion": "0.0.1",
"displayName": "Text Extractor",
"functionName": "text_extractor",
"toolVersion": "0.0.19",
"toolVersion": "0.0.20",
"description": "The Text Extractor is a powerful tool designed to convert documents to its text form or Extract texts from documents",
"input": {
"description": "Document"
Expand Down Expand Up @@ -224,8 +224,8 @@
}
},
"icon": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<svg\n enable-background=\"new 0 0 20 20\"\n height=\"48\"\n viewBox=\"0 0 20 20\"\n width=\"48\"\n fill=\"#000000\"\n version=\"1.1\"\n id=\"svg8109\"\n sodipodi:docname=\"folder_copy_black_48dp.svg\"\n xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:svg=\"http://www.w3.org/2000/svg\">\n <defs\n id=\"defs8113\" />\n <sodipodi:namedview\n id=\"namedview8111\"\n pagecolor=\"#ffffff\"\n bordercolor=\"#000000\"\n borderopacity=\"0.25\"\n inkscape:showpageshadow=\"2\"\n inkscape:pageopacity=\"0.0\"\n inkscape:pagecheckerboard=\"0\"\n inkscape:deskcolor=\"#d1d1d1\"\n showgrid=\"false\" />\n <g\n id=\"g8099\">\n <rect\n fill=\"none\"\n height=\"20\"\n width=\"20\"\n x=\"0\"\n id=\"rect8097\"\n y=\"0\" />\n </g>\n <g\n id=\"g8107\"\n style=\"fill:#ff4d6d;fill-opacity:1\">\n <g\n id=\"g8105\"\n style=\"fill:#ff4d6d;fill-opacity:1\">\n <path\n d=\"M 2.5,5 H 1 V 15.5 C 1,16.33 1.67,17 2.5,17 H 15.68 V 15.5 H 2.5 Z\"\n id=\"path8101\"\n style=\"fill:#ff4d6d;fill-opacity:1\" />\n <path\n d=\"M 16.5,4 H 11 L 9,2 H 5.5 C 4.67,2 4,2.67 4,3.5 v 9 C 4,13.33 4.67,14 5.5,14 h 11 c 0.83,0 1.5,-0.67 1.5,-1.5 v -7 C 18,4.67 17.33,4 16.5,4 Z m 0,8.5 h -11 v -9 h 2.88 l 2,2 h 6.12 z\"\n id=\"path8103\"\n style=\"fill:#ff4d6d;fill-opacity:1\" />\n </g>\n </g>\n</svg>\n",
"image_url": "docker:unstract/tool-text-extractor:0.0.19",
"image_url": "docker:unstract/tool-text-extractor:0.0.20",
"image_name": "unstract/tool-text-extractor",
"image_tag": "0.0.19"
"image_tag": "0.0.20"
}
}

0 comments on commit 883ff9c

Please sign in to comment.