Skip to content

feat: Add third party service#1

Open
Quentinchampenois wants to merge 17 commits intomainfrom
feat/third_party_service
Open

feat: Add third party service#1
Quentinchampenois wants to merge 17 commits intomainfrom
feat/third_party_service

Conversation

@Quentinchampenois
Copy link

Description

Delegates classification logic to a third party AI system

Note

This PR contains a Scaleway ThirdParty strategy which can be used with a custom AI FaaS

@Quentinchampenois Quentinchampenois force-pushed the feat/third_party_service branch from c57f7c9 to 93f74f0 Compare June 11, 2025 13:30
Copy link

@alecslupu alecslupu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid job overall ( haven't played with it, but is beautiful reading it)

No changes to be made, just various comments, that you may find useful.

class GenericSpamAnalyzerJob < Decidim::Ai::SpamDetection::GenericSpamAnalyzerJob
def perform(reportable, author, locale, fields)
@author = author
organization_host = reportable.organization.host

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this may be needed in decidim, to fully support multi tenant hosts.

def perform(reportable, author, locale, fields)
@author = author
organization_host = reportable.organization.host
klass = reportable.class.to_s

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that we would really need the spam class as input data. I think a spam message is spam regardless of the place is posted. But nevertheless, i would like to find out why you need it.

return unless overall_score >= Decidim::Ai::SpamDetection.resource_score_threshold

Decidim::CreateReport.call(form, reportable)
rescue StandardError => e

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As i was saying, as we want to make sure the the retry works on sidekiq, is not recommended to catch "StandardError".

@author = reportable
organization_host = reportable.organization.host
klass = reportable.class.to_s
classifier.classify(reportable.about, organization_host, klass)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to have the organization host.

Comment on lines +48 to +50
# Configuring Third Party jobs
Decidim::Ai::SpamDetection.user_spam_analyzer_job = "Decidim::Ai::SpamDetection::ThirdParty::UserSpamAnalyzerJob"
Decidim::Ai::SpamDetection.generic_spam_analyzer_job = "Decidim::Ai::SpamDetection::ThirdParty::GenericSpamAnalyzerJob"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we do not need to register a custom analyzer after the changes are added to main repo.

autoload :Base, "decidim/ai/spam_detection/strategy/base"
autoload :Bayes, "decidim/ai/spam_detection/strategy/bayes"
autoload :ThirdParty, "decidim/ai/spam_detection/strategy/third_party"
autoload :Scaleway, "decidim/ai/spam_detection/strategy/scaleway"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add the required services as a gem, in a "Decidim::Ai::SpamDetection::Scaleway" namespace.

Comment on lines +25 to +29
private

def system_log(message, level: :info)
Rails.logger.send(level, message)
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change that should be in decidim (I already see the change is present in Bayes strategy).

module Strategy
# Scaleway third-party strategy
# doc: https://www.scaleway.com/en/docs/managed-inference/quickstart/
class Scaleway < ThirdParty

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could become: "Decidim::Ai::SpamDetection::Scaleway::Strategy".

module Ai
module SpamDetection
module Strategy
class ThirdParty < Base

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could become: "Decidim::Ai::SpamDetection::ThirdParty::Strategy".

@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Decidim

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the host changes are added to the main repo, this class is not needed anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants