@baselinejs/ai-stack
v0.0.6
Published
A AI chat app built on Baseline
Downloads
51
Keywords
Readme
Baseline AI Stack
BaselineJS AI Stack is an open-source, fullstack TypeScript, serverless first framework designed to make building cloud native applications easier. This is a customized version of BaselineJS that demonstrates how Bedrock AI can be integrated into the BaselineJS framework in a working application.
If you like BaselineJS give us a ⭐️
Baseline | Website | Documentation | Discord | LinkedIn | YouTube
Startups, want $10k USD of AWS Credits to Get Started? Apply Here
Getting Started
You have 3 different options to setup Baseline AI Stack:
Workshop Form
A simplified deployment to try out the Baseline AI Stack can be found at Baseline AI Workshop. This will guide you through the process of deploying the Baseline AI Stack to your AWS account. This is the easiest no code way to get started.
Quickstart
npx @baselinejs/quickstart-ai
and follow the setup instructions
Setup
Alternatively, follow the setup instructions below.
- Install requirements
pnpm run install:requirements
npx @baselinejs/create-ai
pnpm install
pnpm run setup
to name your project and set the regionpnpm run aws:profile
to setup your AWS credentials profile (if you have issues please update aws cli)pnpm run deploy:staging
to deploy api & chatpnpm run add:user:staging
to add a chat user to the applicationpnpm run urls:staging
To see your project URLs
Setup the AI settings
packages/api/src/baseblocks/chat/chat-api.ts
contains the settings for the AI model. Set them to the desired values. Deploy the application again after changing these settings with pnpm run deploy:staging
.
The settings are as follows:
const MODEL_REGION = 'ap-southeast-2';
const MODEL_ID = ModelIdentifiers.MISTRAL_MISTRAL_7B_INSTRUCT_V0;
const MAX_INPUT_TOKENS = 100000;
const MAX_OUTPUT_TOKENS = 100000;
const MAX_COMPUTE_MS = 1000000;
const MAX_TOTAL_TOKENS = 0; // No limit
const GLOBAL_MAX_INPUT_TOKENS = 1000000;
const GLOBAL_MAX_OUTPUT_TOKENS = 1000000;
const GLOBAL_MAX_COMPUTE_MS = 10000000;
const GLOBAL_MAX_TOTAL_TOKENS = 0; // No limit
Explanation of the settings:
MODEL_REGION
: The region of the AI model.MODEL_ID
: The ID of the AI model. See the Bedrock AI docs for list.MAX_INPUT_TOKENS
: The maximum number of tokens in the input to the AI model.MAX_OUTPUT_TOKENS
: The maximum number of tokens in the output from the AI model.MAX_COMPUTE_MS
: The maximum time in milliseconds the AI model can take to compute.MAX_TOTAL_TOKENS
: The maximum number of tokens in the input and output combined.GLOBAL_MAX_INPUT_TOKENS
: The maximum number of tokens in the input to the AI model for all users combined.GLOBAL_MAX_OUTPUT_TOKENS
: The maximum number of tokens in the output from the AI model for all users combined.GLOBAL_MAX_COMPUTE_MS
: The maximum time in milliseconds the AI model can take to compute for all users combined.GLOBAL_MAX_TOTAL_TOKENS
: The maximum number of tokens in the input and output combined for all users combined.
Set any of them to 0 to disable the limit.
The user and global limits will be enforced by the API. If the limits are exceeded, the API will return an error. The user limits are enforced per user, and the global limits are enforced for all users combined. A DynamoDB table is used to store the usage of each user as well as the default values, that way any user can be tracked and the limits can be enforced as well as modified.
Local Requirements
These must be installed before following the setup instructions.
- Macos/Linux OS/Windows Subsystem for Linux
- Node.js v20 (v20 or higher) & [email protected] or higher (we suggest installing and using nvm) follow instructions in the link to install, you will generally need to create a new terminal session after installing. If you already have nvm update it before proceeding.
- If nvm is installed you can switch versions with
nvm install 20 && nvm use 20 && nvm alias default 20 && nvm install-latest-npm
- If not using nvm you can manually install node and npm, download from https://nodejs.org/en/download/ alternatively use the operating system package manager or any other appropriate tool to install node
- Current versions can be checked with
node -v
,npm -v
- If nvm is installed you can switch versions with
- pnpm version 9, version can be checked with
pnpm -v
, install withnpm install -g pnpm@9
or other methods - AWS CLI v2
- Homebrew, for Mac users only, follow install instructions here
- jq for extracting Cloudformation outputs
- Install on mac
brew install jq
- Install on Linux
sudo yum install jq
orsudo apt-get install jq
, or other appropriate methods
- Install on mac
- Java Runtime Environment (JRE) version 8.x or newer, it is only required for DynamoDB local
- Install on mac
brew install java
- Install on linux
sudo yum install java
orsudo apt-get install openjdk-8-jdk
, or other appropriate methods - DynamoDB local will automatically install in the project when the api is started, java needs to installed before this occurs
- Install on mac
- curl which is used in some of the bash scripts, curl install instructions
- An IDE such as Visual Studio Code
- Node.js v20 (v20 or higher) & [email protected] or higher (we suggest installing and using nvm) follow instructions in the link to install, you will generally need to create a new terminal session after installing. If you already have nvm update it before proceeding.
- Internet connectivity
- AWS Account https://aws.amazon.com/getting-started/
- IAM credentials https://docs.aws.amazon.com/cli/latest/userguide/getting-started-prereqs.html#getting-started-prereqs-iam be sure to follow Security best practices in IAM
Experimental Requirements Installation
Alternatively, try the experimental requirements installation script. Use at your own risk.
If you are starting a new Baseline project.
curl -o- https://raw.githubusercontent.com/Baseline-JS/core/main/scripts/experimental-install-requirements.sh | bash
or
wget -qO- https://raw.githubusercontent.com/Baseline-JS/core/main/scripts/experimental-install-requirements.sh | bash
If you are joining an existing Baseline project
pnpm run install:requirements
Run Locally
If the project is already setup and you are trying run the project locally make sure you run pnpm run aws:profile
first so that you have the correct credentials for AWS configured locally.
Commands
Start the api and chat in their own terminal windows/tabs with the following commands.
pnpm run generate:env:local
to generate the env files for the frontend clientspnpm run start:api
pnpm run start:chat
Running locally Limitations
- API, Chat: No S3, you will need to rely on AWS staging S3
- API: No local Cognito Authorizer, the deployed staging cognito can be used (see
packages/api/serverless.yml
) or the payload set byAUTHORIZER
inpackages/api/scripts/run-api-local.sh
. - Chat: Cognito UI relies on an active AWS Cognito user pool, use deployed staging
Deploy a Change
Swap staging
to prod
to deploy to production. All environment variables will be automatically set in the process.
pnpm run deploy:staging
to deploy api and chat
Remove Stack
To destroy the deployed cloudformation stacks so it is no longer on AWS run pnpm run remove:staging
. This will likely destroy all data associated with the application.
Major Components
- 🚀 API
- 🌐 React User Application
- ⚙️ CI/CD
- 🔧 Developer Tooling
- 🔒 Authentication
- 🔄 Multiple Environments
- 💻 Run Locally
- 🏗️ Infrastructure as Code (IaC)
- 📦 Managed Environment Variables
- ✨ Baseline Commands
Technology
- 🎁 Package Management: Pnpm + Monorepo
- 🔨 Language & Build: TypeScript + ESBuild
- 🖼 Frontend: React + Vite
- ⚙️ Backend: NodeJS + Express
- 🎨 Linting & Formatting: Prettier + Eslint
- 🏗 IaC: AWS + Serverless Framework
- 🚀 Deploy: Local/Bitbucket/GitHub CI/CD
AWS Services
- Cognito
- S3
- Lambda
- DynamoDB
- CloudFormation
- Route53
- Systems Manager
- CloudFront
- API Gateway
- CloudWatch
- SNS
What can you build with Baseline?
- 🌐 SaaS Solutions: Build software-as-a-service solutions tailored to your audience.
- 🖥️ Web Applications: Develop responsive and scalable web applications.
- 🛒 Marketplaces: Launch and manage online marketplaces with ease.
- 📱 Mobile Applications: Create robust mobile apps for iOS and Android platforms.
- 💼🛍️ B2B/B2C Applications: Seamlessly cater to both business and consumer audiences.
- 🗄️ Headless CMS: Manage content efficiently using a headless content management system.
Benefits
- Serverless First
- Open source
- Full control
- Cost effective implementation
- Hosted in your own AWS account
- Uses popular technology
- Scales on demand
- Staging and production environments
- Runs locally
Baseline
If you would like to learn more about what we do please visit Baseline