Skip to content

Commit

Permalink
Make Step functions vs Bedrock flows techniques clear, add tests for …
Browse files Browse the repository at this point in the history
…Bedrock flows stacks
  • Loading branch information
clareliguori committed Jan 18, 2025
1 parent 270d88c commit 0969d63
Show file tree
Hide file tree
Showing 53 changed files with 253 additions and 133 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ updates:
open-pull-requests-limit: 10
versioning-strategy: increase
- package-ecosystem: pip
directory: "/techniques/functions/parse_json_response"
directory: "/techniques_step_functions/functions/parse_json_response"
schedule:
interval: monthly
open-pull-requests-limit: 10
versioning-strategy: increase
- package-ecosystem: pip
directory: "/techniques-bedrock-flows/functions/parse_json_response"
directory: "/techniques_bedrock_flows/functions/parse_json_response"
schedule:
interval: monthly
open-pull-requests-limit: 10
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ jobs:
pip install -r requirements.txt
pip install -r requirements-dev.txt
pytest test_cdk_stacks.py
cd techniques_bedrock_flows
pytest
cd ../techniques_step_functions
pytest
5 changes: 3 additions & 2 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ python3 -m venv .venv
source .venv/bin/activate
find . -name requirements.txt | xargs -I{} pip install -r {}
find . -name requirements-dev.txt | xargs -I{} pip install -r {}
```
After this initial setup, you only need to run `source .venv/bin/activate` to use the virtual env for further development.

## Deploy the technique examples (AWS Step Functions)

Deploy all the stacks:
```
cd techniques
cd techniques_step_functions
cdk deploy --app 'python3 technique_stacks.py' --all
```
Expand Down Expand Up @@ -53,7 +54,7 @@ Run an example input through each flow example. Edit the files in the `test-inpu

Deploy all the stacks:
```
cd techniques-bedrock-flows
cd techniques_bedrock_flows
cdk deploy --app 'python3 technique_stacks.py' --all
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Both Bedrock and Step Functions are serverless, so you don't have to manage any

This repository illustrate many prompt chaining techniques that can be orchestrated by Step Functions.
The chaining techniques are described below with AWS CDK sample code snippets.
The full code can be found in the [techniques directory](techniques/).
The full code can be found in the [techniques_step_functions directory](techniques_step_functions/).

### Model invocation

Expand Down
2 changes: 1 addition & 1 deletion functions/generic/parse_json_response/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jsonschema==4.23.0
jsonschema==4.17.3
20 changes: 18 additions & 2 deletions pipeline/pipeline_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
},
"build": {
"commands": [
"cd techniques/",
"cd techniques_step_functions/",
"cdk deploy --app 'python3 technique_stacks.py' --all --require-approval=never",
"cd ../techniques_bedrock_flows/",
"cdk deploy --app 'python3 technique_stacks.py' --all --require-approval=never",
]
},
Expand Down Expand Up @@ -182,7 +184,8 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
"phases": {
"build": {
"commands": [
"cd techniques/",
# Test Step Functions examples
"cd techniques_step_functions/",
"./run-test-execution.sh ModelInvocation",
"sleep 15",
"./run-test-execution.sh PromptTemplating",
Expand All @@ -201,6 +204,19 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
"./run-test-execution.sh AwsServiceInvocation",
"sleep 15",
"./run-test-execution.sh Validation",
# Test Bedrock Flows examples
"cd ../techniques_bedrock_flows/",
"python3 run-test-execution.py ModelInvocation",
"sleep 15",
"python3 run-test-execution.py PromptTemplating",
"sleep 15",
"python3 run-test-execution.py SequentialChain",
"sleep 15",
"python3 run-test-execution.py ParallelChain",
"sleep 15",
"python3 run-test-execution.py ConditionalChain",
"sleep 15",
"python3 run-test-execution.py Map",
]
},
},
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion techniques/functions/parse_json_response/requirements.txt

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jsonschema==4.17.3
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from constructs import Construct


class ConditionalChain(Stack):
class FlowsConditionalChain(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import json


class MapChain(Stack):
class FlowsMapChain(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from constructs import Construct


class ModelInvocation(Stack):
class FlowsModelInvocation(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from constructs import Construct


class ParallelChain(Stack):
class FlowsParallelChain(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from constructs import Construct


class PromptTemplating(Stack):
class FlowsPromptTemplating(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from constructs import Construct


class SequentialChain(Stack):
class FlowsSequentialChain(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@
App,
Environment,
)
from stacks.model_invocation import ModelInvocation
from stacks.prompt_templating import PromptTemplating
from stacks.sequential_chain import SequentialChain
from stacks.parallel_chain import ParallelChain
from stacks.conditional_chain import ConditionalChain
from stacks.map_chain import MapChain
from stacks.model_invocation import FlowsModelInvocation
from stacks.prompt_templating import FlowsPromptTemplating
from stacks.sequential_chain import FlowsSequentialChain
from stacks.parallel_chain import FlowsParallelChain
from stacks.conditional_chain import FlowsConditionalChain
from stacks.map_chain import FlowsMapChain
import os


app = App()
env = Environment(account=os.environ["CDK_DEFAULT_ACCOUNT"], region="us-west-2")
ModelInvocation(
FlowsModelInvocation(
app,
"Techniques-Flows-ModelInvocation",
env=env,
)
PromptTemplating(
FlowsPromptTemplating(
app,
"Techniques-Flows-PromptTemplating",
env=env,
)
SequentialChain(
FlowsSequentialChain(
app,
"Techniques-Flows-SequentialChain",
env=env,
)
ParallelChain(
FlowsParallelChain(
app,
"Techniques-Flows-ParallelChain",
env=env,
)
ConditionalChain(
FlowsConditionalChain(
app,
"Techniques-Flows-ConditionalChain",
env=env,
)
MapChain(
FlowsMapChain(
app,
"Techniques-Flows-Map",
env=env,
Expand Down
81 changes: 81 additions & 0 deletions techniques_bedrock_flows/test_bedrock_flows_techniques_stacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import aws_cdk as cdk
from aws_cdk.assertions import Template

from stacks.model_invocation import FlowsModelInvocation
from stacks.prompt_templating import FlowsPromptTemplating
from stacks.sequential_chain import FlowsSequentialChain
from stacks.parallel_chain import FlowsParallelChain
from stacks.conditional_chain import FlowsConditionalChain
from stacks.map_chain import FlowsMapChain


def test_techniques_bedrock_flows_model_invocation_stack_synthesizes_properly():
app = cdk.App()

test_stack = FlowsModelInvocation(
app,
"TestStack",
)

# Ensure the template synthesizes successfully
Template.from_stack(test_stack)


def test_techniques_bedrock_flows_prompt_templating_stack_synthesizes_properly():
app = cdk.App()

test_stack = FlowsPromptTemplating(
app,
"TestStack",
)

# Ensure the template synthesizes successfully
Template.from_stack(test_stack)


def test_techniques_bedrock_flows_sequential_chain_stack_synthesizes_properly():
app = cdk.App()

test_stack = FlowsSequentialChain(
app,
"TestStack",
)

# Ensure the template synthesizes successfully
Template.from_stack(test_stack)


def test_techniques_bedrock_flows_parallel_chain_stack_synthesizes_properly():
app = cdk.App()

test_stack = FlowsParallelChain(
app,
"TestStack",
)

# Ensure the template synthesizes successfully
Template.from_stack(test_stack)


def test_techniques_bedrock_flows_conditional_chain_stack_synthesizes_properly():
app = cdk.App()

test_stack = FlowsConditionalChain(
app,
"TestStack",
)

# Ensure the template synthesizes successfully
Template.from_stack(test_stack)


def test_techniques_bedrock_flows_map_chain_stack_synthesizes_properly():
app = cdk.App()

test_stack = FlowsMapChain(
app,
"TestStack",
)

# Ensure the template synthesizes successfully
Template.from_stack(test_stack)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jsonschema==4.17.3
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 0969d63

Please sign in to comment.