Creazione e gestione dei processori

Prima di poter inviare i documenti da elaborare, devi prima creare la tua istanza di un processore. Questa pagina fornisce informazioni dettagliate sulla creazione e sulla gestione dei processori.

Processori disponibili

Per creare un'istanza del processore utilizzando l'API, devi conoscere il nome di ogni tipo di processore. Recupera questo elenco in modo dinamico (con il codice riportato di seguito), perché il tuo accesso potrebbe cambiare.

I tipi di processore disponibili pubblicamente sono:

Digitalizzare i processori

  • OCR_PROCESSOR
  • FORM_PARSER_PROCESSOR
  • LAYOUT_PARSER_PROCESSOR

Processori preaddestrati

  • BANK_STATEMENT_PROCESSOR
  • EXPENSE_PROCESSOR
  • FORM_W2_PROCESSOR
  • ID_PROOFING_PROCESSOR
  • INVOICE_PROCESSOR
  • PAYSTUB_PROCESSOR
  • US_DRIVER_LICENSE_PROCESSOR
  • US_PASSPORT_PROCESSOR
  • UTILITY_PROCESSOR

Processori di estrazione / classificazione / suddivisione

  • CUSTOM_EXTRACTION_PROCESSOR
  • CUSTOM_CLASSIFICATION_PROCESSOR
  • CUSTOM_SPLITTING_PROCESSOR
  • SUMMARIZER_PROCESSOR

Elenco dei tipi di processore

UI web

  1. Nella Google Cloud console, nella sezione Document AI, vai alla pagina Galleria processori.

    Vai alla galleria dei processori

  2. Visualizza o cerca l'elenco dei tipi di processore.

REST

Questo esempio mostra come elencare i tipi di processore disponibili per il tuo progetto utilizzando il metodo fetchProcessorTypes.

Prima di utilizzare i dati della richiesta, apporta le sostituzioni seguenti:

  • LOCATION: la posizione del tuo processore, ad esempio:
    • us - Stati Uniti
    • eu - Unione Europea
  • PROJECT_ID: l'ID progetto Google Cloud .

Metodo HTTP e URL:

GET https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION:fetchProcessorTypes

Per inviare la richiesta, scegli una di queste opzioni:

curl

Esegui questo comando:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION:fetchProcessorTypes"

PowerShell

Esegui questo comando:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION:fetchProcessorTypes" | Select-Object -Expand Content

La risposta è un elenco di ProcessorType che mostra i tipi di processore disponibili, insieme alla categoria e alle località disponibili.

{
  "processorTypes": [
  [
    ...
    {
      "name": "projects/PROJECT_ID/locations/LOCATION/processorTypes/FORM_PARSER_PROCESSOR",
      "type": "FORM_PARSER_PROCESSOR",
      "category": "GENERAL",
      "availableLocations": [
        {
          "locationId": "eu"
        },
        {
          "locationId": "us"
        }
      ],
      "allowCreation": true,
      "launchStage": "GA"
    },
    {
      "name": "projects/PROJECT_ID/locations/LOCATION/processorTypes/OCR_PROCESSOR",
      "type": "OCR_PROCESSOR",
      "category": "GENERAL",
      "availableLocations": [
        {
          "locationId": "eu"
        },
        {
          "locationId": "us"
        }
      ],
      "allowCreation": true,
      "launchStage": "GA"
    },
    {
      "name": "projects/PROJECT_ID/locations/LOCATION/processorTypes/INVOICE_PROCESSOR",
      "type": "INVOICE_PROCESSOR",
      "category": "SPECIALIZED",
      "availableLocations": [
        {
          "locationId": "eu"
        },
        {
          "locationId": "us"
        }
      ],
      "allowCreation": true,
      "launchStage": "GA"
    },
    {
      "name": "projects/PROJECT_ID/locations/LOCATION/processorTypes/US_DRIVER_LICENSE_PROCESSOR",
      "type": "US_DRIVER_LICENSE_PROCESSOR",
      "category": "SPECIALIZED",
      "availableLocations": [
        {
          "locationId": "us"
        },
        {
          "locationId": "eu"
        }
      ],
      "allowCreation": true,
      "launchStage": "GA"
    },
    ...
  ]
}

Python

Per saperne di più, consulta la documentazione di riferimento dell'API Document AI Python.

Per eseguire l'autenticazione in Document AI, configura le Credenziali predefinite dell'applicazione. Per saperne di più, consulta Configura l'autenticazione per un ambiente di sviluppo locale.


from google.api_core.client_options import ClientOptions
from google.cloud import documentai  # type: ignore

# TODO(developer): Uncomment these variables before running the sample.
# project_id = 'YOUR_PROJECT_ID'
# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu'


def fetch_processor_types_sample(project_id: str, location: str) -> None:
    # You must set the api_endpoint if you use a location other than 'us'.
    opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com")

    client = documentai.DocumentProcessorServiceClient(client_options=opts)

    # The full resource name of the location
    # e.g.: projects/project_id/locations/location
    parent = client.common_location_path(project_id, location)

    # Fetch all processor types
    response = client.fetch_processor_types(parent=parent)

    print("Processor types:")
    # Print the available processor types
    for processor_type in response.processor_types:
        if processor_type.allow_creation:
            print(processor_type.type_)

Go

Per saperne di più, consulta la documentazione di riferimento dell'API Document AI Go.

Per eseguire l'autenticazione in Document AI, configura le Credenziali predefinite dell'applicazione. Per saperne di più, consulta Configura l'autenticazione per un ambiente di sviluppo locale.


//go:build examples

package main

import (
	"context"

	documentai "cloud.google.com/go/documentai/apiv1"
	documentaipb "cloud.google.com/go/documentai/apiv1/documentaipb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := documentai.NewDocumentProcessorClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &documentaipb.FetchProcessorTypesRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/documentai/apiv1/documentaipb#FetchProcessorTypesRequest.
	}
	resp, err := c.FetchProcessorTypes(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_