Skip to content

Commit

Permalink
🚪 Implement chat endpoint for ChatGPT API
Browse files Browse the repository at this point in the history
  • Loading branch information
hidragos committed Mar 22, 2023
1 parent 891c967 commit c846943
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 26 deletions.
36 changes: 30 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4",
"axios": "^0.26.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.26.1",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"openai": "^3.2.1"
"gpt-turbo": "^1.6.0",
"openai": "^3.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
33 changes: 22 additions & 11 deletions server/index.js
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}`);
});
3 changes: 3 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}

0 comments on commit c846943

Please sign in to comment.