-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixed some bugs and handling errors better * feat: plugins support * fix: prettier error message * moved circular-json-es6 in /api * docs: added openai moderation text * fix(gptPlugins): incorrect merge * discarding changes * removed circular-json-es6
- Loading branch information
Showing
9 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
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
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,39 @@ | ||
const axios = require('axios'); | ||
const denyRequest = require('./denyRequest'); | ||
|
||
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) { | ||
console.error('Error in moderateText:', error); | ||
const errorMessage = 'error in moderation check'; | ||
return await denyRequest(req, res, errorMessage); | ||
} | ||
} | ||
next(); | ||
} | ||
|
||
module.exports = moderateText; |
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
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
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