|
| 1 | +# Amazon Bedrock Runtime code examples for the SDK for PHP |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Shows how to use the AWS SDK for PHP to work with Amazon Bedrock Runtime. |
| 6 | + |
| 7 | +<!--custom.overview.start--> |
| 8 | +<!--custom.overview.end--> |
| 9 | + |
| 10 | +_Amazon Bedrock Runtime is a fully managed service that makes it easy to use foundation models from third-party providers and Amazon._ |
| 11 | + |
| 12 | +## ⚠ Important |
| 13 | + |
| 14 | +* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/). |
| 15 | +* Running the tests might result in charges to your AWS account. |
| 16 | +* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege). |
| 17 | +* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). |
| 18 | + |
| 19 | +<!--custom.important.start--> |
| 20 | +<!--custom.important.end--> |
| 21 | + |
| 22 | +## Code examples |
| 23 | + |
| 24 | +### Prerequisites |
| 25 | + |
| 26 | +For prerequisites, see the [README](../../README.md#Prerequisites) in the `php` folder. |
| 27 | + |
| 28 | + |
| 29 | +<!--custom.prerequisites.start--> |
| 30 | +- [PHP](https://www.php.net/) version 8.2 or higher |
| 31 | +- [Composer](https://getcomposer.org), for dependency management |
| 32 | +- You must have an AWS account, and have your default credentials and AWS Region |
| 33 | + configured as described in the |
| 34 | + [AWS Tools and SDKs Shared Configuration and Credentials Reference Guide](https://docs.aws.amazon.com/credref/latest/refdocs/creds-config-files.html). |
| 35 | + |
| 36 | +> ⚠ You must request access to a model before you can use it. If you try to use the model (with the API or console) before you have requested access to it, you will receive an error message. For more information, see [Model access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html). |
| 37 | +<!--custom.prerequisites.end--> |
| 38 | +### Scenarios |
| 39 | + |
| 40 | +Code examples that show you how to accomplish a specific task by calling multiple |
| 41 | +functions within the same service. |
| 42 | + |
| 43 | +- [Invoke multiple foundation models on Amazon Bedrock](GettingStartedWithBedrockRuntime.php) |
| 44 | + |
| 45 | +### AI21 Labs Jurassic-2 |
| 46 | + |
| 47 | +- [InvokeModel](BedrockRuntimeService.php#L64) |
| 48 | + |
| 49 | +### Amazon Titan Image Generator |
| 50 | + |
| 51 | +- [InvokeModel](BedrockRuntimeService.php#L131) |
| 52 | + |
| 53 | +### Anthropic Claude |
| 54 | + |
| 55 | +- [InvokeModel](BedrockRuntimeService.php#L31) |
| 56 | + |
| 57 | +### Stable Diffusion |
| 58 | + |
| 59 | +- [InvokeModel](BedrockRuntimeService.php#L94) |
| 60 | + |
| 61 | + |
| 62 | +<!--custom.examples.start--> |
| 63 | +<!--custom.examples.end--> |
| 64 | + |
| 65 | +## Run the examples |
| 66 | + |
| 67 | +### Instructions |
| 68 | + |
| 69 | + |
| 70 | +<!--custom.instructions.start--> |
| 71 | +<!--custom.instructions.end--> |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +#### Invoke multiple foundation models on Amazon Bedrock |
| 76 | + |
| 77 | +This example shows you how to prepare and send a prompt to a variety of large-language models (LLMs) on Amazon Bedrock |
| 78 | + |
| 79 | + |
| 80 | +<!--custom.scenario_prereqs.bedrock-runtime_Scenario_InvokeModels.start--> |
| 81 | +<!--custom.scenario_prereqs.bedrock-runtime_Scenario_InvokeModels.end--> |
| 82 | + |
| 83 | + |
| 84 | +<!--custom.scenarios.bedrock-runtime_Scenario_InvokeModels.start--> |
| 85 | +<!--custom.scenarios.bedrock-runtime_Scenario_InvokeModels.end--> |
| 86 | + |
| 87 | +### Tests |
| 88 | + |
| 89 | +⚠ Running tests might result in charges to your AWS account. |
| 90 | + |
| 91 | + |
| 92 | +To find instructions for running these tests, see the [README](../../README.md#Tests) |
| 93 | +in the `php` folder. |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +<!--custom.tests.start--> |
| 98 | +From the `aws-doc-sdk-examples/php/example_code/bedrock-runtime` directory: |
| 99 | + |
| 100 | +Install the reequired dependencies using Composer: |
| 101 | + |
| 102 | +``` |
| 103 | +composer install |
| 104 | +``` |
| 105 | +Run the tests with the following command: |
| 106 | +``` |
| 107 | +../vendor/bin/phpunit tests/BedrockRuntimeTests.php |
| 108 | +``` |
| 109 | + |
| 110 | +<!--custom.tests.end--> |
| 111 | + |
| 112 | +## Additional resources |
| 113 | + |
| 114 | +- [Amazon Bedrock Runtime User Guide](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html) |
| 115 | +- [Amazon Bedrock Runtime API Reference](https://docs.aws.amazon.com/bedrock/latest/APIReference/welcome.html) |
| 116 | +- [SDK for PHP Amazon Bedrock Runtime reference](https://docs.aws.amazon.com/aws-sdk-php/v3/api/namespace-Aws.Bedrock-runtime.html) |
| 117 | + |
| 118 | +<!--custom.resources.start--> |
| 119 | +<!--custom.resources.end--> |
| 120 | + |
| 121 | +--- |
| 122 | + |
| 123 | +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 124 | + |
| 125 | +SPDX-License-Identifier: Apache-2.0 |
0 commit comments