Implementation of generative AI abstractions using Amazon Bedrock as the model provider.
$ dotnet add package Universal.GenerativeAI.AmazonBedrockImplementation of generative AI interfaces using Amazon Bedrock models for text generation and transformation.
Implements the IAsyncTextGenerator interface to generate text using Amazon Bedrock's AI models.
// Basic usage with default options
var bedrockClient = new AmazonBedrockRuntimeClient();
var generator = new AmazonBedrockTextGenerator(bedrockClient);
string generatedText = generator.Generate("Write a summary of the key features of quantum computing:");
// Asynchronous usage with custom options
var options = new AmazonBedrockTextGenerator.Options
{
ModelId = "<model ID or inference profile ARN>",
MaxTokens = 4096
};
var generator = new AmazonBedrockTextGenerator(bedrockClient, options);
string generatedText = await generator.GenerateAsync("Write a summary of the key features of quantum computing:", cancellationToken);
Implements the IAsyncTextTransformer interface to transform text into structured objects using Amazon Bedrock's AI models.
// Basic usage to transform text into a custom type
var bedrockClient = new AmazonBedrockRuntimeClient();
var transformer = new AmazonBedrockTextTransformer(bedrockClient);
// Define a class to hold the structured data
public class Product
{
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
}
// Transform text into a Product instance, with explicit prompt for JSON output
Product product = transformer.Transform<Product>(
"Extract product details from this text and respond ONLY with valid JSON in the following format:\n" +
"{\n" +
" \"Name\": \"product name\",\n" +
" \"Description\": \"product description\",\n" +
" \"Price\": numeric price\n" +
"}\n\n" +
"Text: Gaming laptop XPS-9000, high-performance gaming with RGB keyboard, priced at $1299.99"
);
// Asynchronous usage with custom options
var options = new AmazonBedrockTextTransformer.Options
{
ModelId = "anthropic.claude-3-5-sonnet-20240620-v1:0",
MaxTokens = 2048
};
var transformer = new AmazonBedrockTextTransformer(bedrockClient, options);
List<Product> products = await transformer.TransformAsync<List<Product>>(
"Extract all products from this text and respond ONLY with valid JSON as an array of objects in the following format:\n" +
"[\n" +
" {\n" +
" \"Name\": \"product name\",\n" +
" \"Description\": \"product description\",\n" +
" \"Price\": numeric price\n" +
" },\n" +
" ...\n" +
"]\n\n" +
"Text: Our latest models include the XPS-9000 gaming laptop ($1299.99) with RGB keyboard, and the UltraSlim X1 ultrabook ($899.50) featuring a 4K touchscreen.",
cancellationToken
);