RPA.DocumentAI

Retrieve the result data previously obtained with Predict.

Arguments

ArgumentTypeDefault value
extendedboolFalse

The stored raw result is usually pre-processed with a library specific keyword prior the return.

param extended:Get all the details inside the result data. (main fields only by default)
returns:Usually a list of fields detected in the document.

Example: Robot Framework

*** Tasks *** Scan With Base64 Document AI Base64 ${data} = Get Result Log List ${data}

Example: Python

result = lib_docai.get_result() for field in result: print(field)

Initialize the engine you want to scan documents with.

Arguments

ArgumentTypeDefault value
nameEngineName, strnull
secretstr, Path, Tuple, List, Dict, NoneNone
vaultDict, str, NoneNone
kwargsnull

This is required before being able to run Predict. Once initialized, you don't need to run this again, simply use Switch Engine to jump between the engines. The final secret value (passed directly with secret or picked up automatically from the Vault with vault) will be split into authorization args and kwargs or just passed as it is to the wrapped library. Keep in mind that some engines are expecting API keys where others tokens or private keys. Any optional keyword argument will be passed further in the wrapped library.

param name:Name of the engine.
param secret:Authenticate with a string/file/object secret directly.
param vault:Specify the Vault storage name and secret key in order to authenticate. ('name:key' or {name: key} formats are supported)

How secret resolution works

When vault is passed in, the corresponding Vault is retrieved and the value belonging to specified field is returned as a secret. If a secret is used, then this value is returned as it is if this isn't a path pointing to the file holding the value to be returned. We'll be relying on environment variables in the absence of both the secret and vault.

Expected secret value formats:

  • google: <json-service/token> (RPA.Cloud.Google.Init Document AI)
  • base64ai: <e-mail>,<api-key> (RPA.DocumentAI.Base64AI.Set Authorization)
  • nanonets: <api-key> (RPA.DocumentAI.Nanonets.Set Authorization)

Example: Robot Framework

*** Keywords *** Init Base64 Init Engine base64ai vault=document_ai:base64ai

Example: Python

from RPA.DocumentAI import DocumentAI from RPA.Robocorp.Vault import Vault lib_docai = DocumentAI() mail_apikey = Vault().get_secret("document_ai")["base64ai"] lib_docai.init_engine("base64ai", secret=mail_apikey)

Scan a document with the currently active engine and store the result internally for a later retrieval.

Arguments

ArgumentTypeDefault value
locationPath, strnull
modelList[str], str, NoneNone
kwargsnull

Based on the selected engine, this wraps a chain of libraries until calling a service API in the end, where the passed file is analyzed. Any optional keyword argument will be passed further in the wrapped library. (some engines require mandatory parameters like project ID or region)

param location:Path to a local file or URL address of a remote one. (not all engines work with URLs)
param model:Model name(s) to scan with. (some engines guess the model if not specified)

Example: Robot Framework

*** Tasks *** Document AI Base64 [Setup] Init Base64 Predict https://site.com/path/to/invoice.png

Example: Python

lib_docai.predict("local/path/to/invoice.png", model="finance/invoice")

Switch between already initialized engines.

Arguments

ArgumentTypeDefault value
nameEngineName, strnull

Use this to jump between engines when scanning with multiple of them.

param name:Name of the engine to be set as active. (choose between: google, base64ai, nanonets)

Example: Robot Framework

*** Tasks *** Document AI All @{engines} = Create List base64ai nanonets FOR ${engine} IN @{engines} Switch Engine ${engine} Log Scanning with engine: ${engine}... Predict invoice.png ${data} = Get Result Log List ${data} END

Example: Python

lib_docai.switch_engine("base64ai") lib_docai.predict("invoice.png")