This repository contains two projects:
- A simple Node.js service that communicates with OpenAI's chat endpoint
- MODO - A hackathon project for assessment generation
The MODO project is located in the project directory and consists of a React-based frontend and an Express-based backend.
- Navigate to the server directory:
cd project/server- Install dependencies:
yarn install- Create a
.envfile with your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
- Start the development server:
yarn devThe backend will be available at http://localhost:3000
- Navigate to the project directory:
cd project- Install dependencies:
yarn install- Start the development server:
yarn devThe frontend will be available at http://localhost:5173
Note: Both the frontend and backend need to be running simultaneously for the full application to work.
A simple Node.js service that communicates with OpenAI's chat endpoint using Koa and node-fetch.
A very basic chat UI was added as an easy way to add prompts and see how OpenAI reacts. System prompts can be added to the messages array in public/app.js. The conversation is stored in memory, so refreshing the page restarts the conversation but the system prompts will always be there.
- Install dependencies:
yarn install- Create a
.envfile in the root directory with your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
PORT=3000
- Start the server:
node src/server.jsUse a web browser and navigate to localhost:3000 and chat away
POST /chat
Request body:
{
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
],
"stream": false // Optional, defaults to false
}The messages array should follow OpenAI's chat format with role and content for each message.
If stream is set to true, the response will be streamed as Server-Sent Events (SSE).
// Non-streaming request
const response = await fetch('http://localhost:3000/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
messages: [
{
role: 'user',
content: 'Hello, how are you?'
}
]
})
});
// Streaming request
const response = await fetch('http://localhost:3000/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
messages: [
{
role: 'user',
content: 'Hello, how are you?'
}
],
stream: true
})
});