FoundationModel Class
A Bedrock base foundation model.
Example
ts
import * as bedrock from 'aws-cdk-lib/aws-bedrock';
const model = bedrock.FoundationModel.fromFoundationModelId(
this,
'Model',
bedrock.FoundationModelIdentifier.AMAZON_TITAN_TEXT_G1_EXPRESS_V1,
);
const task = new tasks.BedrockInvokeModel(this, 'Prompt Model', {
model,
body: sfn.TaskInput.fromObject(
{
inputText: 'Generate a list of five first names.',
textGenerationConfig: {
maxTokenCount: 100,
temperature: 1,
},
},
),
resultSelector: {
names: sfn.JsonPath.stringAt('$.Body.results[0].outputText'),
},
});
python
import aws_cdk.aws_bedrock as bedrock
model = bedrock.FoundationModel.from_foundation_model_id(self, "Model", bedrock.FoundationModelIdentifier.AMAZON_TITAN_TEXT_G1_EXPRESS_V1)
task = tasks.BedrockInvokeModel(self, "Prompt Model",
model=model,
body=sfn.TaskInput.from_object({
"input_text": "Generate a list of five first names.",
"text_generation_config": {
"max_token_count": 100,
"temperature": 1
}
}),
result_selector={
"names": sfn.JsonPath.string_at("$.Body.results[0].outputText")
}
)
java
import software.amazon.awscdk.services.bedrock.*;
FoundationModel model = FoundationModel.fromFoundationModelId(this, "Model", FoundationModelIdentifier.AMAZON_TITAN_TEXT_G1_EXPRESS_V1);
BedrockInvokeModel task = BedrockInvokeModel.Builder.create(this, "Prompt Model")
.model(model)
.body(TaskInput.fromObject(Map.of(
"inputText", "Generate a list of five first names.",
"textGenerationConfig", Map.of(
"maxTokenCount", 100,
"temperature", 1))))
.resultSelector(Map.of(
"names", JsonPath.stringAt("$.Body.results[0].outputText")))
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Bedrock;
var model = FoundationModel.FromFoundationModelId(this, "Model", FoundationModelIdentifier.AMAZON_TITAN_TEXT_G1_EXPRESS_V1);
var task = new BedrockInvokeModel(this, "Prompt Model", new BedrockInvokeModelProps {
Model = model,
Body = TaskInput.FromObject(new Dictionary<string, object> {
{ "inputText", "Generate a list of five first names." },
{ "textGenerationConfig", new Dictionary<string, int> {
{ "maxTokenCount", 100 },
{ "temperature", 1 }
} }
}),
ResultSelector = new Dictionary<string, object> {
{ "names", JsonPath.StringAt("$.Body.results[0].outputText") }
}
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
model := bedrock.FoundationModel_FromFoundationModelId(this, jsii.String("Model"), bedrock.FoundationModelIdentifier_AMAZON_TITAN_TEXT_G1_EXPRESS_V1())
task := tasks.NewBedrockInvokeModel(this, jsii.String("Prompt Model"), &BedrockInvokeModelProps{
Model: Model,
Body: sfn.TaskInput_FromObject(map[string]interface{}{
"inputText": jsii.String("Generate a list of five first names."),
"textGenerationConfig": map[string]*f64{
"maxTokenCount": jsii.Number(100),
"temperature": jsii.Number(1),
},
}),
ResultSelector: map[string]interface{}{
"names": sfn.JsonPath_stringAt(jsii.String("$.Body.results[0].outputText")),
},
})
Properties
Methods
fromFoundationModelId(scope: Construct, _id: string, foundationModelId: FoundationModelIdentifier): FoundationModel // chainable@staticmethod def from_foundation_model_id(scope: Construct, _id: str, foundation_model_id: FoundationModelIdentifier) -> FoundationModelpublic static FoundationModel fromFoundationModelId(Construct scope, String _id, FoundationModelIdentifier foundationModelId)public static FoundationModel FromFoundationModelId(Construct scope, string _id, FoundationModelIdentifier foundationModelId)func FromFoundationModelId(Scope Construct, _id *string, FoundationModelId FoundationModelIdentifier) FoundationModelstatic#Construct a Bedrock base foundation model given the model identifier.
3 parameters · returns
Parameters
scopescopescopescopeScope— The parent construct._id_id_id_id_id— The name of the model construct.foundationModelIdfoundation_model_idfoundationModelIdfoundationModelIdFoundationModelId— The model identifier such as 'amazon.titan-text-express-v1'.
Returns: A Bedrock base foundation model.