fix(captain): preserve FAQ suggestion assistant
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
class Captain::Llm::ConversationFaqJob < ApplicationJob
|
||||
queue_as :low
|
||||
|
||||
def perform(conversation)
|
||||
def perform(conversation, assistant)
|
||||
inbox = conversation.inbox
|
||||
|
||||
return unless conversation.resolved?
|
||||
return unless inbox.captain_active?
|
||||
|
||||
assistant = inbox.captain_assistant
|
||||
return if assistant.config['feature_faq'].blank?
|
||||
|
||||
Captain::Llm::ConversationFaqService.new(assistant, conversation).generate_suggestions
|
||||
|
||||
@@ -8,6 +8,6 @@ class CaptainListener < BaseListener
|
||||
return unless conversation.inbox.captain_active?
|
||||
|
||||
Captain::Llm::ContactNotesService.new(assistant, conversation).generate_and_update_notes if assistant.config['feature_memory'].present?
|
||||
Captain::Llm::ConversationFaqJob.perform_later(conversation) if assistant.config['feature_faq'].present?
|
||||
Captain::Llm::ConversationFaqJob.perform_later(conversation, assistant) if assistant.config['feature_faq'].present?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Captain::Llm::ConversationFaqJob, type: :job do
|
||||
let(:account) { create(:account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:assistant) { create(:captain_assistant, account: account, config: { feature_faq: true }) }
|
||||
let(:conversation) { create(:conversation, account: account, inbox: inbox, first_reply_created_at: Time.zone.now) }
|
||||
let(:faq_service) { instance_double(Captain::Llm::ConversationFaqService, generate_suggestions: []) }
|
||||
|
||||
before do
|
||||
create(:captain_inbox, inbox: inbox, captain_assistant: assistant)
|
||||
conversation.update!(status: :resolved)
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
it 'uses the assistant captured when the job was enqueued' do
|
||||
replacement_assistant = create(:captain_assistant, account: account, config: { feature_faq: true })
|
||||
inbox.captain_inbox.update!(captain_assistant: replacement_assistant)
|
||||
|
||||
expect(inbox.reload.captain_assistant).to eq(replacement_assistant)
|
||||
expect(Captain::Llm::ConversationFaqService).to receive(:new)
|
||||
.with(assistant, conversation)
|
||||
.and_return(faq_service)
|
||||
expect(faq_service).to receive(:generate_suggestions)
|
||||
|
||||
described_class.perform_now(conversation, assistant)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -43,7 +43,7 @@ describe CaptainListener do
|
||||
end
|
||||
|
||||
it 'enqueues FAQ suggestion generation' do
|
||||
expect(Captain::Llm::ConversationFaqJob).to receive(:perform_later).with(conversation)
|
||||
expect(Captain::Llm::ConversationFaqJob).to receive(:perform_later).with(conversation, assistant)
|
||||
expect(Captain::Llm::ContactNotesService).not_to receive(:new)
|
||||
|
||||
listener.conversation_resolved(event)
|
||||
|
||||
Reference in New Issue
Block a user