This project is a Node.js Express server that uses the OpenAI API to create a chatbot simulating an expert mechanic with over 30 years of experience. The chatbot compresses conversation history to reduce token usage while maintaining context.
- Compresses conversation history to save tokens
- Uses GPT-4 for generating expert mechanic responses
- Persists conversation context across user sessions
- Node.js
- Express
- Axios
- OpenAI API
- dotenv
- Node.js (>= 14.x)
- npm or yarn
- OpenAI API key
git clone https://github.com/your-username/gpt4-mechanic-chatbot.git
cd gpt4-mechanic-chatbot
npm install
# or
yarn install
-
Create a
.env
file in the root directory with the following content:PORT=3000
-
Save your OpenAI API key in a file named
openai.token
inside the~/.config
directory. If the directory does not exist, create it:mkdir -p ~/.config echo "your-openai-api-key" > ~/.config/openai.token
To start the server, run the following command:
npm run dev
# or
yarn dev
This command will use nodemon
to run the server with the --experimental-modules
flag for handling ES modules.
Open your browser and go to http://localhost:3000
.
Initiates a conversation or continues an existing session with the chatbot.
{
"sessionId": "unique-session-id",
"message": "User's message"
}
{
"response": "AI's response"
}
Simple health check endpoint.
- Add authentication and authorization
- Improve error handling and validation
- Implement more sophisticated session management