AWS bedrock documentation change
Summary
Added Swift SDK code example for Converse API with Amazon Nova model including client setup, message handling, and inference parameters
Security assessment
The change adds a programming example without any security-specific configurations or warnings. It demonstrates standard API usage patterns without addressing vulnerabilities or security controls.
Diff
diff --git a/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_Converse_AmazonNovaText_section.md b/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_Converse_AmazonNovaText_section.md index 7a6d66075..4fc13cbc0 100644 --- a//bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_Converse_AmazonNovaText_section.md +++ b//bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_Converse_AmazonNovaText_section.md @@ -754,0 +755,72 @@ Send a text message to Amazon Nova, using Bedrock's Converse API. +Swift + + +**SDK for Swift** + + +###### 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/swift/example_code/bedrock-runtime#code-examples). + +Send a text message to Amazon Nova, using Bedrock's Converse API. + + + // An example demonstrating how to use the Conversation API to send + // a text message to Amazon Nova. + + import AWSBedrockRuntime + + func converse(_ textPrompt: String) async throws -> String { + + // Create a Bedrock Runtime client in the AWS Region you want to use. + let config = + try await BedrockRuntimeClient.BedrockRuntimeClientConfiguration( + region: "us-east-1" + ) + let client = BedrockRuntimeClient(config: config) + + // Set the model ID. + let modelId = "amazon.nova-micro-v1:0" + + // Start a conversation with the user message. + let message = BedrockRuntimeClientTypes.Message( + content: [.text(textPrompt)], + role: .user + ) + + // Optionally use inference parameters + let inferenceConfig = + BedrockRuntimeClientTypes.InferenceConfiguration( + maxTokens: 512, + stopSequences: ["END"], + temperature: 0.5, + topp: 0.9 + ) + + // Create the ConverseInput to send to the model + let input = ConverseInput( + inferenceConfig: inferenceConfig, messages: [message], modelId: modelId) + + // Send the ConverseInput to the model + let response = try await client.converse(input: input) + + // Extract and return the response text. + if case let .message(msg) = response.output { + if case let .text(textResponse) = msg.content![0] { + return textResponse + } else { + return "No text response found in message content" + } + } else { + return "No message found in converse output" + } + } + + + + + * For API details, see [Converse](https://sdk.amazonaws.com/swift/api/awsbedrockruntime/latest/documentation/awsbedrockruntime/bedrockruntimeclient/converse\(input:\)) in _AWS SDK for Swift API reference_. + + + +