fix: Show sources in bot response only if documents are present (#8055)

- show sources section in bot only based on appropriate conditions
This commit is contained in:
Sojan Jose
2023-10-05 00:11:01 -07:00
committed by GitHub
parent 3227cf7ff3
commit 72ba429159
2 changed files with 36 additions and 7 deletions

View File

@@ -30,6 +30,36 @@ RSpec.describe Enterprise::MessageTemplates::ResponseBotService, type: :service
last_message = conversation.messages.last
expect(last_message.content).to include('some_response')
expect(last_message.content).to include(Response.first.question)
expect(last_message.content).to include('**Sources**')
end
end
context 'when context_ids are not present' do
it 'creates an outgoing message without article references' do
allow(chat_gpt_double).to receive(:generate_response).and_return({ 'response' => 'some_response' })
expect do
service.perform
end.to change { conversation.messages.where(message_type: :outgoing).count }.by(1)
last_message = conversation.messages.last
expect(last_message.content).to include('some_response')
expect(last_message.content).not_to include('**Sources**')
end
end
context 'when response doesnt have response document' do
it 'creates an outgoing message without article references' do
response = create(:response, response_source: response_source, response_document: nil)
allow(chat_gpt_double).to receive(:generate_response).and_return({ 'response' => 'some_response', 'context_ids' => [response.id] })
expect do
service.perform
end.to change { conversation.messages.where(message_type: :outgoing).count }.by(1)
last_message = conversation.messages.last
expect(last_message.content).to include('some_response')
expect(last_message.content).not_to include('**Sources**')
end
end