feat: solution for 'Повторный экзамен: FAQ-бот — ChromaDB + один MCP-tool'
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
const moderate = require('moderate-censor');
|
||||
|
||||
/**
|
||||
* Moderates user input using moderate-censor.
|
||||
* @param {string} text
|
||||
* @returns {Promise<{allowed: boolean, reasons: string[]}>}
|
||||
*/
|
||||
async function moderateInput(text) {
|
||||
try {
|
||||
const result = await moderate.moderate(text);
|
||||
if (result.isAllowed) {
|
||||
return { allowed: true, reasons: [] };
|
||||
} else {
|
||||
return { allowed: false, reasons: result.reasons || [] };
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Moderation error:', err);
|
||||
// If moderation fails, default to allowing to avoid blocking legitimate queries
|
||||
return { allowed: true, reasons: [] };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { moderateInput };
|
||||
Reference in New Issue
Block a user