Add GPT Chat to Base Docs (#323)

* Install fetch event source to handle SSEs

* Add docs chatbot modal UI.

* Update Modal and Icon components.

* Add no scroll class.

* Add DocChat component.

* Installed fetch event source.

* Add light theme styles. Clean up code.

* Remove unneeded React import.

* Adjust copy as deployment test change.

* Undo test changes.

* Add Mendable URLs to CSP.

* Add markdown rendering support for chatbot responses.

* Yarn lock update.

* Adjust modal layout spacing.

* Fix chatbot modal styling for mobile screens.

* Add UI for rating bot responses.

* Temporarily disable response rating feature.

* Add server API endpoint for processing Base GPT response rating requests.

* Update csp for new API version.

* Add CCA events for GPT interactions. Fix id data types.

* Swap in prod client-side API keys.

* Use session storage for conversation data.

* Swap in prod client-side API keys.

* Remove unneeded log.

* Simplify state updates.

* Replace dangerouslySetInnerHTML with useRef innerHTML.

* Updated yarn.lock

* Swap in test API key for dev.

* Fix typo.

* Swap in prod client-side key.

* Temporarily remove sources. Adjust scroll behavior. Adjust modal close handler. Update API keys.
This commit is contained in:
jacob-moore-cb
2024-03-07 13:20:35 -08:00
committed by GitHub
parent 691cfab3fb
commit 8fbeb790e3
24 changed files with 1469 additions and 18 deletions

View File

@@ -3,6 +3,11 @@ const path = require('path');
const basicAuth = require('express-basic-auth');
const fs = require('fs');
const notFound = require('./404.js');
const bodyParser = require('body-parser');
const fetch = require('node-fetch');
const dotenv = require('dotenv');
dotenv.config();
const unless = function (path, middleware) {
return function (req, res, next) {
@@ -18,10 +23,32 @@ const app = express();
app.use(express.static('static'));
app.use(bodyParser.json());
app.get('/api/_health', (_, res) => {
res.sendStatus(200);
});
app.post('/api/rateMessage', (req, res) => {
const { message_id, rating_value } = req.body;
const data = {
api_key: process.env.MENDABLE_SERVER_API_KEY,
message_id,
rating_value,
};
fetch('https://api.mendable.ai/v1/rateMessage', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then((response) => res.json(response))
.catch((error) => res.status(400));
});
app.get('/base-camp', (req, res) => {
res.redirect('base-camp/docs/welcome');
});
@@ -73,6 +100,9 @@ const contentSecurityPolicy = {
'https://cca-lite.coinbase.com', // CCA Lite
'https://*.algolia.net', // Algolia Search
'https://*.algolianet.com', // Algolia Search
'https://api.mendable.ai/v1/newConversation', // Mendable API
'https://api.mendable.ai/v1/mendableChat', // Mendable API
'https://api.mendable.ai/v1/rateMessage', // Mendable API
],
'frame-src': ["'self'", 'https://player.vimeo.com', 'https://verify.walletconnect.org'],
};