feat: Response Bot using GPT and Webpage Sources (#7518)

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.
This commit is contained in:
Sojan Jose
2023-07-21 18:11:51 +03:00
committed by GitHub
parent 30f3928904
commit 480f34803b
41 changed files with 976 additions and 10 deletions

View File

@@ -0,0 +1,36 @@
# == Schema Information
#
# Table name: responses
#
# id :bigint not null, primary key
# answer :text not null
# embedding :vector(1536)
# question :string not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
# response_document_id :bigint
#
# Indexes
#
# index_responses_on_embedding (embedding) USING ivfflat
# index_responses_on_response_document_id (response_document_id)
#
class Response < ApplicationRecord
belongs_to :response_document
belongs_to :account
has_neighbors :embedding, normalize: true
before_save :update_response_embedding
def self.search(query)
embedding = Openai::EmbeddingsService.new.get_embedding(query)
nearest_neighbors(:embedding, embedding, distance: 'cosine').first(5)
end
private
def update_response_embedding
self.embedding = Openai::EmbeddingsService.new.get_embedding("#{question}: #{answer}")
end
end