文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 SDK for SAP ABAP 的 Amazon Bedrock 运行时系统示例
以下代码示例向您展示了如何使用适用于 SAP ABAP 的 AWS 软件开发工具包和 Amazon Bedrock Runtime 来执行操作和实现常见场景。
每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。
Stable Image Core
以下代码示例展示了如何在 Amazon Bedrock 上调用 St Stability.ai able Image Core 来生成图像。
- 适用于 SAP ABAP 的 SDK
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 使用 Stable Diffusion 创建图像。
"Stable Image Core Input Parameters should be in a format like this: * { * "prompt": "Draw a dolphin with a mustache, photorealistic", * "aspect_ratio": "1:1", * "seed": 0, * "output_format": "png" * } DATA: BEGIN OF ls_input, prompt TYPE /aws1/rt_shape_string, aspect_ratio TYPE /aws1/rt_shape_string, seed TYPE /aws1/rt_shape_integer, output_format TYPE /aws1/rt_shape_string, END OF ls_input. ls_input-prompt = iv_prompt. ls_input-aspect_ratio = '1:1'. ls_input-seed = 0. "or better, choose a random integer. ls_input-output_format = 'png'. DATA(lv_json) = /ui2/cl_json=>serialize( data = ls_input pretty_name = /ui2/cl_json=>pretty_mode-low_case ). TRY. DATA(lo_response) = lo_bdr->invokemodel( iv_body = /aws1/cl_rt_util=>string_to_xstring( lv_json ) iv_modelid = 'stability.stable-image-core-v1:1' iv_accept = 'application/json' iv_contenttype = 'application/json' ). "Stable Image Core Result Format: * { * "seeds": ["0"], * "finish_reasons": [null], * "images": ["iVBORw0KGgoAAAANSUhEUgAAAgAAA...."] * } DATA: BEGIN OF ls_response, images TYPE STANDARD TABLE OF /aws1/rt_shape_string, END OF ls_response. /ui2/cl_json=>deserialize( EXPORTING jsonx = lo_response->get_body( ) pretty_name = /ui2/cl_json=>pretty_mode-camel_case CHANGING data = ls_response ). IF ls_response-images IS NOT INITIAL. DATA(lv_image) = cl_http_utility=>if_http_utility~decode_x_base64( ls_response-images[ 1 ] ). ENDIF. CATCH /aws1/cx_bdraccessdeniedex INTO DATA(lo_ex). WRITE / lo_ex->get_text( ). WRITE / |Don't forget to enable model access at https://console.aws.amazon.com/bedrock/home?#/modelaccess|. ENDTRY.调用 St Stability.ai able Image Core 基础模型,使用 L2 高级客户端生成图像。
TRY. DATA(lo_bdr_l2_sd) = /aws1/cl_bdr_l2_factory=>create_stable_diffusion_xl_1( lo_bdr ). " iv_prompt contains a prompt like 'Show me a picture of a unicorn reading an enterprise financial report'. DATA(lv_image) = lo_bdr_l2_sd->text_to_image( iv_prompt ). CATCH /aws1/cx_bdraccessdeniedex INTO DATA(lo_ex). WRITE / lo_ex->get_text( ). WRITE / |Don't forget to enable model access at https://console.aws.amazon.com/bedrock/home?#/modelaccess|. ENDTRY.-
有关 API 的详细信息,请参阅适用InvokeModel于 S AP 的AWS SDK ABAP API 参考。
-