-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚪 Implement chat endpoint for ChatGPT API
- Loading branch information
Showing
4 changed files
with
65 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
require('dotenv').config(); | ||
const express = require('express'); | ||
import { Conversation } from 'gpt-turbo'; | ||
import express from 'express'; | ||
import dotenv from 'dotenv'; | ||
import cors from 'cors'; | ||
|
||
dotenv.config(); | ||
|
||
const app = express(); | ||
const port = 3500; | ||
app.use(express.json()); | ||
app.use(cors()); | ||
|
||
app.post('/chat', async (req, res) => { | ||
const { prompt } = req.body; | ||
const conversation = new Conversation({ | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
|
||
const response = await conversation.prompt(prompt); | ||
|
||
// Simple hello world get request | ||
app.get('/hello', (req, res) => { | ||
const openai = process.env.OPENAI_API_KEY; | ||
res.send(`key`+ openai); | ||
res.json(response); | ||
}); | ||
|
||
// Start the server | ||
app.listen(port, () => { | ||
console.log(`Example app listening at http:https://localhost:${port}`); | ||
}); | ||
const PORT = process.env.PORT || 3500; | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Server is running on port ${PORT}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |