feat: Add support for the references in FAQs (#10699)
Currently, it’s unclear whether an FAQ item is generated from a document, derived from a conversation, or added manually. This PR resolves the issue by providing visibility into the source of each FAQ. Users can now see whether an FAQ was generated or manually added and, if applicable, by whom. - Move the document_id to a polymorphic relation (documentable). - Updated the APIs to accommodate the change. - Update the service to add corresponding references. - Updated the specs. <img width="1007" alt="Screenshot 2025-01-15 at 11 27 56 PM" src="https://github.com/user-attachments/assets/7d58f798-19c0-4407-b3e2-748a919d14af" /> --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
@@ -19,7 +19,7 @@ RSpec.describe 'Api::V1::Accounts::Captain::AssistantResponses', type: :request
|
||||
create_list(:captain_assistant_response, 30,
|
||||
account: account,
|
||||
assistant: assistant,
|
||||
document: document)
|
||||
documentable: document)
|
||||
end
|
||||
|
||||
it 'returns first page of responses with default pagination' do
|
||||
@@ -48,11 +48,11 @@ RSpec.describe 'Api::V1::Accounts::Captain::AssistantResponses', type: :request
|
||||
create_list(:captain_assistant_response, 3,
|
||||
account: account,
|
||||
assistant: assistant,
|
||||
document: document)
|
||||
documentable: document)
|
||||
create_list(:captain_assistant_response, 2,
|
||||
account: account,
|
||||
assistant: another_assistant,
|
||||
document: document)
|
||||
documentable: document)
|
||||
end
|
||||
|
||||
it 'returns only responses for the specified assistant' do
|
||||
@@ -72,11 +72,11 @@ RSpec.describe 'Api::V1::Accounts::Captain::AssistantResponses', type: :request
|
||||
create_list(:captain_assistant_response, 3,
|
||||
account: account,
|
||||
assistant: assistant,
|
||||
document: document)
|
||||
documentable: document)
|
||||
create_list(:captain_assistant_response, 2,
|
||||
account: account,
|
||||
assistant: assistant,
|
||||
document: another_document)
|
||||
documentable: another_document)
|
||||
end
|
||||
|
||||
it 'returns only responses for the specified document' do
|
||||
@@ -87,7 +87,7 @@ RSpec.describe 'Api::V1::Accounts::Captain::AssistantResponses', type: :request
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json_response[:payload].length).to eq(3)
|
||||
expect(json_response[:payload][0][:document][:id]).to eq(document.id)
|
||||
expect(json_response[:payload][0][:documentable][:id]).to eq(document.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ RSpec.describe Captain::Documents::ResponseBuilderJob, type: :job do
|
||||
describe '#perform' do
|
||||
context 'when processing a document' do
|
||||
it 'deletes previous responses' do
|
||||
existing_response = create(:captain_assistant_response, document: document)
|
||||
existing_response = create(:captain_assistant_response, documentable: document)
|
||||
|
||||
described_class.new.perform(document)
|
||||
|
||||
@@ -40,7 +40,7 @@ RSpec.describe Captain::Documents::ResponseBuilderJob, type: :job do
|
||||
expect(first_response.question).to eq('What is Ruby?')
|
||||
expect(first_response.answer).to eq('A programming language')
|
||||
expect(first_response.assistant).to eq(assistant)
|
||||
expect(first_response.document).to eq(document)
|
||||
expect(first_response.documentable).to eq(document)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,10 +49,10 @@ RSpec.describe Captain::Llm::ConversationFaqService do
|
||||
it 'saves the correct FAQ content' do
|
||||
service.generate_and_deduplicate
|
||||
expect(
|
||||
captain_assistant.responses.pluck(:question, :answer, :status)
|
||||
captain_assistant.responses.pluck(:question, :answer, :status, :documentable_id)
|
||||
).to contain_exactly(
|
||||
['What is the purpose?', 'To help users.', 'pending'],
|
||||
['How does it work?', 'Through AI.', 'pending']
|
||||
['What is the purpose?', 'To help users.', 'pending', conversation.id],
|
||||
['How does it work?', 'Through AI.', 'pending', conversation.id]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user