プロセッサ バージョンの管理

新しいバージョンがリリースされる理由はさまざまです。たとえば、精度を高めたり、可用性を高めたり、選択マークなどの新しいドキュメント要素をサポートしたりするためです。

Document AI は生成 AI を活用しているため、今後のバージョンでは新しい基盤モデルが使用され、生成 AI の強化を利用できるようになります。

基盤モデルの改善に伴い、以前の基盤モデルは非推奨になりました。同様に、プロセッサ バージョンは、新しいバージョンがリリースされてから 6 か月後に非推奨になります。

プロセッサには、次のいずれかのバージョンがあります。

このページでは、プロセッサにバージョンが付けられる仕組みと、特定のバージョンを表示して選択する方法について説明します。

managing-processor-versions-1

プロセッサ バージョンの概要

プロセッサ バージョンには次の 2 つのカテゴリがあります。

  • Google バージョンは、安定版(本番環境のユースケース向け)またはリリース候補版(最新機能を備えた試験運用版)です。
  • ユーザー バージョンは、ドキュメントの予測をカスタマイズするために作成され、英数字のバージョン ID が付いています。

Google のバージョン

各 Google バージョンは、バージョン IDpretrained-TYPE-vX.X-YYYY-MM-DD など)で識別されます。Google が提供する各プロセッサ バージョンの名前は、Google Stable または Google Release Candidate(RC)です。

Google の安定版

安定版は本番環境に対応した品質で、すぐに利用できます。

  • Google はプロセッサの動作の安定性を優先しますが、重要な修正が提供されることがあります。
  • 以前の Google 安定版は、次の図に示すように、最新の安定版がリリースされてから 6 か月後に非推奨になります。

managing-processor-versions-2

Google リリース候補版(RC)

リリース候補版は試験運用の段階であり、定期的にアップグレードされて最新の機能が提供されます。これらは本番環境に対応したバージョンではなく、安定性は変動する場合があります。

カスタマイズ バージョン

カスタマイズされたバージョンは、ドキュメントに基づいて作成して予測をカスタマイズできるプロセッサ バージョンです。カスタマイズされたバージョンには Type があり、予測に使用されるモデルの種類を示します。基盤モデルを使用してバージョンを作成する(バージョンの作成またはファインチューニング)場合、タイプは 生成 AI です。小さいカスタムモデル(モデルベースまたはテンプレートベース)をトレーニングしてプロセッサ バージョンを作成する場合は、タイプは カスタムです。プロセッサ バージョンを作成する場合は、名前と ID を決定します。

基本バージョン

プロセッサ バージョンを作成した場合、[ベース バージョン] には、カスタマイズされたユーザー バージョンを動かす Google バージョンが表示されます。ベースバージョンによって、ユーザー バージョンのライフサイクルが決まります。カスタマイズしたユーザー バージョンのライフサイクルをどのように管理するかを決定する必要があります。

利用可能な安定版プロセッサ バージョン

カスタム エクストラクタ リリース日 サポート終了日
pretrained-foundation-model-v1.3-2024-08-31 2024 年 5 月 28 日 該当なし
pretrained-foundation-model-v1.2-2024-05-10 2024 年 5 月 28 日 該当なし
pretrained-foundation-model-v1.0-2023-08-22 2024 年 1 月 9 日 2025 年 4 月 9 日
銀行の明細書 リリース日 サポート終了日
pretrained-bankstatement-v3.0-2022-05-16 2022 年 5 月 16 日 該当なし
pretrained-bankstatement-v2.0-2021-12-10 2021 年 12 月 10 日 該当なし
pretrained-bankstatement-v1.1-2021-08-13 2021 年 8 月 13 日 該当なし
pretrained-bankstatement-v1.0-2021-08-08 2021 年 8 月 8 日 該当なし
費用 リリース日 サポート終了日
pretrained-expense-v1.3-2022-07-15 2022 年 7 月 15 日 2025 年 4 月 30 日をもって、米国(US)と欧州連合(EU)でサポートを終了します。
pretrained-expense-v1.2-2022-02-18 2022 年 2 月 18 日 2025 年 4 月 30 日をもって、米国(US)と欧州連合(EU)でサポートを終了します。
pretrained-expense-v1.1-2021-04-09 2021 年 4 月 9 日 該当なし
身元確認 リリース日 サポート終了日
pretrained-id-proofing-v1.0-2022-10-03 2022 年 10 月 3 日 該当なし
請求書 リリース日 サポート終了日
pretrained-invoice-v1.3-2022-07-15 2022 年 7 月 15 日 該当なし
pretrained-invoice-v1.2-2022-02-18 2022 年 2 月 18 日 該当なし
pretrained-invoice-v1.1-2021-04-09 2021 年 4 月 9 日 該当なし
米国の運転免許証 リリース日 サポート終了日
pretrained-us-driver-license-v1.0-2021-06-14 2021 年 6 月 14 日 該当なし
米国のパスポートを提出する リリース日 サポート終了日
pretrained-us-passport-v1.0-2021-06-14 2021 年 6 月 14 日 該当なし
給与明細 リリース日 サポート終了日
pretrained-paystub-v2.0-2022-07-22 2022 年 7 月 22 日 該当なし
pretrained-paystub-v1.2-2021-12-10 2021 年 12 月 10 日 該当なし
pretrained-paystub-v1.1-2021-08-13 2021 年 8 月 13 日 該当なし
pretrained-paystub-v1.0-2021-03-19 2021 年 3 月 19 日 該当なし
W2 リリース日 サポート終了日
pretrained-w2-v2.1-2022-06-08 2022 年 6 月 8 日 該当なし
pretrained-w2-v1.2-2022-01-28 2022 年 1 月 28 日 該当なし
pretrained-w2-v1.1-2022-01-27 2022 年 1 月 27 日 2024 年 3 月 31 日
pretrained-w2-v1.0-2020-10-01 2020 年 10 月 1 日 2024 年 3 月 31 日

managing-processor-versions-3

プロセッサ バージョンのライフサイクル

新しい Google バージョンが利用可能になり次第、新しいベースバージョンを使用して新しいユーザー バージョンを作成して評価する必要があります。次に、新しいバージョンをデプロイし、以前の安定版をベースとして使用している以前のユーザー バージョンをデプロイ解除(または削除)します。安定版は、新しいバージョンがリリースされると廃止されます。このような場合、Google は少なくとも 6 か月前に通知します。

ベース バージョンが非推奨になった場合、どうなりますか?

以前のベース バージョンに依存するユーザー バージョンは、ベース バージョンが非推奨になると予測を返さなくなります。

リクエストのプロセッサ バージョンはどのように選択されますか?

プロセッサ バージョンを指定しないでプロセッサ エンドポイントを呼び出すと、デフォルトのプロセッサ バージョンが使用されます。デフォルトのプロセッサ バージョンが変更された場合は、コードを更新しなければならない場合があります。

使用されるエンドポイント 経験
プロセッサ バージョン ID を指定しない場合 新しいデフォルトのプロセッサ バージョンを使用して処理されたリクエスト。
デフォルトのプロセッサ バージョンが非推奨になった場合、古いデフォルト バージョンが非推奨になると、デフォルトは最新の安定版 Google バージョンに更新されます。
プロセッサ バージョン ID を指定する プロセッサ エンドポイントを呼び出して、非推奨のバージョン ID を指定すると、レスポンスは失敗します。

カスタマイズされたバージョンのサポート終了例

カスタマイズされたバージョンの非推奨化におけるイベントの順序を示す次のシナリオについて考えてみましょう。

  1. デベロッパーは、カスタム エクストラクタを使用してドキュメントからデータを取得しています。処理するドキュメントの複雑さと量を考慮して、基盤モデルを微調整して fine-tune-A という名前のバージョンを作成します。fine-tune-A バージョンをプロセッサのデフォルト バージョンとして設定し、ドキュメントの処理に使用します。fine-tune-A モデルを支えるベース バージョンは、pretrained-foundation-model-v1.0-2023-08-22 (v1.0) 安定版です。

  2. Google は pretrained-foundation-model-v1.2-2024-05-10 (v1.2) という新しい安定版を公開し、v1.0 安定版は 2025 年 4 月 9 日に非推奨になることを発表しました。

  3. トレーニング ドキュメントとテストドキュメントはプロセッサのデータセットに残しておいたので、最新の Google 安定版 v1.2 に基づいて別のバージョンをファインチューニングし、fine-tune-B という名前を付けます。パフォーマンスを評価したら、fine-tune-B バージョンをプロセッサの新しいデフォルト バージョンとして設定し、fine-tune-A バージョンを廃止します。新しいバージョンでは、サポートされている最新の Google 安定版が使用されます。

一方、カスタマイズされた fine-tune-B バージョンを作成して評価していなかった場合、Google は 2025 年 4 月 9 日にプロセッサのデフォルト バージョンを v1.2 に更新していました。プロセッサのエンドポイントを呼び出し、プロセッサのバージョンを指定しないため、新しい v1.2 バージョンが新しいデフォルトとしてリクエストの処理に使用されます。

サポート終了と移行に関するリソース

非推奨のパラッサとプロセッサについては、Document AI の非推奨をご覧ください。

移行については、次のリソースをご覧ください。

プロセッサ バージョンの選択

オンライン処理とバッチ処理に使用するプロセッサ バージョンを指定するには、次の 3 つの方法があります。

  • バージョンを指定しない場合、プロセッサのデフォルトが使用されます。

    • 例: projects/my-proj/locations/us/processors/my-processor:process
  • バージョンを指定すると、そのバージョンが使用されます。特定のバージョンが存在しない場合、リクエストはエラーで失敗します。

    • 例: projects/my-proj/locations/us/processors/my-processor/processorVersions/pretrained-invoice-v1.2-2022-02-18:process
  • チャンネルを指定すると、そのチャンネルの最新バージョンが使用されます。(オプション: stablerc

    • 例: projects/my-proj/locations/us/processors/my-processor/processorVersions/stable:process

利用可能なバージョンを表示

Console

  1. Google Cloud コンソールの Document AI セクションで、[プロセッサ] ページに移動します。

    [プロセッサ] に移動

  2. プロセッサのリストで、詳細を表示するプロセッサの名前をクリックします。

  3. [バージョンの管理](または [デプロイと使用])タブを選択すると、使用可能なプロセッサ バージョンがすべて表示されます。

REST

このサンプルは、processorVersions.list メソッドを使用して、プロセッサで使用可能なプロセッサ バージョンを一覧表示する方法を示しています。

リクエストのデータを使用する前に、次のように置き換えます。

  • LOCATION: プロセッサのロケーション(例:
    • us - 米国
    • eu - 欧州連合
  • PROJECT_ID: 実際の Google Cloud プロジェクト ID。
  • PROCESSOR_ID: カスタム プロセッサの ID。

HTTP メソッドと URL:

GET https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

次のコマンドを実行します。

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

PowerShell

次のコマンドを実行します。

$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/processors/PROCESSOR_ID/processorVersions" | Select-Object -Expand Content

レスポンスには ProcessorVersions のリストが含まれます。これには、namestate などの各プロセッサ バージョンに関する情報が含まれます。

{
  "processorVersions": [
    {
      "name": "projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/pretrained-ocr-v1.1-2022-09-12",
      "displayName": "Google Release Candidate",
      "state": "DEPLOYED",
      "createTime": "2022-09-13T23:39:12.156648Z",
      "googleManaged": true
    },
    {
      "name": "projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/pretrained-ocr-v1.0-2020-09-23",
      "displayName": "Google Stable",
      "state": "DEPLOYED",
      "createTime": "2022-09-12T23:35:09.829557Z",
      "googleManaged": true,
      "deprecationInfo": {
        "deprecationTime": "1970-01-01T00:00:00Z"
      }
    }
  ]
}

C#

詳細については、Document AI C# API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

using Google.Api.Gax;
using Google.Cloud.DocumentAI.V1;
using System;

public sealed partial class GeneratedDocumentProcessorServiceClientSnippets
{
    /// <summary>Snippet for ListProcessorVersions</summary>
    /// <remarks>
    /// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void ListProcessorVersionsRequestObject()
    {
        // Create client
        DocumentProcessorServiceClient documentProcessorServiceClient = DocumentProcessorServiceClient.Create();
        // Initialize request argument(s)
        ListProcessorVersionsRequest request = new ListProcessorVersionsRequest
        {
            ParentAsProcessorName = ProcessorName.FromProjectLocationProcessor("[PROJECT]", "[LOCATION]", "[PROCESSOR]"),
        };
        // Make the request
        PagedEnumerable<ListProcessorVersionsResponse, ProcessorVersion> response = documentProcessorServiceClient.ListProcessorVersions(request);

        // Iterate over all response items, lazily performing RPCs as required
        foreach (ProcessorVersion item in response)
        {
            // Do something with each item
            Console.WriteLine(item);
        }

        // Or iterate over pages (of server-defined size), performing one RPC per page
        foreach (ListProcessorVersionsResponse page in response.AsRawResponses())
        {
            // Do something with each page of items
            Console.WriteLine("A page of results:");
            foreach (ProcessorVersion item in page)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
        }

        // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
        int pageSize = 10;
        Page<ProcessorVersion> singlePage = response.ReadPage(pageSize);
        // Do something with the page of items
        Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
        foreach (ProcessorVersion item in singlePage)
        {
            // Do something with each item
            Console.WriteLine(item);
        }
        // Store the pageToken, for when the next page is required.
        string nextPageToken = singlePage.NextPageToken;
    }
}

Go

詳細については、Document AI Go API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


package main

import (
	"context"

	documentai "cloud.google.com/go/documentai/apiv1"
	documentaipb "cloud.google.com/go/documentai/apiv1/documentaipb"
	"google.golang.org/api/iterator"
)

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.ListProcessorVersionsRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/documentai/apiv1/documentaipb#ListProcessorVersionsRequest.
	}
	it := c.ListProcessorVersions(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			// TODO: Handle error.
		}
		// TODO: Use resp.
		_ = resp

		// If you need to access the underlying RPC response,
		// you can do so by casting the `Response` as below.
		// Otherwise, remove this line. Only populated after
		// first call to Next(). Not safe for concurrent access.
		_ = it.Response.(*documentaipb.ListProcessorVersionsResponse)
	}
}

Java

詳細については、Document AI Java API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1.ListProcessorVersionsRequest;
import com.google.cloud.documentai.v1.ProcessorName;
import com.google.cloud.documentai.v1.ProcessorVersion;

public class SyncListProcessorVersions {

  public static void main(String[] args) throws Exception {
    syncListProcessorVersions();
  }

  public static void syncListProcessorVersions() throws Exception {
    // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DocumentProcessorServiceClient documentProcessorServiceClient =
        DocumentProcessorServiceClient.create()) {
      ListProcessorVersionsRequest request =
          ListProcessorVersionsRequest.newBuilder()
              .setParent(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
              .setPageSize(883849137)
              .setPageToken("pageToken873572522")
              .build();
      for (ProcessorVersion element :
          documentProcessorServiceClient.listProcessorVersions(request).iterateAll()) {
        // doThingsWith(element);
      }
    }
  }
}

Python

詳細については、Document AI Python API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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'
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample


def list_processor_versions_sample(
    project_id: str, location: str, processor_id: 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 processor
    # e.g.: projects/project_id/locations/location/processors/processor_id
    parent = client.processor_path(project_id, location, processor_id)

    # Make ListProcessorVersions request
    processor_versions = client.list_processor_versions(parent=parent)

    # Print the processor version information
    for processor_version in processor_versions:
        processor_version_id = client.parse_processor_version_path(
            processor_version.name
        )["processor_version"]

        print(f"Processor Version: {processor_version_id}")
        print(f"Display Name: {processor_version.display_name}")
        print(f"DEPLOYED: {processor_version.state}")
        print("")

Ruby

詳細については、Document AI Ruby API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/document_ai/v1"

##
# Snippet for the list_processor_versions call in the DocumentProcessorService service
#
# 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://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client#list_processor_versions.
#
def list_processor_versions
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::DocumentAI::V1::ListProcessorVersionsRequest.new

  # Call the list_processor_versions method.
  result = client.list_processor_versions request

  # The returned object is of type Gapic::PagedEnumerable. You can iterate
  # over elements, and API calls will be issued to fetch pages as needed.
  result.each do |item|
    # Each element is of type ::Google::Cloud::DocumentAI::V1::ProcessorVersion.
    p item
  end
end

バージョンの詳細を表示する

Console

  1. Google Cloud コンソールの Document AI セクションで、[プロセッサ] ページに移動します。

    [プロセッサ] に移動

  2. プロセッサのリストで、詳細を表示するプロセッサの名前をクリックします。

  3. [バージョンの管理](または [デプロイと使用])タブを選択すると、使用可能なすべてのプロセッサ バージョンとその詳細が表示されます。

REST

このサンプルは、processorVersions.get メソッドを使用してプロセッサのプロセッサ バージョンの詳細を取得する方法を示しています。

リクエストのデータを使用する前に、次のように置き換えます。

  • LOCATION: プロセッサのロケーション(例:
    • us - 米国
    • eu - 欧州連合
  • PROJECT_ID: 実際の Google Cloud プロジェクト ID。
  • PROCESSOR_ID: カスタム プロセッサの ID。
  • PROCESSOR_VERSION: プロセッサのバージョン ID。詳細については、プロセッサ バージョンを選択するをご覧ください。例:
    • pretrained-TYPE-vX.X-YYYY-MM-DD
    • stable
    • rc

HTTP メソッドと URL:

GET https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

次のコマンドを実行します。

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

PowerShell

次のコマンドを実行します。

$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/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION" | Select-Object -Expand Content

レスポンスは ProcessorVersion で、namestate などのプロセッサ バージョンに関する情報が含まれています。

{
  "name": "projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/pretrained-ocr-v1.1-2022-09-12",
  "displayName": "Google Release Candidate",
  "state": "DEPLOYED",
  "createTime": "2022-09-13T23:39:12.156648Z",
  "googleManaged": true
}

C#

詳細については、Document AI C# API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

using Google.Cloud.DocumentAI.V1;

public sealed partial class GeneratedDocumentProcessorServiceClientSnippets
{
    /// <summary>Snippet for GetProcessorVersion</summary>
    /// <remarks>
    /// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void GetProcessorVersionRequestObject()
    {
        // Create client
        DocumentProcessorServiceClient documentProcessorServiceClient = DocumentProcessorServiceClient.Create();
        // Initialize request argument(s)
        GetProcessorVersionRequest request = new GetProcessorVersionRequest
        {
            ProcessorVersionName = ProcessorVersionName.FromProjectLocationProcessorProcessorVersion("[PROJECT]", "[LOCATION]", "[PROCESSOR]", "[PROCESSOR_VERSION]"),
        };
        // Make the request
        ProcessorVersion response = documentProcessorServiceClient.GetProcessorVersion(request);
    }
}

Go

詳細については、Document AI Go API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.GetProcessorVersionRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/documentai/apiv1/documentaipb#GetProcessorVersionRequest.
	}
	resp, err := c.GetProcessorVersion(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

詳細については、Document AI Java API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1.GetProcessorVersionRequest;
import com.google.cloud.documentai.v1.ProcessorVersion;
import com.google.cloud.documentai.v1.ProcessorVersionName;

public class SyncGetProcessorVersion {

  public static void main(String[] args) throws Exception {
    syncGetProcessorVersion();
  }

  public static void syncGetProcessorVersion() throws Exception {
    // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DocumentProcessorServiceClient documentProcessorServiceClient =
        DocumentProcessorServiceClient.create()) {
      GetProcessorVersionRequest request =
          GetProcessorVersionRequest.newBuilder()
              .setName(
                  ProcessorVersionName.of(
                          "[PROJECT]", "[LOCATION]", "[PROCESSOR]", "[PROCESSOR_VERSION]")
                      .toString())
              .build();
      ProcessorVersion response = documentProcessorServiceClient.getProcessorVersion(request);
    }
  }
}

Python

詳細については、Document AI Python API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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'
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample
# processor_version_id = 'YOUR_PROCESSOR_VERSION_ID'


def get_processor_version_sample(
    project_id: str, location: str, processor_id: str, processor_version_id: 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 processor version
    # e.g.: projects/project_id/locations/location/processors/processor_id/processorVersions/processor_version_id
    name = client.processor_version_path(
        project_id, location, processor_id, processor_version_id
    )

    # Make GetProcessorVersion request
    processor_version = client.get_processor_version(name=name)

    # Print the processor version information
    print(f"Processor Version: {processor_version_id}")
    print(f"Display Name: {processor_version.display_name}")
    print(f"DEPLOYED: {processor_version.state}")

Ruby

詳細については、Document AI Ruby API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/document_ai/v1"

##
# Snippet for the get_processor_version call in the DocumentProcessorService service
#
# 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://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client#get_processor_version.
#
def get_processor_version
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::DocumentAI::V1::GetProcessorVersionRequest.new

  # Call the get_processor_version method.
  result = client.get_processor_version request

  # The returned object is of type Google::Cloud::DocumentAI::V1::ProcessorVersion.
  p result
end

デフォルトのバージョンを変更する

プロセッサのデフォルト バージョンは、特定のバージョンを指定しない場合、ドキュメントの処理に使用されるバージョンを指定します。プロセッサを作成すると、初期のデフォルト バージョンは安定版チャンネルの最新バージョンになります。

デフォルトのバージョンを変更すると、受信リクエストは新しく選択されたバージョンを使用して処理されます。プロセッサがリクエストの処理中にデフォルト バージョンを変更した場合、リクエストでは以前に選択したバージョンが引き続き使用されます。

デフォルトのバージョンを変更するには:

Console

  1. Google Cloud コンソールの Document AI セクションで、[プロセッサ] ページに移動します。

    [プロセッサ] ページに移動

  2. プロセッサのリストで、詳細を表示するプロセッサの名前をクリックします。

  3. プロセッサの [バージョンの管理](または [デプロイと使用])タブの [デフォルト バージョン] プルダウン メニューで、デフォルト バージョンとして使用するプロセッサのバージョンを選択します。

REST

このサンプルは、processors.setDefaultProcessorVersion メソッドを使用してプロセッサのデフォルト プロセッサ バージョンを設定する方法を示しています。

リクエストのデータを使用する前に、次のように置き換えます。

  • LOCATION: プロセッサのロケーション(例:
    • us - 米国
    • eu - 欧州連合
  • PROJECT_ID: 実際の Google Cloud プロジェクト ID。
  • PROCESSOR_ID: カスタム プロセッサの ID。
  • PROCESSOR_VERSION: プロセッサのバージョン ID。詳細については、プロセッサ バージョンを選択するをご覧ください。例:
    • pretrained-TYPE-vX.X-YYYY-MM-DD
    • stable
    • rc

HTTP メソッドと URL:

POST https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID:setDefaultProcessorVersion

リクエストの本文(JSON):

{
  "defaultProcessorVersion": "PROCESSOR_VERSION"
}

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID:setDefaultProcessorVersion"

PowerShell

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID:setDefaultProcessorVersion" | Select-Object -Expand Content

レスポンスは長時間実行オペレーションです。長時間実行オペレーションをポーリングするには、operations.get を呼び出します。

レスポンスの SetDefaultProcessorVersionMetadata は、オペレーションの状態を示します。

{
  "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.documentai.v1.SetDefaultProcessorVersionMetadata",
    "commonMetadata": {
      "state": "SUCCEEDED",
      "createTime": "2022-03-02T22:52:49.957096Z",
      "updateTime": "2022-03-02T22:52:50.175976Z",
      "resource": "projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION"
    }
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.documentai.v1.SetDefaultProcessorVersionResponse"
  }
}

C#

詳細については、Document AI C# API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

using Google.Cloud.DocumentAI.V1;
using Google.LongRunning;

public sealed partial class GeneratedDocumentProcessorServiceClientSnippets
{
    /// <summary>Snippet for SetDefaultProcessorVersion</summary>
    /// <remarks>
    /// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void SetDefaultProcessorVersionRequestObject()
    {
        // Create client
        DocumentProcessorServiceClient documentProcessorServiceClient = DocumentProcessorServiceClient.Create();
        // Initialize request argument(s)
        SetDefaultProcessorVersionRequest request = new SetDefaultProcessorVersionRequest
        {
            ProcessorAsProcessorName = ProcessorName.FromProjectLocationProcessor("[PROJECT]", "[LOCATION]", "[PROCESSOR]"),
            DefaultProcessorVersionAsProcessorVersionName = ProcessorVersionName.FromProjectLocationProcessorProcessorVersion("[PROJECT]", "[LOCATION]", "[PROCESSOR]", "[PROCESSOR_VERSION]"),
        };
        // Make the request
        Operation<SetDefaultProcessorVersionResponse, SetDefaultProcessorVersionMetadata> response = documentProcessorServiceClient.SetDefaultProcessorVersion(request);

        // Poll until the returned long-running operation is complete
        Operation<SetDefaultProcessorVersionResponse, SetDefaultProcessorVersionMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        SetDefaultProcessorVersionResponse result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<SetDefaultProcessorVersionResponse, SetDefaultProcessorVersionMetadata> retrievedResponse = documentProcessorServiceClient.PollOnceSetDefaultProcessorVersion(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            SetDefaultProcessorVersionResponse retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

詳細については、Document AI Go API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.SetDefaultProcessorVersionRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/documentai/apiv1/documentaipb#SetDefaultProcessorVersionRequest.
	}
	op, err := c.SetDefaultProcessorVersion(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

詳細については、Document AI Java API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1.ProcessorName;
import com.google.cloud.documentai.v1.ProcessorVersionName;
import com.google.cloud.documentai.v1.SetDefaultProcessorVersionRequest;
import com.google.cloud.documentai.v1.SetDefaultProcessorVersionResponse;

public class SyncSetDefaultProcessorVersion {

  public static void main(String[] args) throws Exception {
    syncSetDefaultProcessorVersion();
  }

  public static void syncSetDefaultProcessorVersion() throws Exception {
    // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DocumentProcessorServiceClient documentProcessorServiceClient =
        DocumentProcessorServiceClient.create()) {
      SetDefaultProcessorVersionRequest request =
          SetDefaultProcessorVersionRequest.newBuilder()
              .setProcessor(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
              .setDefaultProcessorVersion(
                  ProcessorVersionName.of(
                          "[PROJECT]", "[LOCATION]", "[PROCESSOR]", "[PROCESSOR_VERSION]")
                      .toString())
              .build();
      SetDefaultProcessorVersionResponse response =
          documentProcessorServiceClient.setDefaultProcessorVersionAsync(request).get();
    }
  }
}

Python

詳細については、Document AI Python API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


from google.api_core.client_options import ClientOptions
from google.api_core.exceptions import NotFound
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'
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample
# processor_version_id = 'YOUR_PROCESSOR_VERSION_ID'


def set_default_processor_version_sample(
    project_id: str, location: str, processor_id: str, processor_version_id: 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 processor
    # e.g.: projects/project_id/locations/location/processors/processor_id
    processor = client.processor_path(project_id, location, processor_id)

    # The full resource name of the processor version
    # e.g.: projects/project_id/locations/location/processors/processor_id/processorVersions/processor_version_id
    processor_version = client.processor_version_path(
        project_id, location, processor_id, processor_version_id
    )

    request = documentai.SetDefaultProcessorVersionRequest(
        processor=processor, default_processor_version=processor_version
    )

    # Make SetDefaultProcessorVersion request
    try:
        operation = client.set_default_processor_version(request)
        # Print operation details
        print(operation.operation.name)
        # Wait for operation to complete
        operation.result()
    except NotFound as e:
        print(e.message)

Ruby

詳細については、Document AI Ruby API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/document_ai/v1"

##
# Snippet for the set_default_processor_version call in the DocumentProcessorService service
#
# 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://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client#set_default_processor_version.
#
def set_default_processor_version
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::DocumentAI::V1::SetDefaultProcessorVersionRequest.new

  # Call the set_default_processor_version method.
  result = client.set_default_processor_version request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

プロセッサ バージョンをデプロイする

Document AI で新しいプロセッサ バージョンを作成したら、このバージョンでドキュメントを処理する前にデプロイする必要があります。

Console

  1. Google Cloud コンソールの Document AI セクションで、[プロセッサ] ページに移動します。

    [プロセッサ] ページに移動

  2. プロセッサのリストで、詳細を表示するプロセッサの名前をクリックします。

  3. プロセッサの [バージョンの管理](または [デプロイと使用])タブで、デプロイするプロセッサ バージョンの横にあるチェックボックスをオンにします。

  4. [Deploy] をクリックし、ダイアログ ウィンドウでもう一度 [Deploy] をクリックします。この処理には数分かかります。

REST

このサンプルは、processorVersions.deploy メソッドを使用してプロセッサのプロセッサ バージョンをデプロイする方法を示しています。

リクエストのデータを使用する前に、次のように置き換えます。

  • LOCATION: プロセッサのロケーション(例:
    • us - 米国
    • eu - 欧州連合
  • PROJECT_ID: 実際の Google Cloud プロジェクト ID。
  • PROCESSOR_ID: カスタム プロセッサの ID。
  • PROCESSOR_VERSION: プロセッサのバージョン ID。

HTTP メソッドと URL:

POST https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION:deploy

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

次のコマンドを実行します。

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION:deploy"

PowerShell

次のコマンドを実行します。

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION:deploy" | Select-Object -Expand Content

レスポンスは長時間実行オペレーションです。長時間実行オペレーションをポーリングするには、operations.get を呼び出します。

レスポンスの DeployProcessorVersionMetadata は、オペレーションの状態を示します。

{
  "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.documentai.v1.DeployProcessorVersionMetadata",
    "commonMetadata": {
      "state": "SUCCEEDED",
      "createTime": "2022-08-29T16:27:00.195539Z",
      "updateTime": "2022-08-29T16:32:01.963962Z",
      "resource": "projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION"
    }
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.documentai.v1.DeployProcessorVersionResponse"
  }
}

C#

詳細については、Document AI C# API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

using Google.Cloud.DocumentAI.V1;
using Google.LongRunning;

public sealed partial class GeneratedDocumentProcessorServiceClientSnippets
{
    /// <summary>Snippet for DeployProcessorVersion</summary>
    /// <remarks>
    /// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void DeployProcessorVersionRequestObject()
    {
        // Create client
        DocumentProcessorServiceClient documentProcessorServiceClient = DocumentProcessorServiceClient.Create();
        // Initialize request argument(s)
        DeployProcessorVersionRequest request = new DeployProcessorVersionRequest
        {
            ProcessorVersionName = ProcessorVersionName.FromProjectLocationProcessorProcessorVersion("[PROJECT]", "[LOCATION]", "[PROCESSOR]", "[PROCESSOR_VERSION]"),
        };
        // Make the request
        Operation<DeployProcessorVersionResponse, DeployProcessorVersionMetadata> response = documentProcessorServiceClient.DeployProcessorVersion(request);

        // Poll until the returned long-running operation is complete
        Operation<DeployProcessorVersionResponse, DeployProcessorVersionMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        DeployProcessorVersionResponse result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<DeployProcessorVersionResponse, DeployProcessorVersionMetadata> retrievedResponse = documentProcessorServiceClient.PollOnceDeployProcessorVersion(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            DeployProcessorVersionResponse retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

詳細については、Document AI Go API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.DeployProcessorVersionRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/documentai/apiv1/documentaipb#DeployProcessorVersionRequest.
	}
	op, err := c.DeployProcessorVersion(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

詳細については、Document AI Java API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.documentai.v1.DeployProcessorVersionRequest;
import com.google.cloud.documentai.v1.DeployProcessorVersionResponse;
import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1.ProcessorVersionName;

public class SyncDeployProcessorVersion {

  public static void main(String[] args) throws Exception {
    syncDeployProcessorVersion();
  }

  public static void syncDeployProcessorVersion() throws Exception {
    // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DocumentProcessorServiceClient documentProcessorServiceClient =
        DocumentProcessorServiceClient.create()) {
      DeployProcessorVersionRequest request =
          DeployProcessorVersionRequest.newBuilder()
              .setName(
                  ProcessorVersionName.of(
                          "[PROJECT]", "[LOCATION]", "[PROCESSOR]", "[PROCESSOR_VERSION]")
                      .toString())
              .build();
      DeployProcessorVersionResponse response =
          documentProcessorServiceClient.deployProcessorVersionAsync(request).get();
    }
  }
}

Python

詳細については、Document AI Python API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


from google.api_core.client_options import ClientOptions
from google.api_core.exceptions import FailedPrecondition
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'
# processor_id = 'YOUR_PROCESSOR_ID'
# processor_version_id = 'YOUR_PROCESSOR_VERSION_ID'


def deploy_processor_version_sample(
    project_id: str, location: str, processor_id: str, processor_version_id: 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 processor version
    # e.g.: projects/project_id/locations/location/processors/processor_id/processorVersions/processor_version_id
    name = client.processor_version_path(
        project_id, location, processor_id, processor_version_id
    )

    # Make DeployProcessorVersion request
    try:
        operation = client.deploy_processor_version(name=name)
        # Print operation details
        print(operation.operation.name)
        # Wait for operation to complete
        operation.result()
    # Deploy request will fail if the
    # processor version is already deployed
    except FailedPrecondition as e:
        print(e.message)

Ruby

詳細については、Document AI Ruby API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/document_ai/v1"

##
# Snippet for the deploy_processor_version call in the DocumentProcessorService service
#
# 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://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client#deploy_processor_version.
#
def deploy_processor_version
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::DocumentAI::V1::DeployProcessorVersionRequest.new

  # Call the deploy_processor_version method.
  result = client.deploy_processor_version request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

プロセッサ バージョンをデプロイ解除する

Document AI で新しいプロセッサ バージョンを作成してデプロイした後、プロセッサ バージョンで処理リクエストを処理しないようにするには、デプロイを解除します。

Console

  1. Google Cloud コンソールの Document AI セクションで、[プロセッサ] ページに移動します。

    [プロセッサ] ページに移動

  2. プロセッサのリストで、詳細を表示するプロセッサの名前をクリックします。

  3. プロセッサの [バージョンの管理](または [デプロイと使用])タブで、デプロイを解除するプロセッサ バージョンの横にあるチェックボックスをオンにします。

  4. [デプロイ解除] をクリックし、ダイアログ ウィンドウでもう一度 [デプロイ解除] をクリックします。この処理には数分かかります。

REST

このサンプルは、processorVersions.undeploy メソッドを使用してプロセッサのプロセッサ バージョンをデプロイ解除する方法を示しています。

リクエストのデータを使用する前に、次のように置き換えます。

  • LOCATION: プロセッサのロケーション(例:
    • us - 米国
    • eu - 欧州連合
  • PROJECT_ID: 実際の Google Cloud プロジェクト ID。
  • PROCESSOR_ID: カスタム プロセッサの ID。
  • PROCESSOR_VERSION: プロセッサのバージョン ID。

HTTP メソッドと URL:

POST https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION:undeploy

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

次のコマンドを実行します。

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION:undeploy"

PowerShell

次のコマンドを実行します。

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION:undeploy" | Select-Object -Expand Content

レスポンスは長時間実行オペレーションです。長時間実行オペレーションをポーリングするには、operations.get を呼び出します。

レスポンスの UndeployProcessorVersionMetadata は、オペレーションの状態を示します。

{
  "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.documentai.v1.UndeployProcessorVersionMetadata",
    "commonMetadata": {
      "state": "SUCCEEDED",
      "createTime": "2022-08-29T16:27:00.195539Z",
      "updateTime": "2022-08-29T16:32:01.963962Z",
      "resource": "projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION"
    }
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.documentai.v1.UndeployProcessorVersionResponse"
  }
}

C#

詳細については、Document AI C# API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

using Google.Cloud.DocumentAI.V1;
using Google.LongRunning;

public sealed partial class GeneratedDocumentProcessorServiceClientSnippets
{
    /// <summary>Snippet for UndeployProcessorVersion</summary>
    /// <remarks>
    /// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void UndeployProcessorVersionRequestObject()
    {
        // Create client
        DocumentProcessorServiceClient documentProcessorServiceClient = DocumentProcessorServiceClient.Create();
        // Initialize request argument(s)
        UndeployProcessorVersionRequest request = new UndeployProcessorVersionRequest
        {
            ProcessorVersionName = ProcessorVersionName.FromProjectLocationProcessorProcessorVersion("[PROJECT]", "[LOCATION]", "[PROCESSOR]", "[PROCESSOR_VERSION]"),
        };
        // Make the request
        Operation<UndeployProcessorVersionResponse, UndeployProcessorVersionMetadata> response = documentProcessorServiceClient.UndeployProcessorVersion(request);

        // Poll until the returned long-running operation is complete
        Operation<UndeployProcessorVersionResponse, UndeployProcessorVersionMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        UndeployProcessorVersionResponse result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<UndeployProcessorVersionResponse, UndeployProcessorVersionMetadata> retrievedResponse = documentProcessorServiceClient.PollOnceUndeployProcessorVersion(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            UndeployProcessorVersionResponse retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

詳細については、Document AI Go API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.UndeployProcessorVersionRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/documentai/apiv1/documentaipb#UndeployProcessorVersionRequest.
	}
	op, err := c.UndeployProcessorVersion(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

詳細については、Document AI Java API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1.ProcessorVersionName;
import com.google.cloud.documentai.v1.UndeployProcessorVersionRequest;
import com.google.cloud.documentai.v1.UndeployProcessorVersionResponse;

public class SyncUndeployProcessorVersion {

  public static void main(String[] args) throws Exception {
    syncUndeployProcessorVersion();
  }

  public static void syncUndeployProcessorVersion() throws Exception {
    // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DocumentProcessorServiceClient documentProcessorServiceClient =
        DocumentProcessorServiceClient.create()) {
      UndeployProcessorVersionRequest request =
          UndeployProcessorVersionRequest.newBuilder()
              .setName(
                  ProcessorVersionName.of(
                          "[PROJECT]", "[LOCATION]", "[PROCESSOR]", "[PROCESSOR_VERSION]")
                      .toString())
              .build();
      UndeployProcessorVersionResponse response =
          documentProcessorServiceClient.undeployProcessorVersionAsync(request).get();
    }
  }
}

Python

詳細については、Document AI Python API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


from google.api_core.client_options import ClientOptions
from google.api_core.exceptions import FailedPrecondition
from google.api_core.exceptions import InvalidArgument
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'
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample
# processor_version_id = 'YOUR_PROCESSOR_VERSION_ID'


def undeploy_processor_version_sample(
    project_id: str, location: str, processor_id: str, processor_version_id: 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 processor version
    # e.g.: projects/project_id/locations/location/processors/processor_id/processorVersions/processor_version_id
    name = client.processor_version_path(
        project_id, location, processor_id, processor_version_id
    )

    # Make UndeployProcessorVersion request
    try:
        operation = client.undeploy_processor_version(name=name)
        # Print operation details
        print(operation.operation.name)
        # Wait for operation to complete
        operation.result()
    # Undeploy request will fail if the
    # processor version is already undeployed
    # or if a request is made on a pretrained processor version
    except (FailedPrecondition, InvalidArgument) as e:
        print(e.message)

Ruby

詳細については、Document AI Ruby API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/document_ai/v1"

##
# Snippet for the undeploy_processor_version call in the DocumentProcessorService service
#
# 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://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client#undeploy_processor_version.
#
def undeploy_processor_version
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::DocumentAI::V1::UndeployProcessorVersionRequest.new

  # Call the undeploy_processor_version method.
  result = client.undeploy_processor_version request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

プロセッサ バージョンを削除する

Document AI で新しいプロセッサ バージョンを作成した後、プロセッサ バージョンを必要としなくなった場合は削除できます。

Console

  1. Google Cloud コンソールの Document AI セクションで、[プロセッサ] ページに移動します。

    [プロセッサ] ページに移動

  2. プロセッサのリストで、詳細を表示するプロセッサの名前をクリックします。

  3. プロセッサの [バージョンを管理](または [デプロイと使用])タブで、削除するプロセッサ バージョンの横にあるアクション メニュー をクリックします。

  4. [削除] をクリックし、ダイアログ ウィンドウでもう一度 [削除] をクリックします。

REST

このサンプルは、processorVersions.delete メソッドを使用してプロセッサのプロセッサ バージョンを削除する方法を示しています。

リクエストのデータを使用する前に、次のように置き換えます。

  • LOCATION: プロセッサのロケーション(例:
    • us - 米国
    • eu - 欧州連合
  • PROJECT_ID: 実際の Google Cloud プロジェクト ID。
  • PROCESSOR_ID: カスタム プロセッサの ID。
  • PROCESSOR_VERSION: プロセッサのバージョン ID。

HTTP メソッドと URL:

DELETE https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

次のコマンドを実行します。

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

PowerShell

次のコマンドを実行します。

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

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION" | Select-Object -Expand Content

レスポンスは長時間実行オペレーションです。長時間実行オペレーションをポーリングするには、operations.get を呼び出します。

レスポンスの DeleteProcessorVersionMetadata は、オペレーションの状態を示します。

{
  "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.documentai.v1.DeleteProcessorVersionMetadata",
    "commonMetadata": {
      "state": "SUCCEEDED",
      "createTime": "2022-08-29T16:27:00.195539Z",
      "updateTime": "2022-08-29T16:32:01.963962Z",
      "resource": "projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/processorVersions/PROCESSOR_VERSION"
    }
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.protobuf.Empty"
  }
}

C#

詳細については、Document AI C# API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

using Google.Cloud.DocumentAI.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;

public sealed partial class GeneratedDocumentProcessorServiceClientSnippets
{
    /// <summary>Snippet for DeleteProcessorVersion</summary>
    /// <remarks>
    /// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void DeleteProcessorVersionRequestObject()
    {
        // Create client
        DocumentProcessorServiceClient documentProcessorServiceClient = DocumentProcessorServiceClient.Create();
        // Initialize request argument(s)
        DeleteProcessorVersionRequest request = new DeleteProcessorVersionRequest
        {
            ProcessorVersionName = ProcessorVersionName.FromProjectLocationProcessorProcessorVersion("[PROJECT]", "[LOCATION]", "[PROCESSOR]", "[PROCESSOR_VERSION]"),
        };
        // Make the request
        Operation<Empty, DeleteProcessorVersionMetadata> response = documentProcessorServiceClient.DeleteProcessorVersion(request);

        // Poll until the returned long-running operation is complete
        Operation<Empty, DeleteProcessorVersionMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        Empty result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<Empty, DeleteProcessorVersionMetadata> retrievedResponse = documentProcessorServiceClient.PollOnceDeleteProcessorVersion(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            Empty retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

詳細については、Document AI Go API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


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.DeleteProcessorVersionRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/documentai/apiv1/documentaipb#DeleteProcessorVersionRequest.
	}
	op, err := c.DeleteProcessorVersion(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	err = op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
}

Java

詳細については、Document AI Java API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.documentai.v1.DeleteProcessorVersionRequest;
import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1.ProcessorVersionName;
import com.google.protobuf.Empty;

public class SyncDeleteProcessorVersion {

  public static void main(String[] args) throws Exception {
    syncDeleteProcessorVersion();
  }

  public static void syncDeleteProcessorVersion() throws Exception {
    // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (DocumentProcessorServiceClient documentProcessorServiceClient =
        DocumentProcessorServiceClient.create()) {
      DeleteProcessorVersionRequest request =
          DeleteProcessorVersionRequest.newBuilder()
              .setName(
                  ProcessorVersionName.of(
                          "[PROJECT]", "[LOCATION]", "[PROCESSOR]", "[PROCESSOR_VERSION]")
                      .toString())
              .build();
      documentProcessorServiceClient.deleteProcessorVersionAsync(request).get();
    }
  }
}

Python

詳細については、Document AI Python API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。


from google.api_core.client_options import ClientOptions
from google.api_core.exceptions import FailedPrecondition
from google.api_core.exceptions import InvalidArgument
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'
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample
# processor_version_id = 'YOUR_PROCESSOR_VERSION_ID'


def delete_processor_version_sample(
    project_id: str, location: str, processor_id: str, processor_version_id: 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 processor version
    # e.g.: projects/project_id/locations/location/processors/processor_id/processorVersions/processor_version_id
    name = client.processor_version_path(
        project_id, location, processor_id, processor_version_id
    )

    # Make DeleteProcessorVersion request
    try:
        operation = client.delete_processor_version(name=name)
        # Print operation details
        print(operation.operation.name)
        # Wait for operation to complete
        operation.result()
    # Delete request will fail if the
    # processor version doesn't exist
    # or if a request is made on a pretrained processor version
    # or the default processor version
    except (FailedPrecondition, InvalidArgument) as e:
        print(e.message)

Ruby

詳細については、Document AI Ruby API のリファレンス ドキュメントをご覧ください。

Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

require "google/cloud/document_ai/v1"

##
# Snippet for the delete_processor_version call in the DocumentProcessorService service
#
# 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://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client#delete_processor_version.
#
def delete_processor_version
  # Create a client object. The client can be reused for multiple calls.
  client = Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new

  # Create a request. To set request fields, pass in keyword arguments.
  request = Google::Cloud::DocumentAI::V1::DeleteProcessorVersionRequest.new

  # Call the delete_processor_version method.
  result = client.delete_processor_version request

  # The returned object is of type Gapic::Operation. You can use it to
  # check the status of an operation, cancel it, or wait for results.
  # Here is how to wait for a response.
  result.wait_until_done! timeout: 60
  if result.response?
    p result.response
  else
    puts "No response received."
  end
end

プロセッサ バージョンをインポートする

Document AI で新しいプロセッサを作成したら、同じプロジェクトまたは別のプロジェクトからプロセッサ バージョンをインポートできます。

destination project は、インポートを開始する場所であり、インポート後にプロセッサ バージョンが使用可能になる場所です。

source project は、ソース プロセッサのバージョンが存在する場所です。

インポートするには、移行元または移行先のプロセッサが次の要件を満たしている必要があります。

  • プロセッサのタイプが一致している必要があります。例: CUSTOM_EXTRACTION_PROCESSORINVOICE_PROCESSOR
  • プロセッサ スキーマが競合しないようにする必要があります。
  • 宛先プロセッサには、既存のデータセットとバージョンを含めることができます。
  • 宛先プロセッサは ENABLED の状態である必要があります。
  • ソース プロセッサのバージョンは、次のいずれかの状態である必要があります。
    • DEPLOYED
    • DEPLOYING
    • UNDEPLOYED
    • UNDEPLOYING

権限拒否エラーを回避するには、転送先プロジェクトの DocumentAI Core サービス エージェントに、転送元プロジェクトに対する Document AI 編集者権限を付与する必要があります。

Gemini 1.5 ベースのプロセッサ バージョン(pretrained-foundation-model-v1.2-2024-05-10pretrained-foundation-model-v1.3-2024-08-31カスタム抽出ツールなど)の場合は、ファインチューニング済みのプロセッサ バージョンをインポートできます。このようなインポートを実行する場合、クロスリージョン インポートはサポートされていません。

プロセッサ バージョンをインポートする前に権限を設定するには、次の手順を完了します。

Console

  1. DocumentAI Core サービス エージェントを検索し、宛先プロジェクト番号を入力します。DocumentAI コアサービス エージェントの形式はメールアドレスに似ています。例: service-123@gcp-sa-prod-dai-core.iam.gserviceaccount.com

  2. Google Cloud コンソールで [IAM] ページを開きます。

    [IAM] ページを開く

  3. ソース プロジェクトを選択します。

  4. [アクセス権を付与] をクリックします。

  5. 宛先プロジェクトの DocumentAI Core サービス エージェントを新しいプリンシパルとして追加し、Document AI 編集者のロールを割り当てます。

gcloud

次の gcloud コマンドを使用して、必要な権限を付与します。

gcloud projects add-iam-policy-binding SOURCE_PROJECT \
    --member=serviceAccount:service-DESTINATION_PROJECT NUMBER@gcp-sa-prod-dai-core.iam.gserviceaccount.com \
    --role=roles/documentai.editor

次の値を指定します。

  • SOURCE_PROJECT: ソース プロジェクト番号またはプロジェクト ID。
  • DESTINATION_PROJECT NUMBER: 宛先プロジェクトの番号

権限を更新したら、次の手順でプロセッサ バージョンをインポートします。

Console

  1. Google Cloud コンソールの Document AI セクションで、[プロセッサ] ページに移動します。

    [プロセッサ] ページに移動

  2. プロセッサのリストで、プロセッサ バージョンを宛先プロセッサとしてインポートするプロセッサの名前をクリックします。

  3. [バージョンの管理](または [デプロイと使用])タブに移動し、[インポート] をクリックします。

  4. ウィンドウで、プロジェクト、プロセッサ、ソース プロセッサ バージョンとしてプロセッサ バージョンを選択します。

  5. ウィンドウの [IMPORT] ボタンをクリックすると、インポート オペレーションが開始されます。

REST

このサンプルは、processorVersions.importProcessorVersion メソッドを使用してプロセッサ バージョンをインポートする方法を示しています。

リクエストのデータを使用する前に、次のように置き換えます。

  • 宛先プロジェクト
    • DESTINATION_PROJECT_ID: 宛先の Google Cloud プロジェクト ID。
    • DESTINATION_LOCATION: 宛先プロセッサのロケーション
    • DESTINATION_PROCESSOR_ID: 宛先プロセッサの ID。
  • ソース プロジェクト
    • SOURCE_PROJECT_ID: ソース Google Cloud プロジェクト ID。
    • SOURCE_LOCATION: ソース プロセッサのロケーション。
    • SOURCE_PROCESSOR_ID: ソース プロセッサの ID。
    • SOURCE_PROCESSOR_VERSION: インポートするソース プロセッサのバージョン。

HTTP メソッドと URL:

POST https://DESTINATION_LOCATION-documentai.googleapis.com/v1beta3/projects/DESTINATION_PROJECT_ID/locations/DESTINATION_LOCATION/processors/DESTINATION_PROCESSOR_ID/processorVersions:importProcessorVersion

リクエストの本文(JSON):

{
  "processorVersionSource": "projects/SOURCE_PROJECT_ID/locations/SOURCE_LOCATION/processors/SOURCE_PROCESSOR_ID/processorVersions/SOURCE_PROCESSOR_VERSION"
}

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://DESTINATION_LOCATION-documentai.googleapis.com/v1beta3/projects/DESTINATION_PROJECT_ID/locations/DESTINATION_LOCATION/processors/DESTINATION_PROCESSOR_ID/processorVersions:importProcessorVersion"

PowerShell

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

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

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://DESTINATION_LOCATION-documentai.googleapis.com/v1beta3/projects/DESTINATION_PROJECT_ID/locations/DESTINATION_LOCATION/processors/DESTINATION_PROCESSOR_ID/processorVersions:importProcessorVersion" | Select-Object -Expand Content

次のような JSON レスポンスが返されます。

{
  "name": "projects/DESTINATION_PROJECT_ID/locations/DESTINATION_LOCATION/operations/OPERATION_ID"
}

次のステップ