feat: Add support for account abuse detection (#11001)

This PR adds service to automate account abuse detection. Currently
based on the signup name and URL, could potentially add more context
such as usage analysis, message metadata etc.
This commit is contained in:
Pranav
2025-02-28 15:28:19 -08:00
committed by GitHub
parent 616bbced9c
commit ecfa6bf6a2
25 changed files with 744 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
require 'openai'
class Captain::Llm::AssistantChatService < Captain::Llm::BaseOpenAiService
class Captain::Llm::AssistantChatService < Llm::BaseOpenAiService
include Captain::ChatHelper
def initialize(assistant: nil)

View File

@@ -1,20 +0,0 @@
class Captain::Llm::BaseOpenAiService
DEFAULT_MODEL = 'gpt-4o-mini'.freeze
def initialize
@client = OpenAI::Client.new(
access_token: InstallationConfig.find_by!(name: 'CAPTAIN_OPEN_AI_API_KEY').value,
log_errors: Rails.env.development?
)
setup_model
rescue StandardError => e
raise "Failed to initialize OpenAI client: #{e.message}"
end
private
def setup_model
config_value = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_MODEL')&.value
@model = (config_value.presence || DEFAULT_MODEL)
end
end

View File

@@ -1,4 +1,4 @@
class Captain::Llm::ContactAttributesService < Captain::Llm::BaseOpenAiService
class Captain::Llm::ContactAttributesService < Llm::BaseOpenAiService
def initialize(assistant, conversation)
super()
@assistant = assistant

View File

@@ -1,4 +1,4 @@
class Captain::Llm::ContactNotesService < Captain::Llm::BaseOpenAiService
class Captain::Llm::ContactNotesService < Llm::BaseOpenAiService
def initialize(assistant, conversation)
super()
@assistant = assistant

View File

@@ -1,4 +1,4 @@
class Captain::Llm::ConversationFaqService < Captain::Llm::BaseOpenAiService
class Captain::Llm::ConversationFaqService < Llm::BaseOpenAiService
DISTANCE_THRESHOLD = 0.3
def initialize(assistant, conversation)

View File

@@ -1,6 +1,6 @@
require 'openai'
class Captain::Llm::EmbeddingService < Captain::Llm::BaseOpenAiService
class Captain::Llm::EmbeddingService < Llm::BaseOpenAiService
class EmbeddingsError < StandardError; end
DEFAULT_MODEL = 'text-embedding-3-small'.freeze

View File

@@ -1,4 +1,4 @@
class Captain::Llm::FaqGeneratorService < Captain::Llm::BaseOpenAiService
class Captain::Llm::FaqGeneratorService < Llm::BaseOpenAiService
def initialize(content)
super()
@content = content