Skip to content

AWS Amplify Gen 2 Connected to OpenAI API Assitant

Notifications You must be signed in to change notification settings

y3rsh/amplify-example

Repository files navigation

React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

  • Configure the top-level parserOptions property like this:
export default {
  // other rules...
  parserOptions: {
    ecmaVersion: 'latest',
    sourceType: 'module',
    project: ['./tsconfig.json', './tsconfig.node.json'],
    tsconfigRootDir: __dirname,
  },
}
  • Replace plugin:@typescript-eslint/recommended to plugin:@typescript-eslint/recommended-type-checked or plugin:@typescript-eslint/strict-type-checked
  • Optionally add plugin:@typescript-eslint/stylistic-type-checked
  • Install eslint-plugin-react and add plugin:react/recommended & plugin:react/jsx-runtime to the extends list

steps

https://docs.amplify.aws/gen2/start/quickstart/vite-react-app/

  1. nvs select 20.11.1 (current LTS version of Node.js) https://nodejs.org/en
  2. can switch to pnpm, just have to override the build
  3. curl -fsSL https://get.pnpm.io/install.sh | sh - https://npm.io/installation
  4. navigate to the directory where you want to create the project
  5. npm create vite@latest react-amplify-gen2 -- --template react-ts
  6. cd react-amplify-gen2
  7. npm install
  8. npm create amplify@beta
  9. setup credentials https://docs.amplify.aws/gen2/start/account-setup/
  10. npm amplify configure profile --name dev-personal-josh
  11. enter the access key and secret key and use us-east-1 as the region
  12. for a real team use https://docs.amplify.aws/gen2/start/account-setup/#configure-iam-identity-center
  13. npm amplify sandbox --profile dev-personal-josh
  14. The given region has not been bootstrapped. Sign in to console as a Root user or Admin to complete the bootstrap process and re-run the amplify sandbox command.
  15. This auto opened the browser to the AWS console and I was already logged in as root user so I just clicked the "Complete bootstrap" button
  16. run the local dev server npm run dev
  17. npm amplify sandbox --profile dev-personal-josh
  18. much output ✨ Deployment time: 253.1s
  19. now we are running and amplify is watching for changes
  20. followed the tutorial https://docs.amplify.aws/gen2/start/quickstart/vite-react-app/
  21. followed the steps and the backend is now configured for user authentication
  22. https://docs.amplify.aws/gen2/start/quickstart/vite-react-app/#build-ui
  23. npm install @aws-amplify/ui-react
  24. lint the project npm run lint
  25. build npm run build

Secrets

// npm amplify sandbox secret set openAiApiKey --profile dev-personal-josh // npm amplify sandbox secret set openAiAssistantId --profile dev-personal-josh can call get to make sure they are correct don't seem to be deleted when you `npm amplify sandbox delete --profile dev-personal-josh For the branch deployment these are managed in the Amplify Dashboard.

openai-test.js

export OPENAI_API_KEY='your-api-key-here' node openai-test.js

Next steps

  • setup OpenAI assistant
  • call my openAI assistant with secret
  • store assistant conversation as a user attribute
  • display assistant conversation
  • try the CI/CD branch deployments
  • look at the telemetry/logs etc. in AWS console (only available once deployed)