Skip to content

promptfoo/demo-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demo App - ChatGPT Wrapper Chat API

This is a basic Express application with a /chat endpoint that forwards messages to ChatGPT's API. The purpose is to demonstrate Promptfoo's capabilities including identifying and remediating vulnerabilities. The system prompt is intentionally weak. This is not intended for production use in any way.

Setup

  1. Install dependencies:
npm install
  1. Create a .env file in the root directory

  2. Add your OpenAI API key to .env:

OPENAI_API_KEY=your_openai_api_key_here
PORT=4000

Running the Application

Start the server:

npm start

For development with auto-reload:

npm run dev

The server will start on port 4000 (or the port specified in your .env file).

API Endpoints

POST /chat

Send a message to ChatGPT.

Request Body:

{
  "message": "Hello, how are you?"
}

Response:

{
  "response": "I'm doing well, thank you for asking!"
}

GET /health

Health check endpoint.

Response:

{
  "status": "ok"
}

Error Handling

The API returns appropriate HTTP status codes:

  • 400 - Missing or invalid message field
  • 401 - Invalid OpenAI API key
  • 429 - Rate limit exceeded
  • 500 - Server error or missing API key configuration

About

Basic ChatGPT wrapper start example

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published