AWS code-library documentation change
Summary
Added Go SDK v2 code example for Bedrock Converse API with Anthropic Claude model
Security assessment
Change adds a new programming language example without security-specific content. Shows standard API usage patterns without security configuration or warnings.
Diff
diff --git a/code-library/latest/ug/bedrock-runtime_example_bedrock-runtime_Converse_AnthropicClaude_section.md b/code-library/latest/ug/bedrock-runtime_example_bedrock-runtime_Converse_AnthropicClaude_section.md index 8ea5a5275..8123cb64d 100644 --- a//code-library/latest/ug/bedrock-runtime_example_bedrock-runtime_Converse_AnthropicClaude_section.md +++ b//code-library/latest/ug/bedrock-runtime_example_bedrock-runtime_Converse_AnthropicClaude_section.md @@ -83,0 +84,61 @@ Send a text message to Anthropic Claude, using Bedrock's Converse API. +Go + + +**SDK for Go V2** + + +###### Note + +There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/gov2/bedrock-runtime#code-examples). + +Send a text message to Anthropic Claude, using Bedrock's Converse API. + + + import ( + "context" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/bedrockruntime" + "github.com/aws/aws-sdk-go-v2/service/bedrockruntime/types" + ) + + // ConverseWrapper encapsulates Amazon Bedrock actions used in the examples. + // It contains a Bedrock Runtime client that is used to invoke Bedrock. + type ConverseWrapper struct { + BedrockRuntimeClient *bedrockruntime.Client + } + + + + func (wrapper ConverseWrapper) ConverseClaude(ctx context.Context, prompt string) (string, error) { + var content = types.ContentBlockMemberText{ + Value: prompt, + } + var message = types.Message{ + Content: []types.ContentBlock{&content}, + Role: "user", + } + modelId := "anthropic.claude-3-haiku-20240307-v1:0" + var converseInput = bedrockruntime.ConverseInput{ + ModelId: aws.String(modelId), + Messages: []types.Message{message}, + } + response, err := wrapper.BedrockRuntimeClient.Converse(ctx, &converseInput) + if err != nil { + ProcessError(err, modelId) + } + + responseText, _ := response.Output.(*types.ConverseOutputMemberMessage) + responseContentBlock := responseText.Value.Content[0] + text, _ := responseContentBlock.(*types.ContentBlockMemberText) + return text.Value, nil + + } + + + + + * For API details, see [Converse](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/bedrockruntime#Client.Converse) in _AWS SDK for Go API Reference_. + + + +