Skip to content

Latest commit

 

History

History
138 lines (101 loc) · 10.9 KB

README.md

File metadata and controls

138 lines (101 loc) · 10.9 KB

OpenAI Code Samples

FullStackWithLawrence
OpenAI LangChain Amazon AWS ReactJS Python Terraform
Release Notes GHA pushMain Status AGPL License hack.d Lawrence McDaniel

A React + AWS Serverless full stack implementation of the 30 example applications found in the official OpenAI API documentation. Now with LangChain!

Marv

IMPORTANT DISCLAIMER: AWS' Lambda service has a hard 29-second timeout. OpenAI API calls often take longer than this, in which case the AWS API Gateway endpoint will return a 504 "Gateway timeout error" response to the React client. This happens frequently with apps created using chatgpt-4. Each of the 30 OpenAI API example applications are nonetheless implemented exactly as they are specified in the official documentation.

ReactJS chat application

Complete documentation is located here.

React app that leverages Vite.js, @chatscope/chat-ui-kit-react, and react-pro-sidebar.

Webapp Key features

  • robust, highly customizable chat features
  • A component model for implementing your own highly personalized OpenAI apps
  • Skinnable UI for each app
  • Includes default assets for each app
  • Small compact code base
  • Robust error handling for non-200 response codes from the custom REST API
  • Handles direct text input as well as file attachments
  • Info link to the OpenAI API official code sample
  • Build-deploy managed with Vite

Custom OpenAI REST API Backend

Complete documentation is located here.

A REST API implementing each of the 30 example applications from the official OpenAI API Documentation using a modularized Terraform approach. Leverages OpenAI's suite of AI models, including GPT-3.5, GPT-4, DALL·E, Whisper, Embeddings, and Moderation.

API Key features

  • Built on the OpenAI API Python Library
  • LangChain enabled API endpoints where designated.
  • Customizable. Modularized endpoints that only take a few lines of code each.
  • Highly secure. Your OpenAI API key is stored in a local .env file, and is kept safe during development, build and deployment to production.
  • Implements excellent CloudWatch logs for Lambda as well as API Gateway
  • Fully automated and parameterized Terraform build
  • well documented code plus supplemental documentation resources as well as detailed documentation on each URL endpoint.
  • Low-cost AWS serverless implementation using AWS API Gateway and AWS Lambda; free or nearly free in most cases
  • Robust, performant and infinitely scalable
  • Fast build time; usually less than 60 seconds to fully implement
  • Includes both Python and Node.js Lambda examples
  • Deploy https to a custom domain
  • Preconfigured Postman files for testing
  • includes AWS API Gateway usage policy and api key
  • Full CORS configuration

Requirements

Documentation

Detailed documentation for each endpoint is available here: Documentation

Examples of Code Management Best Practices

This repo is referenced by multiple YouTube videos, including various tutorials about good coding practices and good code management. Of note:

Automations

  • Automated Pull Requests: Github Actions are triggered on pull requests to run any of several different kinds of technology-specific unit tests depending on the contents of the commits included in the PR.
  • python-dotenv for storing sensitive data for local development
  • .gitignore ensures that no sensitive nor useless data accidentally gets pushed to GitHub.
  • tox.ini file for configuring behaviors of Python testing tools
  • GitHub Actions automates unit testing, semantic release rule checking, and dependabot actions.
  • GitHub Secrets to provide sensitive data to Github Actions workflows
  • GitHub Issues
  • Makefile automates procedures like init, build, test, release and linting for Python, ReactJS and Terraform.
  • pre-commit automatically enforces a multitude of code quality, coding style and security policies.
  • Dependabot automatically updates the version pins of code library dependencies for Python, ReactJS and Terraform.
  • Unit Tests are automated and can be invoked
    • manually from the command line
    • manually from GitHub Actions
    • automatically by Dependabot.
  • Mergify automates processing of bot-created pull requests
  • Semantic Release automates version releases as well as maintains the change log for the repo.
  • Change Log

Linters and Formatters

Linters and formatters are tools used in programming to analyze and improve the quality of code. This project leverages several, including:

Code Formatting

  • Prettier: an opinionated code formatter that supports many file formats and languages. This project leverages Prettier to standardize formatting of md, css, json, yml, js, jsx and Typescript files.
  • Black: an opinionated code formatter for Python which is compatible with PEP 8 and the Python Style Guide.
  • isort: a Python utility that sorts imports alphabetically, and automatically, separated into sections and by type.

Code Analysis

  • ESLint: an open source project that helps you find and fix problems with your JavaScript and JSX code.
  • Flake8: provides Python syntax checking, naming style enforcement, code style enforcement, and cyclomatic complexity analysis.
  • pylint: a static code analyser for Python. It analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells, and can make suggestions about how the code could be refactored.
  • bandit: a tool designed to find common security issues in Python code.

Pre-commit hooks

  • pre-commit Hooks: scripts that run automatically before each commit is made to a repository, checking your code for embedded passwords, errors, issues, and any of a multitude of configurable policies that you can optionally enforce. They're part of the git hooks system, which allows you to trigger actions at certain points in git's execution. This project uses many Hooks. See pre-commit-config.yaml.
  • codespell: fixes common misspellings in text files. It's designed primarily for checking misspelled words in source code, but it can be used with other files as well.

Support

To get community support, go to the official Issues Page for this project.

Contributing

We welcome contributions! There are a variety of ways for you to get involved, regardless of your background. In addition to Pull requests, this project would benefit from contributors focused on documentation and how-to video content creation, testing, community engagement, and stewards to help us to ensure that we comply with evolving standards for the ethical use of AI.

For developers, please see:

You can also contact Lawrence McDaniel directly.