🚔 feat: OpenAI Moderation update #4827
Open
+350
−123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces significant improvements to the moderation functionality and configuration management within the codebase. The key changes include adding a new violation type, enhancing the moderation middleware, and refactoring the configuration loading process for better caching and error handling
Moderation Enhancements:
api/server/middleware/moderateText.js
: Replacedaxios
withOpenAI
for moderation requests, added new functions for formatting violations, and implemented a more robust moderation flow with configurable actions and thresholdsConfiguration Management:
api/server/services/Config/loadCustomConfig.js
: Refactored the configuration loading process to include caching, error handling, and validation improvements. [1] [2]packages/data-provider/src/config.ts
: Added a newmoderationSchema
to the configuration schema and included a newViolationTypes.MODERATION
enumeration. [1] [2] [3]Middleware Adjustments:
api/server/routes/ask/gptPlugins.js
,api/server/routes/ask/openAI.js
,api/server/routes/edit/gptPlugins.js
,api/server/routes/edit/openAI.js
: Moved themoderateText
middleware to ensure it is applied correctly across routes. [1] [2] [3] [4]Cache Updates:
api/cache/getLogStores.js
: Added a new violation type to thenamespaces
objectChange Type
Testing
Tested with the OpenAI's endpoint by sending explicit messages containing
self-harm/intent
,self-harm
,hate
,harassment
andsexual
wordsChecklist