File Uploads

TreeScale App can handle various file type uploads where we extract file content and feed that text into your prompt template for the API Endpoint as a variable type.

We are storing uploaded files per TreeScale Application, which means the uploaded files are going to be available for all API Endpoints within the same TreeScale Application. It is possible to reference files using file ID, which is returned in the API Response for each file upload. But it is also possible to send a file content directly using base64 encoded string in JSON payload, during the API Request.

File Types and Limitations

TreeScale App will handle only text-based files, which limits the scope to the file types below.

  • Name
    PDF
    Type
    Description

    Only text-based PDF files

  • Name
    Docx
    Type
    Description

    Images and visual effects will be ignored for now

  • Name
    Doc
    Type
    Description

    Same as Docx format

  • Name
    XML
    Type
    Description

    We will keep the XML Tag structure, which would be the raw format for your prompt

  • Name
    RTF
    Type
    Description

    Same as Docx format

Each file upload is being processed in parallel, so if you have multiple users using the same API Endpoint, we will ensure no response delay based on the API Request Load.

Right now, we are limiting file upload sizes to the Maximum of 10MB per file upload, which in most cases, is quite big text-based files and should be enough for essential inputs on your Prompt templates for LLMs

File Upload and Prompt Template Usage

File upload request is made using multipart/form-data content type, which means you can use any HTTP Client to upload files to TreeScale App. We will use curl for this example.

File Upload Request Body

curl https://tree.tsapp.dev/api/files \
  --header 'Authorization: Bearer pk_b75cb4fcf8a7258e45f35f5a639e869444c5a2b19b582e418f33a8c0ee1b372c' \
  --form 'files=@"./test.pdf"'

# Response
[
    {
      "id": "5f9b3b3c-0b7c-4b9e-8b0a-5f9b3b3c0b7c",
      "name": "test.pdf",
      "size": 123456,
      "type": "application/pdf",
    }
]

The upload request will return an array of files, which is the same as the request payload, but with additional file metadata. Later on when you need to reference a file, you can use the id property from the response.

File Upload Request Body

curl -X POST 'https://tree.tsapp.dev/prompt-with-file' \
  --header 'Authorization: Bearer pk_b75cb4fcf8a7258e45f35f5a639e869444c5a2b19b582e418f33a8c0ee1b372c' \
  --header 'Content-Type: application/json' \
  --data '{
    "variables": {
        "file_content": {
            "file": "5f9b3b3c-0b7c-4b9e-8b0a-5f9b3b3c0b7c"
        }
    }
}'

# Response
{
  "result": "The population of the country mentioned in the given context text is 123456"
}

This example shows that for the country variable, we are using the file ID from the previous request. The file content will be extracted and used as a variable value for the country variable.

Write the description about the following PDF file with the content below:
{file_content}

Here we have a prompt template with file_content variable, which should be given by uploading a file as a text value.