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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user