mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

* WIP: basic route for file downloads and file strategy for generating readablestream to pipe as res * chore(DALLE3): add typing for OpenAI client * chore: add `CONSOLE_JSON` notes to dotenv.md * WIP: first pass OpenAI Assistants File Output handling * feat: first pass assistants output file download from openai * chore: yml vs. yaml variation to .gitignore for `librechat.yml` * refactor(retrieveAndProcessFile): remove redundancies * fix(syncMessages): explicit sort of apiMessages to fix message order on abort * chore: add logs for warnings and errors, show toast on frontend * chore: add logger where console was still being used
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
const axios = require('axios');
|
|
const denyRequest = require('./denyRequest');
|
|
const { logger } = require('~/config');
|
|
|
|
async function moderateText(req, res, next) {
|
|
if (process.env.OPENAI_MODERATION === 'true') {
|
|
try {
|
|
const { text } = req.body;
|
|
|
|
const response = await axios.post(
|
|
process.env.OPENAI_MODERATION_REVERSE_PROXY || 'https://api.openai.com/v1/moderations',
|
|
{
|
|
input: text,
|
|
},
|
|
{
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${process.env.OPENAI_MODERATION_API_KEY}`,
|
|
},
|
|
},
|
|
);
|
|
|
|
const results = response.data.results;
|
|
const flagged = results.some((result) => result.flagged);
|
|
|
|
if (flagged) {
|
|
const type = 'moderation';
|
|
const errorMessage = { type };
|
|
return await denyRequest(req, res, errorMessage);
|
|
}
|
|
} catch (error) {
|
|
logger.error('Error in moderateText:', error);
|
|
const errorMessage = 'error in moderation check';
|
|
return await denyRequest(req, res, errorMessage);
|
|
}
|
|
}
|
|
next();
|
|
}
|
|
|
|
module.exports = moderateText;
|