Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bedrock prompt to rain build #230

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cfn-lint, Guard and more:

* **Combined logs for nested stacks with sensible filtering**: When you run `rain log`, you will see a combined stream of logs from the stack you specified along with any nested stack associated with it. Rain also filters out uninteresting log messages by default so you just see the errors that require attention. You can also use `rain log --chart` to see a Gantt chart that shows you how long each operation took for a given stack.

* **Build new CloudFormation templates**: `rain build` generates new CloudFormation templates containing skeleton resources that you specify. This saves you having to look up which properties are available and which are required vs. optional.
* **Build new CloudFormation templates**: `rain build` generates new CloudFormation templates containing skeleton resources that you specify. This saves you having to look up which properties are available and which are required vs. optional. Build skeleton templates by specifying a resource name like `AWS::S3::Bucket`, or enable the Bedrock Claude model in your account to use generative AI with a command like `rain build -p "A VPC with 2 subnets"`. (Note that Bedrock is not free, and requires some [setup](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html)).

* **Manipulate CloudFormation stack sets**: `rain stackset deploy` creates a new stackset, updates an existing one or adds a stack instance(s) to an existing stack set. You can list stack sets using `rain stackset ls`, review stack set details with `rain stackset ls <stack set name>` and delete stack set and\or its instances with `rain stackset rm <stack set name>`

Expand Down
447 changes: 278 additions & 169 deletions cft/spec/cfn.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/README.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cfn-lint, Guard and more:

* **Combined logs for nested stacks with sensible filtering**: When you run `rain log`, you will see a combined stream of logs from the stack you specified along with any nested stack associated with it. Rain also filters out uninteresting log messages by default so you just see the errors that require attention. You can also use `rain log --chart` to see a Gantt chart that shows you how long each operation took for a given stack.

* **Build new CloudFormation templates**: `rain build` generates new CloudFormation templates containing skeleton resources that you specify. This saves you having to look up which properties are available and which are required vs. optional.
* **Build new CloudFormation templates**: `rain build` generates new CloudFormation templates containing skeleton resources that you specify. This saves you having to look up which properties are available and which are required vs. optional. Build skeleton templates by specifying a resource name like `AWS::S3::Bucket`, or enable the Bedrock Claude model in your account to use generative AI with a command like `rain build -p "A VPC with 2 subnets"`. (Note that Bedrock is not free, and requires some [setup](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html)).

* **Manipulate CloudFormation stack sets**: `rain stackset deploy` creates a new stackset, updates an existing one or adds a stack instance(s) to an existing stack set. You can list stack sets using `rain stackset ls`, review stack set details with `rain stackset ls <stack set name>` and delete stack set and\or its instances with `rain stackset rm <stack set name>`

Expand Down
7 changes: 6 additions & 1 deletion docs/bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ _rain_build()
flags+=("-b")
local_nonpersistent_flags+=("--bare")
local_nonpersistent_flags+=("-b")
flags+=("--debug")
local_nonpersistent_flags+=("--debug")
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
Expand All @@ -432,7 +434,10 @@ _rain_build()
flags+=("-l")
local_nonpersistent_flags+=("--list")
local_nonpersistent_flags+=("-l")
flags+=("--debug")
flags+=("--prompt")
flags+=("-p")
local_nonpersistent_flags+=("--prompt")
local_nonpersistent_flags+=("-p")
flags+=("--no-colour")

must_have_one_flag=()
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Rain is a command line tool for working with AWS CloudFormation templates and st
* [rain tree](rain_tree.md) - Find dependencies of Resources and Outputs in a local template
* [rain watch](rain_watch.md) - Display an updating view of a CloudFormation stack

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_bootstrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ rain bootstrap

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
15 changes: 8 additions & 7 deletions docs/rain_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ Create CloudFormation templates
Outputs a CloudFormation template containing the named resource types.

```
rain build [<resource type>...]
rain build [<resource type> or <prompt>]
```

### Options

```
-b, --bare Produce a minimal template, omitting all optional resource properties
-h, --help help for build
-j, --json Output the template as JSON (default format: YAML)
-l, --list List all CloudFormation resource types
-b, --bare Produce a minimal template, omitting all optional resource properties
--debug Output debugging information
-h, --help help for build
-j, --json Output the template as JSON (default format: YAML)
-l, --list List all CloudFormation resource types
-p, --prompt Generate a template using Bedrock and a prompt
```

### Options inherited from parent commands

```
--debug Output debugging information
--no-colour Disable colour output
```

### SEE ALSO

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_cat.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ rain cat <stack>

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_ccdeploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ rain ccdeploy <template> <name>

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_ccrm.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ rain ccrm <name>

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_console.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ rain console [stack]

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ rain deploy <template> [stack]

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ rain diff <from> <to>

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_fmt.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ rain fmt <filename>...

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_forecast.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ rain forecast --experimental <template> [stackName]

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ rain info

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ rain logs <stack> (<resource>)

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ rain ls <stack>

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ rain merge <template> <template> ...

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_pkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ rain pkg <template>

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ rain rm <stack>

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_stackset.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ This command manipulates stack sets. It has no action if specific stack set comm
* [rain stackset ls](rain_stackset_ls.md) - List a CloudFormation stack sets in a given region
* [rain stackset rm](rain_stackset_rm.md) - Delete a CloudFormation stack set and/or its instances.

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_stackset_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ rain stackset deploy <template> [stackset] [flags]

* [rain stackset](rain_stackset.md) - This command manipulates stack sets.

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_stackset_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ rain stackset ls <stack set>

* [rain stackset](rain_stackset.md) - This command manipulates stack sets.

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_stackset_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ rain stackset rm <stackset>

* [rain stackset](rain_stackset.md) - This command manipulates stack sets.

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ rain tree [template]

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
2 changes: 1 addition & 1 deletion docs/rain_watch.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ rain watch <stack>

* [rain](index.md) -

###### Auto generated by spf13/cobra on 11-Dec-2023
###### Auto generated by spf13/cobra on 13-Dec-2023
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ go 1.18
require (
github.com/ake-persson/mapslice-json v0.0.0-20210720081907-22c8edf57807
github.com/appscode/jsonpatch v1.0.1
github.com/aws/aws-sdk-go-v2 v1.22.2
github.com/aws/aws-sdk-go-v2 v1.24.0
github.com/aws/aws-sdk-go-v2/config v1.23.0
github.com/aws/aws-sdk-go-v2/credentials v1.15.2
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.5.5
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.39.0
github.com/aws/aws-sdk-go-v2/service/ec2 v1.132.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.42.1
github.com/aws/aws-sdk-go-v2/service/sts v1.25.1
github.com/aws/smithy-go v1.16.0
github.com/aws/smithy-go v1.19.0
github.com/chzyer/readline v1.5.1
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.4.0
Expand All @@ -31,10 +32,10 @@ require (
)

require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.6.0 // indirect
github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.14.2
github.com/aws/aws-sdk-go-v2/service/iam v1.27.1
Expand Down
24 changes: 14 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@ github.com/ake-persson/mapslice-json v0.0.0-20210720081907-22c8edf57807 h1:w3nrG
github.com/ake-persson/mapslice-json v0.0.0-20210720081907-22c8edf57807/go.mod h1:fGnnfniJiO/ajHAVHqMSUSL8sE9LmU9rzclCtoeB+y8=
github.com/appscode/jsonpatch v1.0.1 h1:e82Bj+rsBSnpsmjiIGlc9NiKSBpJONZkamk/F8GrCR0=
github.com/appscode/jsonpatch v1.0.1/go.mod h1:4AJxUpXUhv4N+ziTvIcWWXgeorXpxPZOfk9HdEVr96M=
github.com/aws/aws-sdk-go-v2 v1.22.2 h1:lV0U8fnhAnPz8YcdmZVV60+tr6CakHzqA6P8T46ExJI=
github.com/aws/aws-sdk-go-v2 v1.22.2/go.mod h1:Kd0OJtkW3Q0M0lUWGszapWjEvrXDzRW+D21JNsroB+c=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 h1:hHgLiIrTRtddC0AKcJr5s7i/hLgcpTt+q/FKxf1Zayk=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0/go.mod h1:w4I/v3NOWgD+qvs1NPEwhd++1h3XPHFaVxasfY6HlYQ=
github.com/aws/aws-sdk-go-v2 v1.24.0 h1:890+mqQ+hTpNuw0gGP6/4akolQkSToDJgHfQE7AwGuk=
github.com/aws/aws-sdk-go-v2 v1.24.0/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 h1:OCs21ST2LrepDfD3lwlQiOqIGp6JiEUqG84GzTDoyJs=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4/go.mod h1:usURWEKSNNAcAZuzRn/9ZYPT8aZQkR7xcCtunK/LkJo=
github.com/aws/aws-sdk-go-v2/config v1.23.0 h1:kqzEfGGDIrRJpfJckgwuZfFTbU9NB1jZnRcaO9MpOqE=
github.com/aws/aws-sdk-go-v2/config v1.23.0/go.mod h1:p7wbxKXXjS1GGQOss7VXOazVMFF9bjUGq85/4wR/fSw=
github.com/aws/aws-sdk-go-v2/credentials v1.15.2 h1:rKH7khRMxPdD0u3dHecd0Q7NOVw3EUe7AqdkUOkiOGI=
github.com/aws/aws-sdk-go-v2/credentials v1.15.2/go.mod h1:tXM8wmaeAhfC7nZoCxb0FzM/aRaB1m1WQ7x0qlBLq80=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.3 h1:G5KawTAkyHH6WyKQCdHiW4h3PmAXNJpOgwKg3H7sDRE=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.3/go.mod h1:hugKmSFnZB+HgNI1sYGT14BUPZkO6alC/e0AWu+0IAQ=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2 h1:AaQsr5vvGR7rmeSWBtTCcw16tT9r51mWijuCQhzLnq8=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2/go.mod h1:o1IiRn7CWocIFTXJjGKJDOwxv1ibL53NpcvcqGWyRBA=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2 h1:UZx8SXZ0YtzRiALzYAWcjb9Y9hZUR7MBKaBQ5ouOjPs=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2/go.mod h1:ipuRpcSaklmxR6C39G187TpBAO132gUfleTGccUPs8c=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 h1:v+HbZaCGmOwnTTVS86Fleq0vPzOd7tnJGbFhP0stNLs=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9/go.mod h1:Xjqy+Nyj7VDLBtCMkQYOw1QYfAEZCVLrfI0ezve8wd4=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 h1:N94sVhRACtXyVcjXxrwK1SKFIJrA9pOJ5yu2eSHnmls=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9/go.mod h1:hqamLz7g1/4EJP+GH5NBhcUMLjW+gKLQabgyz6/7WAU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.6.0 h1:hwZB07/beLiCopuRKF0t+dEHmP39iN4YtDh3X5d3hrg=
github.com/aws/aws-sdk-go-v2/internal/ini v1.6.0/go.mod h1:rdAuXeHWhI/zkpYcO5n8WCpaIgY9MUxFyBsuqq3kjyA=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.2 h1:pyVrNAf7Hwz0u39dLKN5t+n0+K/3rMYKuiOoIum3AsU=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.2/go.mod h1:mydrfOb9uiOYCxuCPR8YHQNQyGQwUQ7gPMZGBKbH8NY=
github.com/aws/aws-sdk-go-v2/service/bedrock v1.5.5 h1:dnIEmiCC9JWN6k7da5lLGQ7OKwfl/rJus4vFlR053UE=
github.com/aws/aws-sdk-go-v2/service/bedrock v1.5.5/go.mod h1:BV0qlxGaHddZC0s61iQ91+bLER+H0fZBOHuD4oqB8/s=
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.5.5 h1:r2bcKgvZb4VoHKYjvcWnxa0yBtIvzWiHajbMFt5HYVM=
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.5.5/go.mod h1:S3/2PY5KgjXCnd8ixvdsHdHd49ZyspgOgWAk7E78B2o=
github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.14.2 h1:wm8zm7z6Gl+5O4K5DbZAm1Q37W2SGX4OrP9VOVPuHvc=
github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.14.2/go.mod h1:PsNbJnRfd+PDuV0zZ55KDBSdDSOb/SRcD3FFPFxXnUI=
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.39.0 h1:Inl237UhHY2vGmRUBZvi3NJ+pbFLcgrE0qKrDFoxS1k=
Expand All @@ -44,8 +48,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.1 h1:iRFNqZH4a67IqPvK8xxtyQYn
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.1/go.mod h1:pTy5WM+6sNv2tB24JNKFtn6EvciQ5k40ZJ0pq/Iaxj0=
github.com/aws/aws-sdk-go-v2/service/sts v1.25.1 h1:txgVXIXWPXyqdiVn92BV6a/rgtpX31HYdsOYj0sVQQQ=
github.com/aws/aws-sdk-go-v2/service/sts v1.25.1/go.mod h1:VAiJiNaoP1L89STFlEMgmHX1bKixY+FaP+TpRFrmyZ4=
github.com/aws/smithy-go v1.16.0 h1:gJZEH/Fqh+RsvlJ1Zt4tVAtV6bKkp3cC+R6FCZMNzik=
github.com/aws/smithy-go v1.16.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE=
github.com/aws/smithy-go v1.19.0 h1:KWFKQV80DpP3vJrrA9sVAHQ5gc2z8i4EzrLhLlWXcBM=
github.com/aws/smithy-go v1.19.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE=
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
Expand Down
74 changes: 74 additions & 0 deletions internal/aws/bedrock/bedrock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package bedrock

import (
"context"
"encoding/json"
"fmt"

rainaws "github.com/aws-cloudformation/rain/internal/aws"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/bedrockruntime"
)

type Request struct {
Prompt string `json:"prompt"`
MaxTokensToSample int `json:"max_tokens_to_sample"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
TopK int `json:"top_k,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
}

type Response struct {
Completion string `json:"completion"`
}

func getClient() *bedrockruntime.Client {
return bedrockruntime.NewFromConfig(rainaws.Config())
}

const (
claudePromptFormat = "\n\nHuman:%s\n\nAssistant:"
claudeV2ModelID = "anthropic.claude-v2"
)

// Invoke invokes the Claude V2 model with the provided prompt.
func Invoke(p string) (string, error) {

// Create the Claude 2 payload
payload := Request{
Prompt: fmt.Sprintf(claudePromptFormat, p),
MaxTokensToSample: 2048,
Temperature: 0.5,
TopK: 250,
TopP: 1,
}

// Convert the request to JSON
payloadBytes, err := json.Marshal(payload)
if err != nil {
return "", fmt.Errorf("error marshalling payload: %w", err)
}

// Make the SDK call to the API
output, err := getClient().InvokeModel(context.Background(),
&bedrockruntime.InvokeModelInput{
Body: payloadBytes,
ModelId: aws.String(claudeV2ModelID),
ContentType: aws.String("application/json"),
})

if err != nil {
return "", fmt.Errorf("error invoking model: %w", err)
}

var resp Response

err = json.Unmarshal(output.Body, &resp)

if err != nil {
return "", fmt.Errorf("error unmarshalling response: %w", err)
}

return resp.Completion, nil
}
Loading
Loading