Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add perspectiveapi for moderation #406

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Paillat-dev
Copy link
Contributor

No description provided.

… add new languages with perspective. Move language check before moderation.

This change is NON BREAKING, the FORCE_ENGLISH environement variable still works.
…vice, get_force_language, get_perspective_api_key, get_max_perspective_requests_per_second functions

This is NON BREAKING, the FORCE_ENGLISH env variable still works.
@Paillat-dev Paillat-dev changed the title Google perspective Add perspectiveapi for moderation Nov 14, 2023
@Kav-K
Copy link
Owner

Kav-K commented Nov 14, 2023

Nice! What does aiolimiter do?

@Kav-K Kav-K self-assigned this Nov 14, 2023
@Kav-K Kav-K added the enhancement New feature or request label Nov 14, 2023
@Paillat-dev
Copy link
Contributor Author

Paillat-dev commented Nov 14, 2023

Soooo
Here it is:

  1. Use /mod perspective_config for setting the tresholds with perspective.
  2. Language detection can now be applyed to many languages thanks to perspectiveapi.

The added environement variables are:

  • PERSPECTIVE_API_KEY: the perspectiveapi api key
  • MODERATION_SERVICE: choose between openai and perspective, defaults to openai
  • LANGUAGE_DETECT_SERVICE: overrides the language detection service to be different, defaults to the set MODERATION_SERVICE
  • FORCE_LANGUAGE: can be one of the following: Arabic (ar), Chinese (zh), Czech (cs), Dutch (nl), English (en), French (fr), German (de), Hindi (hi), Hinglish (hi-Latn), Indonesian (id), Italian (it), Japanese (ja), Korean (ko), Polish (pl), Portuguese (pt), Russian (ru), Spanish (es), Swedish (sv).
  • MAX_PERSPECTIVE_REQUESTS_PER_SECOND: Only change if you got an api ratelimit increase by google.
  • FORCE_ENGLISH: becomes an alias that sets FORCE_LANGUAGE="en" when FORCE_LANGUAGE is not set.

Openai language detection works only for english, and if another language is set while openai is the language detection service, lanuage detection will be disabled and a message will be printed in the terminal.

Language detection automatically sends a message in the user's language if it is applicable when telling the user his message is not in {language}.

I moved language detection before moderation to avoid unnecessary api calls.

@Paillat-dev
Copy link
Contributor Author

Paillat-dev commented Nov 14, 2023

Nice! What does aiolimiter do?

It allows me to ratelimit the calls of the api to one per second to avoid being rate limited.

See the perspective_model.py file in models

@Paillat-dev
Copy link
Contributor Author

I will let this draft for some more time so that I can test it more and find any possible bugs.

@Paillat-dev
Copy link
Contributor Author

Paillat-dev commented Nov 14, 2023

I think that It could be nice to add some knd of multi-language message replying to the enforce language, when using perspective. So it will warn the user in its language.

Edit: Just pushed it to the branch

…ignature to include an optional override_model parameter

fix(moderations_service.py): update send_moderations_request method to check for override_model parameter and use it to determine which model to use
fix(moderations_service.py): update set_thumbnail method in Moderation class to conditionally set the thumbnail URL based on the model type
fix(moderations_service.py): update set_thumbnail method in Moderation class to conditionally set the thumbnail URL based on the language_detect_type
…ntent in the notification embed to hide sensitive information
…ne breaks for better readability

feat(moderations_service.py): add support for language detection using OpenAI and Perspective models
feat(moderations_service.py): add moderation messages for different languages to be sent to users when their messages are moderated
fix(moderations_service.py): fix method signature and add missing line breaks for better readability
@Kav-K
Copy link
Owner

Kav-K commented Nov 16, 2023

I think that It could be nice to add some knd of multi-language message replying to the enforce language, when using perspective. So it will warn the user in its language.

Edit: Just pushed it to the branch

Yeah this would be nice, I guess we can have a layer one level above moderations that just checks what language the message was in and then outputs a locale string, and then that locale string can be passed into some sort of config file that we have locally that contains the translations of the error message in the different locales, keyed by the locale string, no need to have an LLM call for this

@Kav-K
Copy link
Owner

Kav-K commented Nov 16, 2023

How is this going generally? When would you like me to give it a full review? @Paillat-dev

@Paillat-dev
Copy link
Contributor Author

How is this going generally? When would you like me to give it a full review? @Paillat-dev

I am still testing a bit, and I would like that add some more error handling before, I'll let you know.

…d ANALYZE_REQUEST_NOT_EN to allow language detection

fix(perspective_model.py): add exception handling for languageNotSupportedByAttribute when using ANALYZE_REQUEST_NOT_EN
fix(moderations_service.py): add docstrings to send_language_detect_request and send_moderations_request methods
fix(moderations_service.py): add exception handling for languageNotSupportedByAttribute in send_moderations_request method
fix(moderations_service.py): add exception handling for languageNotSupportedByAttribute in moderation loop to ignore messages with unsupported languages
…ass to improve code readability and documentation
@Paillat-dev
Copy link
Contributor Author

I'll also write some docs in the AI-MODERATION md

… Moderation guide

The AI Moderation guide has been reorganized and improved for better readability and understanding. The changes include:

- Renaming the section titles to be more descriptive.
- Adding a section for choosing between the OpenAI and PerspectiveAPI moderation services.
- Providing separate commands and thresholds for each moderation service.
- Adding a section for language detection and the force language feature.
- Including additional configuration options and instructions.
- Removing the note about the server not being for support or discussions about GPT3Discord.

These changes aim to make it easier for users to understand and configure the AI Moderation feature.
@Paillat-dev Paillat-dev marked this pull request as ready for review November 17, 2023 19:43
@Paillat-dev
Copy link
Contributor Author

@Kav-K I'm good.

@Kav-K
Copy link
Owner

Kav-K commented Nov 21, 2023

Sorry for the delays on this, been a bit busy, will take a look ASAP @Paillat-dev

@Paillat-dev
Copy link
Contributor Author

Sorry for the delays on this, been a bit busy, will take a look ASAP @Paillat-dev

Yup, take the time needed, there is no hurry :)

@Paillat-dev
Copy link
Contributor Author

Heyy, do I keep this open or do I close it?

@Kav-K
Copy link
Owner

Kav-K commented Dec 31, 2023

@Paillat-dev I've just been busy and sick recently, will review when I can

@Kav-K
Copy link
Owner

Kav-K commented Dec 31, 2023

@Paillat-dev Before I go ahead and test this thoroughly on my end, did you test this thoroughly locally on your end?

@Paillat-dev
Copy link
Contributor Author

@Paillat-dev Before I go ahead and test this thoroughly on my end, did you test this thoroughly locally on your end?

I did test it, and tried to recreate as many situations as I could.

@Kav-K
Copy link
Owner

Kav-K commented Dec 31, 2023 via email

@Paillat-dev
Copy link
Contributor Author

Just rebased with your main but no real change

@Paillat-dev
Copy link
Contributor Author

@Kav-K Do I keep this open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants