הגדרת גרסת ברירת המחדל של המעבד (v1)

הגדרת גרסת ברירת המחדל של מעבד Document AI.

דוגמת קוד

Go

מידע נוסף מופיע במאמרי העזרה של Document AI Go API.

כדי לבצע אימות ב-Document AI, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.


import (
	"context"
	"fmt"
	"io"

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

// Use the SetDefaultProcessorVersion method.
func setDefaultProcessorVersion(ctx context.Context, w io.Writer, projectID string, locationID string, processorID string, processorVersionID string) error {
	processor := fmt.Sprintf("projects/%s/locations/%s/processors/%s", projectID, locationID, processorID)
	defaultProcessorVersion := fmt.Sprintf("projects/%s/locations/%s/processors/%s/processorVersions/%s", projectID, locationID, processorID, processorVersionID)

	client, err := documentai.NewDocumentProcessorClient(ctx)
	if err != nil {
		return fmt.Errorf("NewDocumentProcessorClient failed: %w", err)
	}
	defer client.Close()

	req := &documentaipb.SetDefaultProcessorVersionRequest{
		Processor:               processor,
		DefaultProcessorVersion: defaultProcessorVersion,
	}

	op, err := client.SetDefaultProcessorVersion(ctx, req)
	if err != nil {
		return fmt.Errorf("SetDefaultProcessorVersion: %w", err)
	}

	// SetDefaultProcessorVersion is a long-running operation; wait for completion.
	if _, err := op.Wait(ctx); err != nil {
		return fmt.Errorf("Wait: %w", err)
	}

	fmt.Fprintf(w, "Set default processor version to %s\n", defaultProcessorVersion)

	return nil
}

המאמרים הבאים

כדי לחפש ולסנן דוגמאות קוד למוצרים אחרים של Google Cloud , ראו דפדפן לדוגמה שלGoogle Cloud .