mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-29 02:02:27 +00:00
This commit introduces the ability to associate response sources to an inbox, allowing external webpages to be parsed by Chatwoot. The parsed data is converted into embeddings for use with GPT models when managing customer queries. The implementation relies on the `pgvector` extension for PostgreSQL. Database migrations related to this feature are handled separately by `Features::ResponseBotService`. A future update will integrate these migrations into the default rails migrations, once compatibility with Postgres extensions across all self-hosted installation options is confirmed. Additionally, a new GitHub action has been added to the CI pipeline to ensure the execution of specs related to this feature.
34 lines
1.1 KiB
Ruby
34 lines
1.1 KiB
Ruby
module Enterprise::Inbox
|
|
def member_ids_with_assignment_capacity
|
|
max_assignment_limit = auto_assignment_config['max_assignment_limit']
|
|
overloaded_agent_ids = max_assignment_limit.present? ? get_agent_ids_over_assignment_limit(max_assignment_limit) : []
|
|
super - overloaded_agent_ids
|
|
end
|
|
|
|
def get_responses(query)
|
|
embedding = Openai::EmbeddingsService.new.get_embedding(query)
|
|
responses.nearest_neighbors(:embedding, embedding, distance: 'cosine').first(5)
|
|
end
|
|
|
|
def active_bot?
|
|
super || response_bot_enabled?
|
|
end
|
|
|
|
def response_bot_enabled?
|
|
account.feature_enabled?('response_bot') && response_sources.any?
|
|
end
|
|
|
|
private
|
|
|
|
def get_agent_ids_over_assignment_limit(limit)
|
|
conversations.open.select(:assignee_id).group(:assignee_id).having("count(*) >= #{limit.to_i}").filter_map(&:assignee_id)
|
|
end
|
|
|
|
def ensure_valid_max_assignment_limit
|
|
return if auto_assignment_config['max_assignment_limit'].blank?
|
|
return if auto_assignment_config['max_assignment_limit'].to_i.positive?
|
|
|
|
errors.add(:auto_assignment_config, 'max_assignment_limit must be greater than 0')
|
|
end
|
|
end
|