Skip to content

Latest commit

 

History

History

structure

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Structure Tool

This is a helper tool that needs to be used along with Prompt Studio. It helps process input files based on the prompts that have been designed and exported as a tool from Prompt Studio.

Required environment variables

Variable Description
PLATFORM_SERVICE_HOST The host in which the platform service is running
PLATFORM_SERVICE_PORT The port in which the service is listening
PLATFORM_SERVICE_API_KEY The API key for the platform
EXECUTION_DATA_DIR The directory in the filesystem which has contents for tool execution
PROMPT_HOST The host in which the prompt service is running
PROMPT_PORT The port in which the prompt service is listening
PROMPT_PORT The port in which the prompt service is listening
X2TEXT_HOST The host where the x2text service is running
X2TEXT_PORT The port where the x2text service is listening

Testing the tool locally

Setting up a dev environment

Setup a virtual environment and activate it

python -m venv .venv
source .venv/bin/activate

Install the dependencies for the tool

pip install -r requirements.txt

To use the local development version of the unstract-sdk install it from the local repository. Replace the path with the path to your local repository

pip install -e ~/path_to_repo/sdks/.

Tool execution preparation

Load the environment variables for the tool. Make a copy of the sample.env file and name it .env. Fill in the required values. They get loaded with python-dotenv through the SDK.

Update the tool's data_dir marked by the EXECUTION_DATA_DIR env. This has to be done before each tool execution since the tool updates the INFILE and METADATA.json.

Run SPEC command

Represents the JSON schema for the runtime configurable settings of a tool

python main.py --command SPEC

Run PROPERTIES command

Describes some metadata for the tool such as its version, description, inputs and outputs

python main.py --command PROPERTIES

Run ICON command

Returns the SVG icon for the tool, used by Unstract's frontend

python main.py --command ICON

Run VARIABLES command

Represents the runtime variables or envs that will be used by the tool

python main.py --command VARIABLES

Run RUN command

The schema of the JSON required for settings can be found by running the SPEC command. Alternatively if you have access to the code base, it is located in the config folder as spec.json.

python main.py \
    --command RUN \
    --settings '{
        "prompt_registry_id": "<ID_from_the_DB>"
    }' \
    --log-level DEBUG

Testing the tool from its docker image

Build the tool docker image from the folder containing the Dockerfile with

docker build -t unstract/tool-structure:0.0.1 .

Make sure the directory pointed by EXECUTION_DATA_DIR has the required information for the tool to run and necessary services like the platform-service is up. To test the tool from its docker image, run the following command

docker run -it \
    --network unstract-network \
    --env-file .env \
    -v "$(pwd)"/data_dir:/app/data_dir \
    unstract/tool-structure:0.0.1 \
    --command RUN \
    --settings '{
        "prompt_registry_id": "<ID_from_the_DB>"
    }' \
    --log-level DEBUG