# FoundationModel

A Bedrock base foundation model.

Implements: [IModel](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrock.IModel.html)
Obtainable from: FoundationModel.fromFoundationModelId
Used as argument in: [BedrockFoundationModel.fromCdkFoundationModel](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-alpha.BedrockFoundationModel.html#fromcdkfoundationmodel)

- Source: [`aws-bedrock/lib/foundation-model.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-bedrock/lib/foundation-model.ts#L650)
- Type last changed: v2.115.0 · 14 Dec 2023

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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") }
    }
});
```

Golang:

```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

- `modelArn`: string — The foundation model ARN.

- `modelId`: string — The foundation model ID.

  ```ts
  'amazon.titan-text-express-v1'
  ```

## Methods

- `fromFoundationModelId(scope: Construct, _id: string, foundationModelId: FoundationModelIdentifier): FoundationModel // chainable` (static) — Construct a Bedrock base foundation model given the model identifier.

  **Parameters**

  - `scope` — The parent construct.
  - `_id` — The name of the model construct.
  - `foundationModelId` — The model identifier such as 'amazon.titan-text-express-v1'.

  **Returns:** A Bedrock base foundation model.
