/nestjs-gpt-action-api-template

Boilerplate project to quickly launch a NestJS powered API for ChatGPT GPT actions

Primary LanguageTypeScriptApache License 2.0Apache-2.0

NestJS GPT Action API Template

Social Image with alt text

Installation

git clone https://github.com/pairprog/nestjs-gpt-action-template.git
cd nestjs-gpt-action-template
pnpm install
cp .env.example .env

Configure

  • In package.json > scripts > tunnel , change domain_name with yours
  • In .env
    • Change BASE_URL with yours
    • (Not required) Set SENTRY_DSN to enable Sentry error reporting
  • In main.ts
    • Set the Title and Description of the API

Run Locally

pnpm run tunnel

And in another terminal window

pnpm run start:dev
# or
pnpm run start:debug
  • The OpenAPI schema's URL will be shown in the terminal window in blue.
    • Copy it
    • In "actions" section of your GPT app:
      • Click "Create New Action"
      • Click on "Import from URL"
      • Paste the URL.
      • Click "Import"

Add an action

Other

OpenAI specific headers

OpenAI provides identifying information with each query. You can access them in routes using the ChatGptHeaders decorator

@Post('/my/path')
function myPath(@ChatGptHeaders() headers: ChatGptHeaders) {
  // ...
}