-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go: Add code examples to demonstrate the InvokeModel and InvokeModelW…
…ithResponseStream actions (#5679)
- Loading branch information
1 parent
81f67b8
commit b41b95e
Showing
14 changed files
with
1,222 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<!--Generated by WRITEME on 2023-12-01 20:14:10.900860 (UTC)--> | ||
# Amazon Bedrock Runtime code examples for the SDK for Go V2 | ||
|
||
## Overview | ||
|
||
Shows how to use the AWS SDK for Go V2 to work with Amazon Bedrock Runtime. | ||
|
||
<!--custom.overview.start--> | ||
<!--custom.overview.end--> | ||
|
||
*Amazon Bedrock Runtime is a fully managed service that makes it easy to use foundation models from third-party providers and Amazon.* | ||
|
||
## ⚠ Important | ||
|
||
* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/?aws-products-pricing.sort-by=item.additionalFields.productNameLowercase&aws-products-pricing.sort-order=asc&awsf.Free%20Tier%20Type=*all&awsf.tech-category=*all) and [Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all). | ||
* Running the tests might result in charges to your AWS account. | ||
* 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). | ||
* 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). | ||
|
||
<!--custom.important.start--> | ||
<!--custom.important.end--> | ||
|
||
## Code examples | ||
|
||
### Prerequisites | ||
|
||
For prerequisites, see the [README](../README.md#Prerequisites) in the `gov2` folder. | ||
|
||
|
||
<!--custom.prerequisites.start--> | ||
> ⚠ 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). | ||
<!--custom.prerequisites.end--> | ||
|
||
### Get started | ||
|
||
* [Hello Amazon Bedrock](hello/hello.go#L4) (`InvokeModel`) | ||
|
||
### Single actions | ||
|
||
Code excerpts that show you how to call individual service functions. | ||
|
||
* [Image generation with Amazon Titan](actions/invoke_model.go#L178) (`InvokeModel`) | ||
* [Invoke AI21 Labs Jurassic-2 on Amazon Bedrock](actions/invoke_model.go#L78) (`InvokeModel`) | ||
* [Invoke Anthropic Claude on Amazon Bedrock](actions/invoke_model.go#L27) (`InvokeModel`) | ||
* [Invoke Anthropic Claude on Amazon Bedrock and process the response stream](actions/invoke_model_with_response_stream.go#L30) (`InvokeModelWithResponseStream`) | ||
* [Invoke Meta Llama 2 on Amazon Bedrock](actions/invoke_model.go#L130) (`InvokeModel`) | ||
|
||
### Scenarios | ||
|
||
Code examples that show you how to accomplish a specific task by calling multiple | ||
functions within the same service. | ||
|
||
* [Invoke multiple foundation models on Amazon Bedrock](scenarios/scenario_invoke_models.go) | ||
|
||
## Run the examples | ||
|
||
### Instructions | ||
|
||
|
||
|
||
<!--custom.instructions.start--> | ||
#### Region configuration | ||
By default, examples are set to `us-east-1`. To specify a different region, use the `-region` flag as shown in this example: | ||
|
||
``` | ||
go run ./hello -region=eu-central-1 | ||
``` | ||
|
||
Be aware that not all regions may support Bedrock and its models yet. Verify service availability for your region [here](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/). For available models per region, refer to the [Bedrock dashboard](https://console.aws.amazon.com/bedrock) in the AWS Management Console. | ||
<!--custom.instructions.end--> | ||
|
||
#### Hello Amazon Bedrock | ||
|
||
This example shows you how to get started using Amazon Bedrock. | ||
|
||
``` | ||
go run ./hello | ||
``` | ||
|
||
#### Run a scenario | ||
|
||
All scenarios can be run with the `cmd` runner. To get a list of scenarios | ||
and to get help for running a scenario, use the following command: | ||
|
||
``` | ||
go run ./cmd -h | ||
``` | ||
|
||
#### Invoke multiple foundation models on Amazon Bedrock | ||
|
||
This example shows you how to invoke multiple foundation models on Amazon Bedrock. | ||
|
||
* Generate text with Anthropic Claude. | ||
* Generate text with AI21 Labs Jurassic-2. | ||
* Generate text with Meta Llama 2 Chat. | ||
* Asynchronously process the response stream from Anthropic Claude. | ||
* Generate an image with the Amazon Titan Image Generator. | ||
|
||
<!--custom.scenario_prereqs.bedrock-runtime_Scenario_InvokeModelsInclResponseStream.start--> | ||
<!--custom.scenario_prereqs.bedrock-runtime_Scenario_InvokeModelsInclResponseStream.end--> | ||
|
||
|
||
<!--custom.scenarios.bedrock-runtime_Scenario_InvokeModelsInclResponseStream.start--> | ||
<!--custom.scenarios.bedrock-runtime_Scenario_InvokeModelsInclResponseStream.end--> | ||
|
||
### Tests | ||
|
||
⚠ Running tests might result in charges to your AWS account. | ||
|
||
|
||
To find instructions for running these tests, see the [README](../README.md#Tests) | ||
in the `gov2` folder. | ||
|
||
|
||
|
||
<!--custom.tests.start--> | ||
<!--custom.tests.end--> | ||
|
||
## Additional resources | ||
|
||
* [Amazon Bedrock Runtime User Guide](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html) | ||
* [Amazon Bedrock Runtime API Reference](https://docs.aws.amazon.com/bedrock/latest/APIReference/welcome.html) | ||
* [SDK for Go V2 Amazon Bedrock Runtime reference](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/bedrock-runtime) | ||
|
||
<!--custom.resources.start--> | ||
<!--custom.resources.end--> | ||
|
||
--- | ||
|
||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
SPDX-License-Identifier: Apache-2.0 |
Oops, something went wrong.