This project runs a script that generates resources through an AWS CDK and deploys it with a Griptape Structure to invoke the Structure for use as a chatbot with the Gradio Interface in the Griptape Cloud. Deploying the resources creates both a DynamoDB table with AWS and creates a Griptape Structure in the Griptape Cloud. Once deployed, the user can call the Griptape Structure with the Griptape Cloud to invoke their structure.
You need:
-
An AWS Account
-
The aws-cli installed Follow the instructions for your OS.
-
AWS credentials or aws sso configured
-
To configure aws sso:
aws configure sso
Values for the SSO:
`SSO session name (Recommended): my-sso`
`SSO start URL [None]: <YourStartURL>`
`SSO region [None]: <YourRegion>`
`SSO registration scopes [None]: sso:account:access`
aws s3 ls --profile <YourProfileName>
You need:
- Node.js installed
This is necessary in order to install aws-cdk.
https://nodejs.org/en/download/package-manager
- The aws-cdk installed
npm install -g aws-cdk
To verify installation:
cdk --version
You need:
- Docker installed
You need:
You need:
- An Open AI account
- An Open AI API Key
To run the structure with Gradio, you need to clone and configure the Griptape Chat repository.
- Follow the instructions on the README
- Set the .env variables based on the repository of your structure.
GITHUB_REPO_OWNER=<your-owner>
GITHUB_REPO_NAME=<your-repo-name>
GITHUB_REPO_BRANCH=<your-branch>
STRUCTURE_FILE_PATH=<your-path-from-repo>
REQUIREMENTS_FILE_PATH=<your-path-from-repo>
- In your repository, add this configuration to your agent and pass a session_id when creating your agent.
conversation_memory=ConversationMemory(
driver=AmazonDynamoDbConversationMemoryDriver(
session=boto3.Session(
aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"],
aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"],
),
table_name=conversation_memory_table_name,
partition_key="id",
partition_key_value=session_id,
value_attribute_key="value",
)
)
- Update your structure with the parsing information at the bottom of the app.py - this is necessary for the way that Gradio passes in the session_id and inputs. Replace
init_structure
with your own agent creation method.
# TODO: Keep this logic for running your own structure
if __name__ == "__main__":
input_arg = sys.argv[1]
input_arg_dict = json.loads(input_arg)
agent = init_structure(input_arg_dict["session_id"])
agent.run(input_arg_dict["input"])
- Clone the Repository
git clone git!@github.com:griptape-ai/griptape-structure-chatbot.git
npm install
Create a .env file, and populate it accordingly to .env.example file. Do not forget to add your Griptape Cloud API Key.
GRIPTAPE_API_KEY=<YOUR_GRIPTAPE_CLOUD_API_KEY>
- Follow the Token provider configuration documentation for AWS IAM Identity Center
- Configure Token provider
aws configure sso-session
If necessary to sign into an IAM Identity Center session:
aws sso login --profile <your-profile-name>
- Export SSO credentials:
eval $(aws configure export-credentials --profile <profile> --format env)
npm run bootstrap
npm run deploy
This can only be accomplished after deploying the CDK Prerequisites:
- Go to IAM Dashboard
- Under Access Management go to Users
- Go to griptape-chatbot-user (Should exist if CDK has been deployed)
- Create an access key and save the values in the .env:
AWS_ACCESS_KEY_ID=<YourAccessKey>
AWS_SECRET_ACCESS_KEY=<YourSecretAccessKey>
Additional environment variables needed:
GT_CLOUD_BASE_URL=http://127.0.0.1:5000
http://127.0.0.1:5000 is the default for Skatepark, but you can change this when running gt skatepark start
Start in Skatepark:
gt skatepark start
Navigate to the directory of your structure:
gt skatepark register --main-file <StructureFilename>
Put your Structure ID in your Griptape Chat .env
GT_STRUCTURE_ID=<your-structure-id>
If you change any environment variables
gt skatepark build
After you deploy the structure
- Get the Structure ID from the Griptape Structure Chatbot: https://cloud.griptape.ai/structures
- Add additional environment variables in the Griptape Cloud
- Create any additional secrets necessary and add them to your structure in the Griptape Cloud.
- ex: Adding a Zenrows API Key
- Click
Create Secret
- Name:
Zenrows API Key
- Value:
<your-Zenrows-API-key-value>
- Name:
- Go to your structure and click
Add Variable
.- Name:
ZENROWS_API_KEY
- Source:
Secret
- Value: select
Zenrows API Key
from the dropdown menu.
- Name:
- Click
- ex: Adding a Zenrows API Key
- Add any environment variables that your structure requires that haven't already been set by clicking
Add Variable
and setting the source toManual
.- ex: Adding a Knowledge Base
- Click
Add Variable
- Name:
KNOWLEDGE_BASE_ID
- Source:
Manual
- Value:
<your-kb-id>
- Name:
- Click
- ex: Adding a Knowledge Base
- Create any additional secrets necessary and add them to your structure in the Griptape Cloud.
- Put the Structure ID in your .env in Griptape Chat
GT_STRUCTURE_ID=<your-structure-id>
In your CLI in the Griptape Chat folder
poetry run python app.py
Invoke the endpoint as follows:
- Retrieve a session_id
curl --json '{"operation": "create_session"}' https://<YOUR_LAMBDA_URL_ID>.lambda-url.<REGION>.on.aws/
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testsnpx cdk deploy
deploy this stack to your default AWS account/regionnpx cdk diff
compare deployed stack with current statenpx cdk synth
emits the synthesized CloudFormation template