Document

The Document component is an operator component that allows users to manipulate Document files. It can carry out the following tasks:

Release Stage

Alpha

Configuration

The component definition and tasks are defined in the definition.yaml and tasks.yaml files respectively.

Supported Tasks

Convert to Markdown

Convert document to text in Markdown format.

InputField IDTypeDescription
Task ID (required)taskstringTASK_CONVERT_TO_MARKDOWN
Document (required)documentstringBase64 encoded PDF/DOCX/DOC/PPTX/PPT/HTML/XLSX/XLS/CSV to be converted to text in Markdown format.
FilenamefilenamestringThe name of the file, please remember to add the file extension in the end of file name. e.g. 'example.pdf'.
Display Image Tagdisplay-image-tagbooleanWhether to display image tag in the markdown text. Default is 'false'. It is only applicable for convert-2024-08-28 converter. And, it is only applicable for the type of PPTX/PPT/DOCX/DOC/PDF.
Display All Page Imagedisplay-all-page-imagebooleanWhether to respond the whole page as the images if we detect there could be images in the page. It will only support DOCX/DOC/PPTX/PPT/PDF.
ResolutionresolutionnumberDesired number pixels per inch. Defaults to 300. Minimum is 72.
ConverterconverterstringThe conversion engine used in the transformation. For now, it only applies to PDF to Markdown conversions. pdfplumber is quicker than Docling, but it typically produces less accurate results.
Enum values
  • pdfplumber
  • docling
OutputField IDTypeDescription
BodybodystringMarkdown text converted from the PDF document.
Filename (optional)filenamestringThe name of the file.
Images (optional)imagesarray[string]Images extracted from the document.
Error (optional)errorstringError message if any during the conversion process.
All Page Images (optional)all-page-imagesarray[string]The image contains all the pages in the document if we detect there could be images in the page. It will only support DOCX/DOC/PPTX/PPT/PDF.
Markdowns (optional)markdownsarray[string]Markdown text converted from the PDF document, separated by page.

Convert to Text

Convert document to text.

InputField IDTypeDescription
Task ID (required)taskstringTASK_CONVERT_TO_TEXT
Document (required)documentstringBase64 encoded PDF/DOC/DOCX/XML/HTML/RTF/MD/PPTX/ODT/TIF/CSV/TXT/PNG document to be converted to plain text.
FilenamefilenamestringThe name of the file, please remember to add the file extension in the end of file name. e.g. 'example.pdf'.
OutputField IDTypeDescription
BodybodystringPlain text converted from the document.
Filename (optional)filenamestringThe name of the file.
MetametajsonMetadata extracted from the document.
MillisecondsmsecsnumberTime taken to convert the document.
ErrorerrorstringError message if any during the conversion process.

Convert to Images

Convert Document to images.

InputField IDTypeDescription
Task ID (required)taskstringTASK_CONVERT_TO_IMAGES
PDF (required)documentstringBase64 encoded PDF/DOCX/DOC/PPT/PPTX to be converted to images.
FilenamefilenamestringThe name of the file, please remember to add the file extension in the end of file name. e.g. 'example.pdf'.
ResolutionresolutionnumberDesired number pixels per inch. Defaults to 300. Minimum is 72.
OutputField IDTypeDescription
Imagesimagesarray[string]Images converted from the document.
Filenames (optional)filenamesarray[string]The filenames of the images. The filenames will be appended with the page number. e.g. 'example-1.jpg'.

Split in Pages

Divide a document in batches of N pages.

InputField IDTypeDescription
Task ID (required)taskstringTASK_SPLIT_IN_PAGES
Document (required)documentstringDocument encoded in Base64. For now, only PDF documents are accepted.
Batch Sizebatch-sizenumberPages in each batch.
OutputField IDTypeDescription
Batches (optional)pagesarray[string]An ordered list of Base64-encoded documents, each one containing N pages of the input document. Page order in the input document is preserved both in the batch array elements and in the pages within each batch.

Example Recipes

version: v1beta
component:
  gpt-4-question:
    type: openai
    task: TASK_TEXT_GENERATION
    input:
      model: gpt-4o
      prompt: |-
        Given the contract content:
        --
        ${pdf-to-text.output.body}
        --
        Please help answer the question: ${variable.question}
      response-format:
        type: text
      system-message: You are a professional and versatile lawyer with diverse lay backgrounds who reviews, investigates and spot pitfalls in a contract.
      top-p: 1
    setup:
      api-key: ${secret.INSTILL_SECRET}
      organization: org-iadti51GxgS0qjX6LJmn75Ti
  gpt-4-summary:
    type: openai
    task: TASK_TEXT_GENERATION
    input:
      model: gpt-4o
      prompt: |-
        Please help check this contract content and tell me what kind of the contract it is about in one concise, short, and simple sentence such as "it is an NDA", "it is an job agency contract", etc.:
        ${pdf-to-text.output.body}
      response-format:
        type: text
      system-message: You are a professional and versatile lawyer with diverse lay backgrounds who reviews, investigates and spot pitfalls in a contract.
      top-p: 1
    setup:
      api-key: ${secret.INSTILL_SECRET}
      organization: org-iadti51GxgS0qjX6LJmn75Ti
  pdf-to-text:
    type: document
    task: TASK_CONVERT_TO_TEXT
    input:
      document: ${variable.contract_pdf_file}
variable:
  contract_pdf_file:
    title: Contract PDF file
    type: document
  question:
    title: Question
    type: string

output:
  contract_question_answering:
    title: Contract Question Answering
    value: ${gpt-4-question.output.texts}
    instill-ui-order: 1
  contract_summary:
    title: Contract Summary
    value: ${gpt-4-summary.output.texts}