You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apigw-rest-stepfunctions-express-sync-bedrock-sam/Readme.md
+13-20Lines changed: 13 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Prompt Chaining with Amazon API Gateway, AWS Step Functions and Amazon Bedrock.
2
2
3
-
The AWS Serverless Application Model (SAM) template deploys an Amazon API Gateway HTTP API endpoint connected to an AWS Step Functions state machine. This example demonstrates how to invoke an Express state machine synchronously and utilize AWS Step Functions intrinsic functions to chain two prompts, which are then used to invoke the Amazon Bedrock language model. The output from the state machine execution is returned to the client within 29 seconds, using the HTTP API. This no-code example showcases how the results from the first prompt can be used to provide context for the second prompt, allowing the language model to deliver a highly-curated response. By chaining these prompts, the system can leverage the capabilities of the language model to generate more meaningful and contextual outputs.
3
+
The AWS Serverless Application Model (SAM) template deploys an Amazon API Gateway REST API endpoint connected to an AWS Step Functions state machine. This example demonstrates how to invoke an Express state machine synchronously and utilize AWS Step Functions intrinsic functions to chain two prompts, which are then used to invoke the Amazon Bedrock language model. The output from the state machine execution is returned to the client within 29 seconds, using the REST API. This no-code example showcases how the results from the first prompt can be used to provide context for the second prompt, allowing the language model to deliver a highly-curated response. By chaining these prompts, the system can leverage the capabilities of the language model to generate more meaningful and contextual outputs.
4
4
5
5
Learn more about this pattern at [Serverless Land Patterns](https://serverlessland.com/patterns/apigw-rest-stepfunctions-express-sync-bedrock-sam)
6
6
@@ -12,7 +12,7 @@ Important: this application uses various AWS services and there are costs associ
12
12
*[AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
*[NOTE! Manage Access to Amazon Bedrock Foundation Models](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html) at the time of writing, this example uses Amazon Bedrock foundation model cohere.command-text-v14
15
+
*This example uses Amazon Bedrock foundation model amazon.nova-2-lite-v1:0
16
16
17
17
18
18
## Deployment Instructions
@@ -45,40 +45,33 @@ Important: this application uses various AWS services and there are costs associ
45
45
46
46
## How it Works
47
47
In this example, the state machine is invoked with a JSON payload
48
+
48
49
```asl
49
50
{
50
51
"prompt_one": "Write a 500 word blog post on The Beatles"
51
52
}
52
53
```
54
+
53
55
During execution, the Task state calls the Bedrock API and the response is passed to the task 'result_one'.
56
+
54
57
```asl
55
58
{
56
-
"result_one.$": "$.Body.generations[0].text"
57
-
}
58
-
```
59
-
A Pass state is then used to format the data using an Intrinsic Function (States.) which is passed to the next state.
By default, the state then sends the task result as output.
73
62
63
+
A Pass state is then used to build the conversation history with the first prompt, the model's response, and the second prompt, which is passed to the next state.
64
+
65
+
The second prompt is then executed with the conversation history that includes the results from the first execution. This provides the model with more context.
66
+
67
+
By default, the state then sends the task result as output.
74
68
75
69
## Testing
76
70
77
71
The stack will output the **api endpoint**. You can use *Postman* or *curl* to send a POST request to the API Gateway endpoint.
78
72
79
73
```
80
74
curl -H "Content-type: application/json" -X POST -d '{"prompt_one": "Write a 500 word blog post on The Beatles"}' <Your API endpoint>
81
-
82
75
```
83
76
After runnning the above command, API Gateway will invoke the State machine and return the results back to the client instead of just the State machine's execution Id.
84
77
@@ -93,6 +86,6 @@ After runnning the above command, API Gateway will invoke the State machine and
Copy file name to clipboardExpand all lines: apigw-rest-stepfunctions-express-sync-bedrock-sam/apigw-rest-stepfunctions-express-sync-bedrock-sam.json
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,17 @@
1
1
{
2
-
"title": "Prompt Chaining with Amazon API Gateway and AWS Step Functions",
3
-
"description": "Prompt Chaining no-code example with Amazon API Gateway HTTP API, AWS Step Functions and Amazon Bedrock.",
2
+
"title": "Prompt Chaining with Amazon API Gateway and AWS Step Functions.",
3
+
"description": "Prompt Chaining no-code example with Amazon API Gateway REST API, AWS Step Functions and Amazon Bedrock.",
4
4
"language": "",
5
5
"level": "200",
6
6
"framework": "AWS SAM",
7
7
"introBox": {
8
8
"headline": "How it works",
9
9
"text": [
10
10
"The provided example demonstrates the deployment of a serverless application using the AWS Serverless Application Model (SAM) template.",
11
-
"This serverless application includes an Amazon API Gateway HTTP API endpoint that is connected to an AWS Step Functions state machine.",
11
+
"This serverless application includes an Amazon API Gateway REST API endpoint that is connected to an AWS Step Functions state machine.",
12
12
"The state machine is designed to invoke an Express workflow synchronously.",
13
13
"It utilizes AWS Step Functions' intrinsic functions to chain two prompts, which are then used to invoke the Amazon Bedrock language model.",
14
-
"The output from the state machine execution is returned to the client within 29 seconds through the HTTP API.",
14
+
"The output from the state machine execution is returned to the client within 29 seconds through the REST API.",
15
15
"This no-code example showcases how the results from the first prompt can be used to provide context for the second prompt, allowing the language model to deliver a highly-curated response.",
16
16
"By chaining these prompts, the system can leverage the capabilities of the language model to generate more meaningful and contextual outputs."
Copy file name to clipboardExpand all lines: apigw-rest-stepfunctions-express-sync-bedrock-sam/example-pattern.json
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,17 @@
1
1
{
2
2
"title": "Prompt Chaining with Amazon API Gateway and AWS Step Functions.",
3
-
"description": "Prompt Chaining no-code example with Amazon API Gateway HTTP API, AWS Step Functions and Amazon Bedrock.",
3
+
"description": "Prompt Chaining no-code example with Amazon API Gateway REST API, AWS Step Functions and Amazon Bedrock.",
4
4
"language": "",
5
5
"level": "200",
6
6
"framework": "AWS SAM",
7
7
"introBox": {
8
8
"headline": "How it works",
9
9
"text": [
10
10
"The provided example demonstrates the deployment of a serverless application using the AWS Serverless Application Model (SAM) template.",
11
-
"This serverless application includes an Amazon API Gateway HTTP API endpoint that is connected to an AWS Step Functions state machine.",
11
+
"This serverless application includes an Amazon API Gateway REST API endpoint that is connected to an AWS Step Functions state machine.",
12
12
"The state machine is designed to invoke an Express workflow synchronously.",
13
13
"It utilizes AWS Step Functions' intrinsic functions to chain two prompts, which are then used to invoke the Amazon Bedrock language model.",
14
-
"The output from the state machine execution is returned to the client within 29 seconds through the HTTP API.",
14
+
"The output from the state machine execution is returned to the client within 29 seconds through the REST API.",
15
15
"This no-code example showcases how the results from the first prompt can be used to provide context for the second prompt, allowing the language model to deliver a highly-curated response.",
16
16
"By chaining these prompts, the system can leverage the capabilities of the language model to generate more meaningful and contextual outputs."
0 commit comments