using Amazon;
using Amazon.BedrockRuntime;
using Amazon.BedrockRuntime.Model;
// 1. Initialize the Bedrock Runtime Client
var client = new AmazonBedrockRuntimeClient(RegionEndpoint.USWest2);
// 2. Define the Model ID (Ensure you have requested access to this model in the AWS console)
var modelId = "amazon.nova-lite-v1:0";
// 3. Create the Request using the Converse API
var request = new ConverseRequest
{
ModelId = modelId,
Messages = new List<Message>
{
new Message
{
Role = ConversationRole.User,
Content = new List<ContentBlock>
{
new ContentBlock { Text = "Explain how async/await works in .NET in two short sentences." }
}
}
}
};
try
{
// 4. Send the request and wait for the response
Console.WriteLine("Sending request to Amazon Bedrock...");
var response = await client.ConverseAsync(request);
// 5. Extract and display the text
string responseText = response?.Output?.Message?.Content?[0]?.Text ?? "No response generated.";
Console.WriteLine("\nResponse:");
Console.WriteLine(responseText);
}
catch (Exception ex)
{
Console.WriteLine($"\nError: {ex.Message}");
}
Loading article