# Pull Request Template ## Description Routes OSS reply-box and small Captain tasks through feature-specific LLM model resolution. Rewrite, reply suggestion, summary, follow-up, and CSAT utility analysis now resolve through the `editor` feature; label suggestion resolves through `label_suggestion`. Existing credentials, account OpenAI hook behavior, and instrumentation event names remain unchanged. Linear: https://linear.app/chatwoot/issue/CW-7425/test-new-models Depends on #14839 ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? - `bundle exec rspec spec/lib/captain/base_task_service_spec.rb spec/lib/captain/rewrite_service_spec.rb spec/lib/captain/reply_suggestion_service_spec.rb spec/lib/captain/summary_service_spec.rb spec/lib/captain/label_suggestion_service_spec.rb spec/lib/captain/csat_utility_analysis_service_spec.rb spec/lib/captain/follow_up_service_spec.rb` passed with 81 examples, 0 failures. - `bundle exec rubocop lib/captain/base_task_service.rb lib/captain/rewrite_service.rb lib/captain/reply_suggestion_service.rb lib/captain/summary_service.rb lib/captain/label_suggestion_service.rb lib/captain/csat_utility_analysis_service.rb lib/captain/follow_up_service.rb enterprise/lib/enterprise/captain/reply_suggestion_service.rb spec/lib/captain/base_task_service_spec.rb spec/lib/captain/rewrite_service_spec.rb spec/lib/captain/reply_suggestion_service_spec.rb spec/lib/captain/summary_service_spec.rb spec/lib/captain/label_suggestion_service_spec.rb spec/lib/captain/csat_utility_analysis_service_spec.rb spec/lib/captain/follow_up_service_spec.rb` passed with no offenses. - `git diff --check` passed. ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
57 lines
2.3 KiB
Ruby
57 lines
2.3 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Captain::SummaryService do
|
|
let(:account) { create(:account) }
|
|
let(:inbox) { create(:inbox, account: account) }
|
|
let(:conversation) { create(:conversation, account: account, inbox: inbox) }
|
|
let(:service) { described_class.new(account: account, conversation_display_id: conversation.display_id) }
|
|
let(:mock_chat) { instance_double(RubyLLM::Chat) }
|
|
let(:mock_context) { instance_double(RubyLLM::Context, chat: mock_chat) }
|
|
let(:mock_response) { instance_double(RubyLLM::Message, content: 'Summary of conversation', input_tokens: 100, output_tokens: 50) }
|
|
|
|
before do
|
|
create(:installation_config, name: 'CAPTAIN_OPEN_AI_API_KEY', value: 'test-key')
|
|
allow(Llm::Config).to receive(:with_api_key).and_yield(mock_context)
|
|
allow(mock_chat).to receive(:with_instructions)
|
|
allow(mock_chat).to receive(:ask).and_return(mock_response)
|
|
# Stub captain enabled check to allow specs to test base functionality
|
|
# without enterprise module interference
|
|
allow(account).to receive(:feature_enabled?).and_call_original
|
|
allow(account).to receive(:feature_enabled?).with('captain_tasks').and_return(true)
|
|
end
|
|
|
|
describe '#perform' do
|
|
it 'routes through the editor feature' do
|
|
expect(service).to receive(:make_api_call).with(
|
|
hash_including(feature: 'editor')
|
|
).and_call_original
|
|
|
|
service.perform
|
|
end
|
|
|
|
it 'passes system prompt and conversation text as messages' do
|
|
allow(service).to receive(:prompt_from_file).with('summary').and_return('Summarize this')
|
|
|
|
expect(service).to receive(:make_api_call) do |args|
|
|
expect(args[:messages].length).to eq(2)
|
|
expect(args[:messages][0][:role]).to eq('system')
|
|
expect(args[:messages][0][:content]).to include('Summarize this')
|
|
expect(args[:messages][0][:content]).to include("Reply in #{account.locale_english_name}")
|
|
expect(args[:messages][1][:role]).to eq('user')
|
|
expect(args[:messages][1][:content]).to be_a(String)
|
|
{ message: 'Summary' }
|
|
end
|
|
|
|
service.perform
|
|
end
|
|
|
|
it 'returns formatted response' do
|
|
result = service.perform
|
|
|
|
expect(result[:message]).to eq('Summary of conversation')
|
|
expect(result[:usage]['prompt_tokens']).to eq(100)
|
|
expect(result[:usage]['completion_tokens']).to eq(50)
|
|
end
|
|
end
|
|
end
|