Membuat dan mengelola pemroses

Sebelum dapat mengirim dokumen untuk diproses, Anda harus membuat instance pemroses terlebih dahulu. Halaman ini memberikan detail tentang cara membuat dan mengelola pemroses.

Prosesor yang tersedia

Untuk membuat instance pemroses menggunakan API, Anda perlu mengetahui nama untuk setiap jenis pemroses. Dapatkan daftar ini secara dinamis (dengan kode di bawah), karena akses Anda dapat berubah.

Jenis pemroses yang tersedia secara publik adalah:

Prosesor digital

  • OCR_PROCESSOR
  • FORM_PARSER_PROCESSOR
  • LAYOUT_PARSER_PROCESSOR

Pemroses terlatih

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

Pemroses ekstraksi / klasifikasi / pemisahan

  • CUSTOM_EXTRACTION_PROCESSOR
  • CUSTOM_CLASSIFICATION_PROCESSOR
  • CUSTOM_SPLITTING_PROCESSOR
  • SUMMARIZER_PROCESSOR

Membuat daftar jenis pemroses

UI Web

  1. Di konsol Google Cloud , di bagian Document AI, buka halaman Processor Gallery.

    Buka Galeri Pemroses

  2. Lihat atau telusuri daftar jenis prosesor.

REST

Contoh ini menunjukkan cara mencantumkan jenis prosesor yang tersedia untuk project Anda menggunakan metode fetchProcessorTypes.

Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

  • LOCATION: lokasi prosesor Anda, misalnya:
    • us - Amerika Serikat
    • eu - Uni Eropa
  • PROJECT_ID: Project ID Google Cloud Anda.

Metode HTTP dan URL:

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

Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

curl

Jalankan perintah berikut:

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

PowerShell

Jalankan perintah berikut:

$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

Responsnya adalah daftar ProcessorType yang menampilkan jenis prosesor yang tersedia, beserta kategori dan lokasi yang tersedia.

{
  "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

Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi API Python Document AI.

Untuk melakukan autentikasi ke Document AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


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

Untuk mengetahui informasi selengkapnya, lihat