使用 Bedrock 資料自動化 API - Amazon Bedrock

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 Bedrock 資料自動化 API

Amazon Bedrock資料自動化 (BDA) 功能提供簡化的 API 工作流程來處理您的資料。對於所有模式,此工作流程包含三個主要步驟:建立專案、調用分析,以及擷取結果。若要擷取已處理資料的自訂輸出,請在調用分析操作時提供藍圖 ARN。

建立資料自動化專案

若要開始使用 BDA 處理檔案,您必須先建立資料自動化專案。這可以透過兩種方式完成,包括 CreateDataAutomationProject 操作或 Amazon Amazon Bedrock主控台。

使用 API

使用 API 建立專案時,您會調用 CreateDataAutomationProject。建立專案時,您必須針對您傾向處理的檔案類型 (您要使用的模式) 定義組態設定。以下是如何設定影像標準輸出的範例:

{ "standardOutputConfiguration": { "image": { "state": "ENABLED", "extraction": { "category": { "state": "ENABLED", "types": [ "CONTENT_MODERATION", "TEXT_DETECTION" ] }, "boundingBox": { "state": "ENABLED" } }, "generativeField": { "state": "ENABLED", "types": [ "IMAGE_SUMMARY", "IAB" ] } } } }

API 會驗證輸入組態。其使用唯一的 ARN 建立新的專案。專案設定會儲存以供日後使用。如果專案建立時未使用參數,則將套用預設設定。例如,處理影像時,預設會啟用影像摘要和文字偵測。

每個AWS帳戶可建立的專案數量有限制。某些設定組合可能不獲允許,或可能需要額外的許可。

調用資料自動化非同步

您已設定專案,可以使用 InvokeDataAutomationAsync 操作開始處理映像。如果使用自訂輸出,則每個請求只能提交單一藍圖 ARN。

此 API 呼叫會啟動指定 S3 儲存貯體中檔案的非同步處理。此 API 會接受專案 ARN 和要處理的檔案,然後開始非同步任務的處理。系統會傳回任務 ID 以追蹤程序。如果專案不存在、或呼叫者沒有必要的許可,或輸入檔案不是支援的格式,就會引發錯誤。

以下是 JSON 請求的結構:

{ { "blueprints": [ { "blueprintArn": "string", "stage": "string", "version": "string" } ], "clientToken": "string", "dataAutomationConfiguration": { "dataAutomationProjectArn": "string", "stage": "string" }, "dataAutomationProfileArn": "string", "encryptionConfiguration": { "kmsEncryptionContext": { "string" : "string" }, "kmsKeyId": "string" }, "inputConfiguration": { "assetProcessingConfiguration": { "video": { "segmentConfiguration": { ... } } "s3Uri": "string" }, "notificationConfiguration": { "eventBridgeConfiguration": { "eventBridgeEnabled": boolean } }, "outputConfiguration": { "s3Uri": "string" }, "tags": [ { "key": "sstring", "value": "string" } ] } }

在影片檔案上執行 InvokeDataAutomationAsync 時,您可以設定影片區段 (5 分鐘或更久),該區段將被視為資料擷取的完整影片。會使用開始毫秒與結束毫秒的時間戳記來設定此時間。會在 assetProcessingConfiguration 元素中新增此資訊。

叫用資料自動化 (同步)

或者,您可以使用 InvokeDataAutomation 操作。InvokeDataAutomation 操作僅支援處理映像。

此 API 呼叫會透過 S3 參考或在承載中啟動 的同步處理。API 接受專案 ARN 和要處理的檔案,並在回應中傳回結構化洞見。如果專案不存在、或呼叫者沒有必要的許可,或輸入檔案不是支援的格式,就會引發錯誤。如果分析的影像以語義分類為文件,這也會引發為錯誤,因為 InvokeDataAutomation 僅支援影像。為避免此錯誤,您可以在專案上使用模態路由,強制將所有影像檔案類型路由為影像 (請參閱 停用模式和路由檔案類型)。

以下是 JSON 請求的結構:

{ { "blueprints": [ { "blueprintArn": "string", "stage": "string", "version": "string" } ], "clientToken": "string", "dataAutomationConfiguration": { "dataAutomationProjectArn": "string", "stage": "string" }, "dataAutomationProfileArn": "string", "encryptionConfiguration": { "kmsEncryptionContext": { "string" : "string" }, "kmsKeyId": "string" }, "inputConfiguration": { "assetProcessingConfiguration": { "video": { "segmentConfiguration": { ... } } "s3Uri": "string" }, "notificationConfiguration": { "eventBridgeConfiguration": { "eventBridgeEnabled": boolean } }, "tags": [ { "key": "string", "value": "string" } ] } }

輸出包含唯一的結構,取決於呼叫 InvokeDataAutomation 時指定的檔案、操作和自訂輸出組態。請注意,此回應同時包含標準和自訂輸出回應。

以下是具有標準和自訂輸出組態的 JSON 回應結構:

{ "semanticModality": "IMAGE", "outputSegments": [ { "customOutputStatus": "MATCH", "standardOutput": { "image": { "summary": "This image shows a white Nike running shoe with a black Nike swoosh logo on the side. The shoe has a modern design with a thick, cushioned sole and a sleek upper part. The word \"ROUKEA\" is visible on the sole of the shoe, repeated twice. The shoe appears to be designed for comfort and performance, suitable for running or athletic activities. The background is plain and dark, highlighting the shoe.", "iab_categories": [ { "category": "Style and Fashion", "confidence": 0.9890000000000001, "taxonomy_level": 1, "parent_name": "", "id": "0ebe86c8-e9af-43f6-a7bb-182a61d2e1fd", "type": "IAB" }, { "category": "Men's Fashion", "confidence": 0.9890000000000001, "taxonomy_level": 2, "parent_name": "Style and Fashion", "id": "13bd456a-3e1b-4681-b0dd-f42a8d5e5ad5", "type": "IAB" }, { "category": "Style and Fashion", "confidence": 0.853, "taxonomy_level": 1, "parent_name": "", "id": "177b29a1-0e40-45c1-8540-5f49a3d7ded3", "type": "IAB" }, { "category": "Women's Fashion", "confidence": 0.853, "taxonomy_level": 2, "parent_name": "Style and Fashion", "id": "f0197ede-3ba6-498b-8f7b-43fecc5735ef", "type": "IAB" } ], "content_moderation": [], "logos": [ { "id": "2e109eb6-39f5-4782-826f-911b62d277fb", "type": "LOGOS", "confidence": 0.9170872209665809, "name": "nike", "locations": [ { "bounding_box": { "left": 0.3977411523719743, "top": 0.4922481227565456, "width": 0.2574246356942061, "height": 0.15461772197001689 } } ] } ], "text_words": [ { "id": "f70301df-5725-405e-b50c-612e352467bf", "type": "TEXT_WORD", "confidence": 0.10091366487951722, "text": "ROUKEA", "locations": [ { "bounding_box": { "left": 0.6486002310163024, "top": 0.6783271480251003, "width": 0.13219473954570082, "height": 0.05802226710963898 }, "polygon": [ { "x": 0.6486002310163024, "y": 0.7025876947351404 }, { "x": 0.7760931467045249, "y": 0.6783271480251003 }, { "x": 0.7807949705620032, "y": 0.7120888684246991 }, { "x": 0.6533020989743271, "y": 0.7363494151347393 } ] } ], "line_id": "9147fec0-d869-4d58-933e-93eb7164c404" } ], "text_lines": [ { "id": "9147fec0-d869-4d58-933e-93eb7164c404", "type": "TEXT_LINE", "confidence": 0.10091366487951722, "text": "ROUKEA", "locations": [ { "bounding_box": { "left": 0.6486002310163024, "top": 0.6783271480251003, "width": 0.13219473954570082, "height": 0.05802226710963898 }, "polygon": [ { "x": 0.6486002310163024, "y": 0.7025876947351404 }, { "x": 0.7760931467045249, "y": 0.6783271480251003 }, { "x": 0.7807949705620032, "y": 0.7120888684246991 }, { "x": 0.6533020989743271, "y": 0.7363494151347393 } ] } ] } ] }, "statistics": { "iab_category_count": 4, "content_moderation_count": 0, "logo_count": 1, "line_count": 1, "word_count": 1 }, "metadata": { "semantic_modality": "IMAGE", "image_width_pixels": 173, "image_height_pixels": 148, "image_encoding": "jpeg", "s3_bucket": "test-bucket", "s3_key": "uploads/test-image.jpeg" } }, "customOutput": { "matched_blueprint": { "arn": "arn:aws:bedrock:us-east-1:123456789012:blueprint/test", "version": "1", "name": "test-blueprint", "confidence": 1.0 }, "inference_result": { "product_details": { "product_category": "footwear" }, "image_sentiment": "Positive", "image_background": "Solid color", "image_style": "Product image", "image_humor": false } } } ] }

取得資料自動化狀態

若要檢查處理任務的狀態並擷取結果,請使用 GetDataAutomationStatus。

GetDataAutomationStatus API 可讓您監控任務進度,並在處理完成後存取結果。API 會接受 InvokeDataAutomationAsync 傳回的調用 ARN。其會檢查任務的目前狀態,並傳回相關資訊。任務完成後,其會在 S3 中提供結果的位置。

如果任務仍在進行中,其會傳回目前狀態 (例如「InProgress」)。如果任務完成,其會傳回「成功」以及結果的 S3 位置。如果發生錯誤,其會傳回「ServiceError」或「ClientError」,內含錯誤詳細資訊。

請求 URL 的格式如下:

{ "InvocationArn": "string" // Arn }

非同步輸出回應

檔案處理的結果會存放在為輸入影像設定的 S3 儲存貯體中。輸出包含唯一的結構,取決於檔案模態和呼叫 InvokeDataAutomationAsync 時指定的操作類型。

如需指定模式標準輸出的相關資訊,請參閱 Bedrock 資料自動化中的標準輸出

例如,對於影像,其可能包含下列資訊:

  • 影像摘要:影像的描述性摘要或字幕。

  • IAB 分類:根據 IAB 分類法進行分類。

  • 影像文字偵測:使用週框方塊資訊擷取的文字。

  • 內容審核:偵測影像中不適當、不需要或令人反感的內容。

以下是影像處理輸出的範例程式碼片段:

{ "metadata": { "id": "image_123", "semantic_modality": "IMAGE", "s3_bucket": "my-s3-bucket", "s3_prefix": "images/", "image_width_pixels": 1920, "image_height_pixels": 1080 }, "image": { "summary": "A lively party scene with colorful decorations and supplies", "iab_categories": [ { "category": "Party Supplies", "confidence": 0.9, "parent_name": "Events & Attractions" } ], "content_moderation": [ { "category": "Drugs & Tobacco Paraphernalia & Use", "confidence": 0.7 } ], "text_words": [ { "id": "word_1", "text": "lively", "confidence": 0.9, "line_id": "line_1", "locations": [ { "bounding_box": { "left": 100, "top": 200, "width": 50, "height": 20 }, "polygon": [ { "x": 100, "y": 200 }, { "x": 150, "y": 200 }, { "x": 150, "y": 220 }, { "x": 100, "y": 220 } ] } ] } ] } }

您可以透過此結構化輸出,輕鬆與下游應用程式整合與進一步分析。

藍圖最佳化 APIs

InvokeBlueprintOptimizationAsync

您可以為範例內容資產提供正確的預期結果,以改善藍圖準確性。藍圖指示最佳化使用您的範例來精簡藍圖欄位中的自然語言指示,進而提升推論結果的準確性。

對於藍圖,您可以呼叫 InvokeBlueprintOptimizationAsync API,以啟動非同步最佳化任務,根據基本事實資料改善藍圖欄位指示。

請求主體

{ "blueprint": { "blueprintArn": "arn:aws:bedrock:us-east-1:123456789012:blueprint/my-document-processor", "stage": "DEVELOPMENT" }, "samples": [ { "assetS3Object": { "s3Uri": "s3://my-optimization-bucket/samples/document1.pdf" }, "groundTruthS3Object": { "s3Uri": "s3://my-optimization-bucket/ground-truth/document1-expected.json" } } ], "outputConfiguration": { "s3Object": { "s3Uri": "s3://my-optimization-bucket/results/optimization-output" } }, "dataAutomationProfileArn": "arn:aws:bedrock:us-east-1:123456789012:data-automation-profile/my-profile" }
回應

{ "invocationArn": "arn:aws:bedrock:us-east-1:123456789012:blueprint-optimization-invocation/opt-12345abcdef" }
重要

儲存 invocationArn 以監控最佳化任務狀態。

GetBlueprintOptimizationStatus

透過呼叫 InvokeBlueprintOptimizationAsync 非同步 API,擷取輸出的藍圖最佳化任務的目前狀態和結果。GetBlueprintOptimizationStatus 接受 InvokeBlueprintOptimizationAsync 傳回的調用 ARN。

回應

{ "status": "Success", "outputConfiguration": { "s3Object": { "s3Uri": "s3://my-optimization-bucket/results/optimization-output" } } }
狀態值:

  • 已建立 - 任務已建立

  • InProgress - 最佳化正在執行

  • 成功 - 已成功完成最佳化

  • ServiceError - 發生內部服務錯誤

  • ClientError - 無效的請求參數

CopyBlueprintStage

將藍圖從來源階段複製到目標階段 (例如 開發階段至 LIVE 階段)。這將用於同步所有組態,包括階段之間的 optimizationSamples 欄位。

請求主體

{ "blueprintArn": "arn:aws:bedrock:us-east-1:123456789012:blueprint/my-document-processor", "sourceStage": "DEVELOPMENT", "targetStage": "LIVE" }
階段值:

  • 開發 - 開發/測試階段

  • LIVE - 生產階段

回應

{}
警告

此操作會覆寫目標階段組態,且無法輕易復原。在複製到 LIVE 階段之前,請務必進行徹底的測試。