本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Bedrock 数据自动化 API
Amazon Bedrock 数据自动化 (BDA) 功能为处理您的数据提供了简化的 API 工作流程。对于所有模态,此工作流都包含三个主要步骤:创建项目、调用分析和检索结果。要检索已处理数据的自定义输出,请在调用分析操作时提供蓝图 ARN。
创建数据自动化项目
要开始使用 BDA 处理文件,您需要先创建数据自动化项目。这可以通过两种方式完成,使用 CreateDataAutomationProject 操作或亚马逊 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 账户可以创建的项目数量是有限的。系统可能会不允许某些设置的组合,或者可能需要其他权限。
以下是具有标准和自定义输出配置的 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 接受由返回的调用 ARN。 InvokeDataAutomationAsync它检查作业的当前状态,并返回相关信息。作业完成后,会提供 S3 中结果的位置。
如果作业仍在进行中,它将返回当前状态(例如 InProgress “”)。如果作业完成,则会返回“成功”以及结果的 S3 位置。如果出现错误,它将返回包含错误详细信息的 “ServiceErrorClientError” 或 “”。
以下为请求 JSON 的格式:
{ "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 } ] } ] } ] } }
此结构化的输出可以方便地与下游应用程序集成以及用于进一步分析。
蓝图优化 API
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" }
重要
保存调用 ARN 以监控优化任务状态。
GetBlueprintOptimizationStatus
检索通过调用异步 API 输出的蓝图优化任务的当前状态和结果。 InvokeBlueprintOptimizationAsync GetBlueprintOptimizationStatus 接受由返回的调用 ARN。 InvokeBlueprintOptimizationAsync
响应
{ "status": "Success", "outputConfiguration": { "s3Object": { "s3Uri": "s3://my-optimization-bucket/results/optimization-output" } } }
状态值:
已创建-已创建任务
InProgress -优化正在运行
成功-优化成功完成
ServiceError -出现内部服务错误
ClientError -请求参数无效
CopyBlueprintStage
将蓝图从源阶段复制到目标阶段(例如从开发阶段到直播阶段)。这将用于同步所有配置,包括阶段之间的 “优化示例” 字段。
请求正文
{ "blueprintArn": "arn:aws:bedrock:us-east-1:123456789012:blueprint/my-document-processor", "sourceStage": "DEVELOPMENT", "targetStage": "LIVE" }
阶段价值:
发展- Development/testing 阶段
直播-制作阶段
响应
{}
警告
此操作会覆盖目标阶段配置,因此无法轻易撤消。在复制到 LIVE 舞台之前,请确保进行全面测试。