Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬
Ruby actioncablechat-widgetconversationcustomer-supportdashboarddesigndockerdocker-imageherokuintercomjavascriptlivechatopensourcerailsrubysassvuejswhatsappzendesk
feat(captain): move GPT-4 series and legacy transcription to GPT-6 Luna and gpt-transcribe (#16266)
Aakash Bakhle12955f13ab52
diff --git a/.gitignore b/.gitignoreindex 511cb9bfd01..645b9b3c66f 100644--- a/.gitignore+++ b/.gitignore@@ -105,3 +105,6 @@ CLAUDE.local.mdlocal/Procfile.worktree.nodeterm/project.json++# Cache that `rake ruby_llm:refresh_models` writes next to the model registry+config/llm_models.json.published.jsondiff --git a/app/jobs/migration/replace_retired_captain_models_job.rb b/app/jobs/migration/replace_retired_captain_models_job.rbnew file mode 100644index 00000000000..a569379dd6e--- /dev/null+++ b/app/jobs/migration/replace_retired_captain_models_job.rb@@ -0,0 +1,41 @@+# OpenAI shuts down the GPT-4 series on January 14, 2027 (gpt-4.1-nano on October 23, 2026)+# and its older transcription models on February 26, 2027.+class Migration::ReplaceRetiredCaptainModelsJob < ApplicationJob+ queue_as :async_database_migration++ TEXT_MODEL = Llm::Config::DEFAULT_MODEL+ TRANSCRIPTION_MODEL = 'gpt-transcribe'.freeze+ RETIRED_MODELS = {+ 'gpt-4.1' => TEXT_MODEL,+ 'gpt-4.1-mini' => TEXT_MODEL,+ 'gpt-4.1-nano' => TEXT_MODEL,+ 'gpt-4o-mini-transcribe' => TRANSCRIPTION_MODEL,+ 'whisper-1' => TRANSCRIPTION_MODEL+ }.freeze++ def perform+ replace_installation_model+ replace_account_models+ end++ private++ def replace_installation_model+ # A custom endpoint may serve its own deployment under a GPT-4 name, so leave that to the operator.+ return unless Llm::FeatureRouter.standard_openai_endpoint?++ config = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_MODEL')+ config.update!(value: TEXT_MODEL) if config&.value.to_s.start_with?('gpt-4')+ end++ def replace_account_models+ Account.find_each do |account|+ models = account.captain_models+ next unless models&.values&.any? { |model| RETIRED_MODELS.key?(model) }++ account.update!(captain_models: models.transform_values { |model| RETIRED_MODELS.fetch(model, model) })+ rescue ActiveRecord::RecordInvalid => e+ Rails.logger.error("[retired-captain-models] account_id=#{account.id} #{e.record.errors.full_messages.to_sentence}")+ end+ end+enddiff --git a/app/models/concerns/captain_featurable.rb b/app/models/concerns/captain_featurable.rbindex 16566eb259c..02e66baeff9 100644--- a/app/models/concerns/captain_featurable.rb+++ b/app/models/concerns/captain_featurable.rb@@ -5,7 +5,8 @@ module CaptainFeaturableincluded dobefore_validation :normalize_captain_models- validate :validate_captain_models+ # A model removed from config/llm.yml stays saved until the account is remapped, so only check changed choices.+ validate :validate_captain_models, if: :captain_models_changed?# Dynamically define accessor methods for each captain featureLlm::Models.feature_keys.each do |feature_key|diff --git a/config/installation_config.yml b/config/installation_config.ymlindex 75e3f61172f..384d5b47733 100644--- a/config/installation_config.yml+++ b/config/installation_config.yml@@ -205,7 +205,7 @@type: secret- name: CAPTAIN_OPEN_AI_MODELdisplay_title: 'OpenAI Model'- description: 'The OpenAI model configured for use in Captain AI. Default: gpt-4.1-mini'+ description: 'The OpenAI model configured for use in Captain AI. Default: gpt-6-luna'locked: false- name: CAPTAIN_OPEN_AI_ENDPOINTdisplay_title: 'OpenAI API Endpoint (optional)'diff --git a/config/llm.yml b/config/llm.ymlindex 805b686572b..2246e8c84b9 100644--- a/config/llm.yml+++ b/config/llm.yml@@ -7,18 +7,6 @@ providers:display_name: 'Gemini'models:- gpt-4.1:- provider: openai- display_name: 'GPT-4.1'- credit_multiplier: 3- gpt-4.1-mini:- provider: openai- display_name: 'GPT-4.1 Mini'- credit_multiplier: 1- gpt-4.1-nano:- provider: openai- display_name: 'GPT-4.1 Nano'- credit_multiplier: 1gpt-5.1:provider: openaidisplay_name: 'GPT-5.1'@@ -39,6 +27,9 @@ models:provider: openaidisplay_name: 'GPT-6 Luna'credit_multiplier: 1+ reasoning_effort: none+ # models.dev lists temperature as unsupported, but Luna accepts it at reasoning effort none.+ temperature: truegpt-6.1-sol:provider: openaidisplay_name: 'GPT-6.1 Sol'@@ -63,13 +54,9 @@ models:display_name: 'Gemini 3 Pro'coming_soon: truecredit_multiplier: 3- whisper-1:- provider: openai- display_name: 'Whisper'- credit_multiplier: 1- gpt-4o-mini-transcribe:+ gpt-transcribe:provider: openai- display_name: 'GPT-4o Mini Transcribe'+ display_name: 'GPT Transcribe'credit_multiplier: 1gpt-4o-mini-tts-2025-12-15:provider: openai@@ -84,35 +71,31 @@ features:conversation_completion:models:[- gpt-4.1-mini,+ gpt-6-luna,gpt-5-mini,- gpt-4.1,gpt-5.1,gpt-5.2,]- default: gpt-4.1+ default: gpt-6-lunainternal: trueeditor:models:[- gpt-4.1-mini,- gpt-4.1-nano,+ gpt-6-luna,gpt-5-mini,- gpt-4.1,gpt-5.1,gpt-5.2,claude-haiku-4.5,gemini-3-flash,gemini-3-pro,]- default: gpt-4.1-mini+ default: gpt-6-lunaassistant:reasoning_effort: nonemodels:[- gpt-4.1-mini,+ gpt-6-luna,gpt-5-mini,- gpt-4.1,gpt-5.1,gpt-5.2,claude-haiku-4.5,@@ -120,14 +103,13 @@ features:gemini-3-flash,gemini-3-pro,]- default: gpt-4.1+ default: gpt-6-lunacopilot:reasoning_effort: nonemodels:[- gpt-4.1-mini,+ gpt-6-luna,gpt-5-mini,- gpt-4.1,gpt-5.1,gpt-5.2,claude-haiku-4.5,@@ -135,13 +117,13 @@ features:gemini-3-flash,gemini-3-pro,]- default: gpt-4.1+ default: gpt-5.2document_faq_generation:+ reasoning_effort: mediummodels:[- gpt-4.1-mini,+ gpt-6-luna,gpt-5-mini,- gpt-4.1,gpt-5.1,gpt-5.2,claude-haiku-4.5,@@ -149,13 +131,12 @@ features:gemini-3-flash,gemini-3-pro,]- default: gpt-4.1-mini+ default: gpt-6-lunaconversation_faq_generation:models:[- gpt-4.1-mini,+ gpt-6-luna,gpt-5-mini,- gpt-4.1,gpt-5.1,gpt-5.2,claude-haiku-4.5,@@ -167,9 +148,8 @@ features:conversation_faq_matching:models:[- gpt-4.1-mini,+ gpt-6-luna,gpt-5-mini,- gpt-4.1,gpt-5.1,gpt-5.2,claude-haiku-4.5,@@ -177,16 +157,15 @@ features:gemini-3-flash,gemini-3-pro,]- default: gpt-4.1-mini+ default: gpt-6-lunapdf_faq_generation:- models: [gpt-4.1-mini, gpt-5-mini, gpt-4.1, gpt-5.1, gpt-5.2]- default: gpt-4.1-mini+ models: [gpt-6-luna, gpt-5-mini, gpt-5.1, gpt-5.2]+ default: gpt-6-lunahelp_center_article_generation:models:[- gpt-4.1-mini,+ gpt-6-luna,gpt-5-mini,- gpt-4.1,gpt-5.1,gpt-5.2,claude-haiku-4.5,@@ -197,20 +176,20 @@ features:default: gpt-5.2onboarding_content_generation:models:- [gpt-4.1, gpt-4.1-mini, gpt-5-mini, gpt-5.1, gpt-5.2]- default: gpt-4.1+ [gpt-6-luna, gpt-5-mini, gpt-5.1, gpt-5.2]+ default: gpt-6-lunahelp_center_query_translation:- models: [gpt-4.1-nano, gpt-4.1-mini, gpt-5-mini]- default: gpt-4.1-nano+ models: [gpt-6-luna, gpt-5-mini]+ default: gpt-6-lunamessage_translation:- models: [gpt-6-luna, gpt-6.1-sol, gpt-5.2, gpt-5-mini, gpt-4.1-mini]+ models: [gpt-6-luna, gpt-6.1-sol, gpt-5.2, gpt-5-mini]default: gpt-6-lunalanguage_detection:models: [gpt-5-mini, gpt-5-nano]default: gpt-5-miniaudio_transcription:- models: [gpt-4o-mini-transcribe, whisper-1]- default: gpt-4o-mini-transcribe+ models: [gpt-transcribe]+ default: gpt-transcribecall_announcement:models: [gpt-4o-mini-tts-2025-12-15]default: gpt-4o-mini-tts-2025-12-15diff --git a/db/migrate/20261015063804_replace_retired_captain_models.rb b/db/migrate/20261015063804_replace_retired_captain_models.rbnew file mode 100644index 00000000000..2abb0ea1933--- /dev/null+++ b/db/migrate/20261015063804_replace_retired_captain_models.rb@@ -0,0 +1,8 @@+class ReplaceRetiredCaptainModels < ActiveRecord::Migration[7.2]+ # Runs inline because a queued job can reach Sidekiq workers still on the previous release, which don't have the job class yet.+ def up+ Migration::ReplaceRetiredCaptainModelsJob.perform_now+ end++ def down; end+enddiff --git a/enterprise/app/models/enterprise/concerns/article.rb b/enterprise/app/models/enterprise/concerns/article.rbindex 6be262fef7d..8164aee3f04 100644--- a/enterprise/app/models/enterprise/concerns/article.rb+++ b/enterprise/app/models/enterprise/concerns/article.rb@@ -68,7 +68,7 @@ module Enterprise::Concerns::Article{ role: 'user', content: "title: #{title} \n description: #{description} \n content: #{content}" }]headers = { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{openai_api_key}" }- body = { model: 'gpt-4o', messages: messages, response_format: { type: 'json_object' } }.to_json+ body = { model: 'gpt-6-luna', reasoning_effort: 'none', messages: messages, response_format: { type: 'json_object' } }.to_jsonRails.logger.info "Requesting Chat GPT with body: #{body}"response = HTTParty.post(openai_api_url, headers: headers, body: body)Rails.logger.info "Chat GPT response: #{response.body}"diff --git a/enterprise/app/services/captain/copilot/chat_service.rb b/enterprise/app/services/captain/copilot/chat_service.rbindex 4de66483a4b..8b85164fc30 100644--- a/enterprise/app/services/captain/copilot/chat_service.rb+++ b/enterprise/app/services/captain/copilot/chat_service.rb@@ -5,7 +5,7 @@ class Captain::Copilot::ChatService < Llm::BaseAiServiceattr_reader :assistant, :account, :user, :copilot_thread, :previous_history, :messagesdef initialize(assistant, config)- super(feature: 'copilot', account: assistant.account)+ super(feature: 'copilot', account: assistant.account, fallback_model: Llm::Models.default_model_for('copilot'))@assistant = assistant@account = assistant.accountdiff --git a/enterprise/app/services/captain/llm/help_center_curation_service.rb b/enterprise/app/services/captain/llm/help_center_curation_service.rbindex 37056dc2562..f6e6188490e 100644--- a/enterprise/app/services/captain/llm/help_center_curation_service.rb+++ b/enterprise/app/services/captain/llm/help_center_curation_service.rb@@ -2,14 +2,11 @@ class Captain::Llm::HelpCenterCurationService < Captain::BaseTaskServiceRESPONSE_SCHEMA = Captain::Llm::HelpCenterCurationSchemaMAX_LINKS_IN_PROMPT = 50IGNORED_URL_PATTERN = /\.(?:pdf|jpe?g|png|gif|webp|svg|ico|bmp|tiff?|avif|heic)(?:\?|#|$)/i- # This model consistently outperforms 5.2 in generating tighter and more- # accurate curations.- CURATION_MODEL = 'gpt-4.1'.freezepattr_initialize [:account!, :links!]def perform- response = make_api_call(feature: 'onboarding_content_generation', model: CURATION_MODEL, messages: messages, schema: RESPONSE_SCHEMA)+ response = make_api_call(feature: 'onboarding_content_generation', messages: messages, schema: RESPONSE_SCHEMA)return response if response[:error]response.merge(message: extract_payload(response[:message]))diff --git a/enterprise/app/services/captain/llm/paginated_faq_generator_service.rb b/enterprise/app/services/captain/llm/paginated_faq_generator_service.rbindex 3e3a12af325..8e6741419c6 100644--- a/enterprise/app/services/captain/llm/paginated_faq_generator_service.rb+++ b/enterprise/app/services/captain/llm/paginated_faq_generator_service.rb@@ -111,7 +111,9 @@ class Captain::Llm::PaginatedFaqGeneratorService < Llm::LegacyBaseOpenAiServicemessage.merge(content: content)end# RubyLLM's Responses requests send store: false; this hand-built request must too, or OpenAI keeps the document.- { model: @model, input: input, store: false, **format_options }+ params = { model: @model, input: input, store: false, **format_options }+ params[:reasoning] = request_options[:thinking] if request_options[:thinking]+ paramsenddef request_completion(params)diff --git a/enterprise/app/services/captain/llm/system_prompts_service.rb b/enterprise/app/services/captain/llm/system_prompts_service.rbindex d93001f1563..8b3da4e1b10 100644--- a/enterprise/app/services/captain/llm/system_prompts_service.rb+++ b/enterprise/app/services/captain/llm/system_prompts_service.rb@@ -155,7 +155,8 @@ class Captain::Llm::SystemPromptsServiceProcess the content starting from approximately page #{start_page} and continuing for about #{end_page - start_page + 1} pages worth of content.IMPORTANT:#{' '}- • If you encounter the end of the document before reaching the expected page count, set "has_content" to false+ • Generate FAQs for all content that exists in this range, even if the document ends before the expected page count+ • Set "has_content" to false when the document ends within this range, so no later range is requested• DO NOT include page numbers in questions or answers• DO NOT reference page numbers at all in the output• Focus on the actual content, not pagination@@ -170,7 +171,7 @@ class Captain::Llm::SystemPromptsService• Extract ALL information that could generate FAQs from this section• Target 5-10 FAQs per page equivalent of rich content• Cover every topic, feature, specification, and detail- • If there's no more content in the document, return empty FAQs with has_content: false+ • If this range has no content at all because the document already ended, return empty FAQs with has_content: false2. **Question Types to Generate**• What is/are...? (definitions, components, features)diff --git a/enterprise/app/services/captain/llm/widget_tagline_service.rb b/enterprise/app/services/captain/llm/widget_tagline_service.rbindex 155b1039648..97911ac5055 100644--- a/enterprise/app/services/captain/llm/widget_tagline_service.rb+++ b/enterprise/app/services/captain/llm/widget_tagline_service.rb@@ -28,6 +28,7 @@ class Captain::Llm::WidgetTaglineService < Captain::BaseTaskService<<~PROMPTYou write a short marketing tagline for a company's customer-support chat widget.Use the provided company context to make the tagline specific and on-brand.+ Keep it under 45 characters, and avoid generic phrasing that could fit any company.PROMPTenddiff --git a/enterprise/app/services/llm/legacy_base_open_ai_service.rb b/enterprise/app/services/llm/legacy_base_open_ai_service.rbindex db441a77914..fbaac8f7c2c 100644--- a/enterprise/app/services/llm/legacy_base_open_ai_service.rb+++ b/enterprise/app/services/llm/legacy_base_open_ai_service.rb@@ -9,7 +9,7 @@## For all other LLM operations, use Llm::BaseAiService with RubyLLM instead.class Llm::LegacyBaseOpenAiService- DEFAULT_MODEL = 'gpt-4.1-mini'+ DEFAULT_MODEL = Llm::Config::DEFAULT_MODELattr_reader :client, :modeldiff --git a/enterprise/lib/captain/prompts/assistant_overview_summary.liquid b/enterprise/lib/captain/prompts/assistant_overview_summary.liquidindex b9a66291738..54408abd8a7 100644--- a/enterprise/lib/captain/prompts/assistant_overview_summary.liquid+++ b/enterprise/lib/captain/prompts/assistant_overview_summary.liquid@@ -7,7 +7,7 @@ Requirements for every point:- Cite the rounded value and comparison that make it notable. Use exact reporting-period or bucket dates when time is relevant.- Explain why the signal matters operationally, but never invent a cause, customer intent, or recommendation that the data does not support.- Cover one distinct theme. Do not repeat the same metric or rephrase another point.-- Aim for 180–220 characters per point, including spaces, and never exceed 220 characters. Keep points similar in length; do not add filler to reach the target.+- Keep every point at 220 characters or fewer, including spaces. If a point would run longer, drop the least important detail instead of exceeding the limit. Keep points similar in length; do not add filler.- Write each point as a single paragraph without line breaks.Prioritize these signals:diff --git a/enterprise/lib/captain/prompts/conversation_completion.liquid b/enterprise/lib/captain/prompts/conversation_completion.liquidindex e039f60b0ab..fc2dbdd6f10 100644--- a/enterprise/lib/captain/prompts/conversation_completion.liquid+++ b/enterprise/lib/captain/prompts/conversation_completion.liquid@@ -40,3 +40,5 @@ Analyze the conversation and respond with ONLY a JSON object (no other text):{"complete": true, "reason": "brief explanation"}or{"complete": false, "reason": "brief explanation"}++Write the reason in English.diff --git a/lib/captain/base_task_service.rb b/lib/captain/base_task_service.rbindex 56e41867cbb..9116f80394f 100644--- a/lib/captain/base_task_service.rb+++ b/lib/captain/base_task_service.rb@@ -3,7 +3,7 @@ class Captain::BaseTaskServiceinclude Captain::ToolInstrumentationinclude Llm::ExceptionTrackable- # gpt-4o-mini supports 128,000 tokens+ # Sized for a 128,000-token context window# 1 token is approx 4 characters# sticking with 120000 to be safe# 120000 * 4 = 480,000 characters (rounding off downwards to 400,000 to be safe)@@ -86,6 +86,7 @@ class Captain::BaseTaskServicetools = request.fetch(:tools, [])options = Captain::ResponsesConfig.options(model: model, temperature: nil, feature: request[:feature])chat = context.chat(model: model, **options.slice(:protocol))+ chat.with_thinking(**options[:thinking]) if options[:thinking]system_msg = messages.find { |m| m[:role] == 'system' }chat.with_instructions(system_msg[:content]) if system_msgchat.with_schema(request[:schema]) if request[:schema]diff --git a/lib/captain/follow_up_service.rb b/lib/captain/follow_up_service.rbindex 9304aa4524b..26f0138157f 100644--- a/lib/captain/follow_up_service.rb+++ b/lib/captain/follow_up_service.rb@@ -47,6 +47,8 @@ class Captain::FollowUpService < Captain::BaseTaskServiceYou just performed a #{action_context} action for a customer support agent.Your job now is to help them refine the result based on their feedback.Be concise and focused on their specific request.+ Change only what the agent asks for. Keep all other content, facts, and any signature exactly as in the previous result.+ Do not shorten, summarize, or drop sentences unless the agent asks.Output only the reply, no preamble, tags, or explanation.PROMPTenddiff --git a/lib/integrations/llm_base_service.rb b/lib/integrations/llm_base_service.rbindex 3f1d13c2f14..c9786b666e7 100644--- a/lib/integrations/llm_base_service.rb+++ b/lib/integrations/llm_base_service.rb@@ -2,7 +2,7 @@ class Integrations::LlmBaseServiceinclude Integrations::LlmInstrumentationinclude Llm::ExceptionTrackable- # gpt-4o-mini supports 128,000 tokens+ # Sized for a 128,000-token context window# 1 token is approx 4 characters# sticking with 120000 to be safe# 120000 * 4 = 480,000 characters (rounding off downwards to 400,000 to be safe)diff --git a/lib/integrations/llm_instrumentation_completion_helpers.rb b/lib/integrations/llm_instrumentation_completion_helpers.rbindex f8c1e36b842..5d5ec9fd71c 100644--- a/lib/integrations/llm_instrumentation_completion_helpers.rb+++ b/lib/integrations/llm_instrumentation_completion_helpers.rb@@ -14,7 +14,7 @@ module Integrations::LlmInstrumentationCompletionHelpersdef set_audio_transcription_span_attributes(span, params)span.set_attribute(ATTR_GEN_AI_PROVIDER, 'openai')- span.set_attribute(ATTR_GEN_AI_REQUEST_MODEL, params[:model] || 'whisper-1')+ span.set_attribute(ATTR_GEN_AI_REQUEST_MODEL, params[:model])span.set_attribute('audio.duration_seconds', params[:duration]) if params[:duration]span.set_attribute(ATTR_LANGFUSE_OBSERVATION_INPUT, params[:file_path].to_s) if params[:file_path]enddiff --git a/lib/integrations/openai/openai_prompts/tone_rewrite.liquid b/lib/integrations/openai/openai_prompts/tone_rewrite.liquidindex 6b62617f0ef..526a8e30439 100644--- a/lib/integrations/openai/openai_prompts/tone_rewrite.liquid+++ b/lib/integrations/openai/openai_prompts/tone_rewrite.liquid@@ -21,6 +21,7 @@ Warm, approachable, and personable. Use conversational language, positive words,Your task is to rewrite the message according to the specified tone instructions.Important guidelines:+- Apply the tone clearly, so the rewritten message reads noticeably different in tone from the original- Preserve the core meaning and all important information from the original message- Keep the rewritten message concise and appropriate for customer support- Maintain helpfulness and respect regardless of tonediff --git a/lib/llm/config.rb b/lib/llm/config.rbindex 26158fce953..afd67a02660 100644--- a/lib/llm/config.rb+++ b/lib/llm/config.rb@@ -1,7 +1,7 @@require 'ruby_llm'module Llm::Config- DEFAULT_MODEL = 'gpt-4.1-mini'.freeze+ DEFAULT_MODEL = 'gpt-6-luna'.freezeclass << selfdef initialized?diff --git a/lib/llm/feature_router.rb b/lib/llm/feature_router.rbindex 284c1f6c214..6fc571a2b1c 100644--- a/lib/llm/feature_router.rb+++ b/lib/llm/feature_router.rb@@ -21,7 +21,7 @@ module Llm::FeatureRouterdef reasoning_effort(feature:, model:)return unless Llm::Models.provider_for(model) == 'openai' && standard_openai_endpoint?- effort = Llm::Models.features.dig(feature.to_s, 'reasoning_effort')+ effort = Llm::Models.features.dig(feature.to_s, 'reasoning_effort') || Llm::Models.model_config(model)&.dig('reasoning_effort')effort.to_sym if RubyLLM.models.find(model).reasoning_option_values(:effort).include?(effort)enddiff --git a/lib/llm/models.rb b/lib/llm/models.rbindex 1c8b812b9e7..7d83837f299 100644--- a/lib/llm/models.rb+++ b/lib/llm/models.rb@@ -37,8 +37,11 @@ module Llm::Modelsmodel_config(model_name)&.dig('provider')end+ # config/llm.yml can override the registry, which `rake ruby_llm:refresh_models` regenerates.def temperature_for(model_name, temperature)- temperature unless RubyLLM.models.find(model_name).metadata[:temperature] == false+ supported = model_config(model_name)&.dig('temperature')+ supported = RubyLLM.models.find(model_name).metadata[:temperature] if supported.nil?+ temperature unless supported == falseenddef feature_config(feature_key)diff --git a/lib/llm_constants.rb b/lib/llm_constants.rbindex 241f3ccba66..328f1528c03 100644--- a/lib/llm_constants.rb+++ b/lib/llm_constants.rb@@ -1,9 +1,8 @@# frozen_string_literal: truemodule LlmConstants- DEFAULT_MODEL = 'gpt-4.1'+ DEFAULT_MODEL = 'gpt-6-luna'DEFAULT_EMBEDDING_MODEL = 'text-embedding-3-small'- PDF_PROCESSING_MODEL = 'gpt-4.1-mini'OPENAI_API_ENDPOINT = 'https://api.openai.com'diff --git a/lib/tasks/ruby_llm.rake b/lib/tasks/llm_models.rakesimilarity index 76%rename from lib/tasks/ruby_llm.rakerename to lib/tasks/llm_models.rakeindex e12accebeec..8cea7c3bce3 100644--- a/lib/tasks/ruby_llm.rake+++ b/lib/tasks/llm_models.rake@@ -9,6 +9,9 @@ namespace :ruby_llm dodesc 'Refresh RubyLLM model registry from models.dev'task refresh_models: :environment doregistry_path = Rails.root.join('config/llm_models.json').to_s+ # RubyLLM 2.0's Rails integration points the registry at a ruby_llm_models table, which Chatwoot does not use.+ RubyLLM.config.model_registry_store = nil+ RubyLLM.config.model_registry_file = registry_pathputs 'Refreshing RubyLLM model registry...'RubyLLM.models.refreshRubyLLM.models.save_to_json(registry_path)diff --git a/spec/controllers/api/v1/accounts/captain/preferences_controller_spec.rb b/spec/controllers/api/v1/accounts/captain/preferences_controller_spec.rbindex 8b61a8b5e86..010f3a31938 100644--- a/spec/controllers/api/v1/accounts/captain/preferences_controller_spec.rb+++ b/spec/controllers/api/v1/accounts/captain/preferences_controller_spec.rb@@ -48,7 +48,7 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doendit 'returns effective model provider and source for each feature' do- account.update!(captain_models: { 'editor' => 'gpt-4.1' })+ account.update!(captain_models: { 'editor' => 'gpt-5.1' })get "/api/v1/accounts/#{account.id}/captain/preferences",headers: admin.create_new_auth_token,@@ -56,8 +56,8 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doexpect(response).to have_http_status(:success)expect(json_response.dig(:features, :editor)).to include(- model: 'gpt-4.1',- selected: 'gpt-4.1',+ model: 'gpt-5.1',+ selected: 'gpt-5.1',provider: 'openai',source: 'account_override')@@ -119,7 +119,7 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request docontext 'when it is an unauthenticated user' doit 'returns unauthorized' doput "/api/v1/accounts/#{account.id}/captain/preferences",- params: { captain_models: { editor: 'gpt-4.1-mini' } },+ params: { captain_models: { editor: 'gpt-5-mini' } },as: :jsonexpect(response).to have_http_status(:unauthorized)@@ -130,7 +130,7 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doit 'returns forbidden' doput "/api/v1/accounts/#{account.id}/captain/preferences",headers: agent.create_new_auth_token,- params: { captain_models: { editor: 'gpt-4.1-mini' } },+ params: { captain_models: { editor: 'gpt-5-mini' } },as: :jsonexpect(response).to have_http_status(:unauthorized)@@ -141,14 +141,14 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doit 'updates captain_models' doput "/api/v1/accounts/#{account.id}/captain/preferences",headers: admin.create_new_auth_token,- params: { captain_models: { editor: 'gpt-4.1-mini' } },+ params: { captain_models: { editor: 'gpt-5-mini' } },as: :jsonexpect(response).to have_http_status(:success)expect(json_response).to have_key(:providers)expect(json_response).to have_key(:models)expect(json_response).to have_key(:features)- expect(account.reload.captain_models['editor']).to eq('gpt-4.1-mini')+ expect(account.reload.captain_models['editor']).to eq('gpt-5-mini')endit 'does not persist unknown or internal captain model feature keys' do@@ -156,15 +156,15 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doheaders: admin.create_new_auth_token,params: {captain_models: {- editor: 'gpt-4.1-mini',- unknown_feature: 'gpt-4.1',- conversation_completion: 'gpt-4.1'+ editor: 'gpt-5-mini',+ unknown_feature: 'gpt-5.1',+ conversation_completion: 'gpt-5.1'}},as: :jsonexpect(response).to have_http_status(:success)- expect(account.reload.captain_models).to eq('editor' => 'gpt-4.1-mini')+ expect(account.reload.captain_models).to eq('editor' => 'gpt-5-mini')expect(json_response[:features]).not_to have_key(:conversation_completion)end@@ -180,7 +180,7 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doendit 'removes blank captain model overrides' do- account.update!(captain_models: { 'editor' => 'gpt-4.1' })+ account.update!(captain_models: { 'editor' => 'gpt-5.1' })put "/api/v1/accounts/#{account.id}/captain/preferences",headers: admin.create_new_auth_token,@@ -209,12 +209,12 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doit 'updates captain_models for conversation FAQ generation' doput "/api/v1/accounts/#{account.id}/captain/preferences",headers: admin.create_new_auth_token,- params: { captain_models: { conversation_faq_generation: 'gpt-4.1-mini' } },+ params: { captain_models: { conversation_faq_generation: 'gpt-5-mini' } },as: :jsonexpect(response).to have_http_status(:success)- expect(json_response.dig(:features, :conversation_faq_generation, :selected)).to eq('gpt-4.1-mini')- expect(account.reload.captain_models['conversation_faq_generation']).to eq('gpt-4.1-mini')+ expect(json_response.dig(:features, :conversation_faq_generation, :selected)).to eq('gpt-5-mini')+ expect(account.reload.captain_models['conversation_faq_generation']).to eq('gpt-5-mini')endit 'updates captain_models for PDF FAQ generation' do@@ -242,11 +242,11 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doendit 'merges with existing captain_models' do- account.update!(captain_models: { 'editor' => 'gpt-4.1-mini', 'assistant' => 'gpt-5.1' })+ account.update!(captain_models: { 'editor' => 'gpt-5-mini', 'assistant' => 'gpt-5.1' })put "/api/v1/accounts/#{account.id}/captain/preferences",headers: admin.create_new_auth_token,- params: { captain_models: { editor: 'gpt-4.1' } },+ params: { captain_models: { editor: 'gpt-5.1' } },as: :jsonexpect(response).to have_http_status(:success)@@ -254,7 +254,7 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doexpect(json_response).to have_key(:models)expect(json_response).to have_key(:features)models = account.reload.captain_models- expect(models['editor']).to eq('gpt-4.1')+ expect(models['editor']).to eq('gpt-5.1')expect(models['assistant']).to eq('gpt-5.1') # Preservedend@@ -279,7 +279,7 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doput "/api/v1/accounts/#{account.id}/captain/preferences",headers: admin.create_new_auth_token,params: {- captain_models: { editor: 'gpt-4.1-mini' },+ captain_models: { editor: 'gpt-5-mini' },captain_features: { editor: true }},as: :json@@ -289,7 +289,7 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request doexpect(json_response).to have_key(:models)expect(json_response).to have_key(:features)account.reload- expect(account.captain_models['editor']).to eq('gpt-4.1-mini')+ expect(account.captain_models['editor']).to eq('gpt-5-mini')expect(account.captain_features['editor']).to be trueendenddiff --git a/spec/controllers/super_admin/accounts_controller_spec.rb b/spec/controllers/super_admin/accounts_controller_spec.rbindex 9a72d15a9f9..35ec59f3a9c 100644--- a/spec/controllers/super_admin/accounts_controller_spec.rb+++ b/spec/controllers/super_admin/accounts_controller_spec.rb@@ -28,7 +28,7 @@ RSpec.describe 'Super Admin accounts API', type: :request dodescribe 'GET /super_admin/accounts/{account_id}' docontext 'when it is an authenticated user' doit 'shows effective Captain model routing', if: ChatwootApp.enterprise? do- account.update!(captain_models: { 'editor' => 'gpt-4.1', 'conversation_completion' => 'gpt-5.2' })+ account.update!(captain_models: { 'editor' => 'gpt-5.1', 'conversation_completion' => 'gpt-5.2' })sign_in(super_admin, scope: :super_admin)get "/super_admin/accounts/#{account.id}"@@ -43,7 +43,7 @@ RSpec.describe 'Super Admin accounts API', type: :request doexpect(summaries).not_to include('All features', 'Captain models')expect(routing_panel.text.squish).to include('Customer features', 'Internal features')expect(completion_card.text.squish).to include('Inactive conversation completion evaluator', 'GPT-5.2', 'Account override')- expect(response.body).to include('Editor', 'OpenAI', 'openai', 'gpt-4.1', 'Help center query translation', 'Default')+ expect(response.body).to include('Editor', 'OpenAI', 'openai', 'gpt-5.1', 'Help center query translation', 'Default')endit 'shows the installation model for internal routing on self-hosted Enterprise', if: ChatwootApp.enterprise? do@@ -71,7 +71,7 @@ RSpec.describe 'Super Admin accounts API', type: :request doit 'renders separate Captain model selectors for customer and internal AI features', if: ChatwootApp.enterprise? doallow(ChatwootApp).to receive(:self_hosted_paid?).and_return(true)InstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_MODEL').update!(value: 'gpt-5.1')- account.update!(captain_models: { 'editor' => 'gpt-4.1' })+ account.update!(captain_models: { 'editor' => 'gpt-5.1' })sign_in(super_admin, scope: :super_admin)get "/super_admin/accounts/#{account.id}/edit"@@ -126,7 +126,7 @@ RSpec.describe 'Super Admin accounts API', type: :request docontext 'when it is an authenticated user' doit 'updates Captain model overrides without changing unrelated settings' doaccount.update!(- captain_models: { 'editor' => 'gpt-4.1' },+ captain_models: { 'editor' => 'gpt-5.1' },keep_pending_on_bot_failure: true)sign_in(super_admin, scope: :super_admin)diff --git a/spec/enterprise/lib/captain/conversation_completion_service_spec.rb b/spec/enterprise/lib/captain/conversation_completion_service_spec.rbindex d7c62ad782e..9e9d76e0398 100644--- a/spec/enterprise/lib/captain/conversation_completion_service_spec.rb+++ b/spec/enterprise/lib/captain/conversation_completion_service_spec.rb@@ -13,6 +13,7 @@ RSpec.describe Captain::ConversationCompletionService doallow(Llm::Config).to receive(:with_api_key).and_yield(mock_context)allow(mock_chat).to receive(:with_instructions)allow(mock_chat).to receive(:with_schema).and_return(mock_chat)+ allow(mock_chat).to receive(:with_thinking).and_return(mock_chat)allow(mock_chat).to receive(:with_model).and_return(mock_chat)allow(account).to receive(:feature_enabled?).and_call_originalallow(account).to receive(:feature_enabled?).with('captain_tasks').and_return(true)@@ -23,7 +24,7 @@ RSpec.describe Captain::ConversationCompletionService dolet(:context) { RubyLLM.context { |config| config.openai_api_key = 'test-key' } }let(:messages) { [{ role: 'system', content: 'Evaluate the conversation.' }, { role: 'user', content: 'Customer: Thanks!' }] }- %w[gpt-4.1 gpt-5.2].each do |model|+ %w[gpt-5-mini gpt-5.2].each do |model|it "renders a Responses schema request for #{model} without specifying effort" dochat = service.send(:build_chat, context, model: model, messages: messages, schema: described_class::RESPONSE_SCHEMA)chat.add_message(role: :user, content: messages.last[:content])@@ -40,12 +41,12 @@ RSpec.describe Captain::ConversationCompletionService doit 'retains Chat Completions for a custom OpenAI endpoint' doInstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_ENDPOINT').update!(value: 'https://custom.example')context.config.openai_protocol = :chat_completions- chat = service.send(:build_chat, context, model: 'gpt-4.1', messages: messages, schema: described_class::RESPONSE_SCHEMA)+ chat = service.send(:build_chat, context, model: 'gpt-6-luna', messages: messages, schema: described_class::RESPONSE_SCHEMA)chat.add_message(role: :user, content: messages.last[:content])expect(chat.render).to include(messages: an_instance_of(Array), response_format: include(type: 'json_schema'))expect(chat.render).not_to have_key(:input)- expect(service.send(:build_instrumentation_params, 'gpt-4.1', messages)[:metadata]).to include(api_protocol: 'chat_completions')+ expect(service.send(:build_instrumentation_params, 'gpt-6-luna', messages)[:metadata]).to include(api_protocol: 'chat_completions')endend@@ -60,11 +61,11 @@ RSpec.describe Captain::ConversationCompletionService doallow(mock_chat).to receive(:ask).and_return(mock_response)end- it 'uses the internal GPT-4.1 route on Chatwoot Cloud' do+ it 'uses the internal GPT-6 Luna route on Chatwoot Cloud' doallow(ChatwootApp).to receive(:self_hosted_paid?).and_return(false)InstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_MODEL').update!(value: 'gpt-5.1')account.enable_features!('captain_integration')- allow(mock_context).to receive(:chat).with(model: 'gpt-4.1').and_return(mock_chat)+ allow(mock_context).to receive(:chat).with(model: 'gpt-6-luna').and_return(mock_chat)expect(service.perform).to include(complete: true)end@@ -86,10 +87,10 @@ RSpec.describe Captain::ConversationCompletionService doexpect(service.perform).to include(complete: true)end- it 'falls back to the internal GPT-4.1 route when the self-hosted installation model is blank' do+ it 'falls back to the internal GPT-6 Luna route when the self-hosted installation model is blank' doallow(ChatwootApp).to receive(:self_hosted_paid?).and_return(true)InstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_MODEL').update!(value: '')- allow(mock_context).to receive(:chat).with(model: 'gpt-4.1').and_return(mock_chat)+ allow(mock_context).to receive(:chat).with(model: 'gpt-6-luna').and_return(mock_chat)expect(service.perform).to include(complete: true)enddiff --git a/spec/enterprise/lib/captain/responses_config_spec.rb b/spec/enterprise/lib/captain/responses_config_spec.rbindex 797c06705ba..05b3ed5733d 100644--- a/spec/enterprise/lib/captain/responses_config_spec.rb+++ b/spec/enterprise/lib/captain/responses_config_spec.rb@@ -41,13 +41,13 @@ RSpec.describe Captain::ResponsesConfig doit 'keeps custom endpoints on their existing protocol without forced reasoning' doInstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_ENDPOINT').update!(value: 'https://custom.example')- expect(described_class.options(model: 'gpt-4.1', temperature: 0.7, feature: 'copilot')).to eq(temperature: 0.7)+ expect(described_class.options(model: 'gpt-6-luna', temperature: 0.7, feature: 'copilot')).to eq(temperature: 0.7)expect(described_class.options(model: 'gpt-5-mini', temperature: 0.7, feature: 'copilot')).to eq(temperature: nil)endit 'reports Chat Completions and omits effort when thinking is not configured' docontext.config.openai_protocol = :chat_completions- chat = context.chat(model: 'gpt-4.1')+ chat = context.chat(model: 'gpt-6-luna')expect(described_class.metadata(chat)).to eq(api_protocol: :chat_completions)enddiff --git a/spec/enterprise/models/concerns/agentable_spec.rb b/spec/enterprise/models/concerns/agentable_spec.rbindex c68531a4117..7858be8b778 100644--- a/spec/enterprise/models/concerns/agentable_spec.rb+++ b/spec/enterprise/models/concerns/agentable_spec.rb@@ -179,20 +179,20 @@ RSpec.describe Concerns::Agentable doendit 'returns account override model when present' do- create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-4.1-nano')+ create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-5-mini')account.update!(captain_models: { 'assistant' => 'gpt-5.2' })expect(dummy_instance.send(:agent_model)).to eq('gpt-5.2')endit 'returns the installation model when account override is absent' do- create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-4.1-nano')+ create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-5-mini')- expect(dummy_instance.send(:agent_model)).to eq('gpt-4.1-nano')+ expect(dummy_instance.send(:agent_model)).to eq('gpt-5-mini')endit 'returns the Captain V2 default when Captain V2 is enabled' do- create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-4.1-nano')+ create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-5-mini')account.enable_features!('captain_integration')expect(dummy_instance.send(:agent_model)).to eq('gpt-5.2')diff --git a/spec/enterprise/services/captain/copilot/chat_service_spec.rb b/spec/enterprise/services/captain/copilot/chat_service_spec.rbindex 9d69cb9710d..c75ea54dd95 100644--- a/spec/enterprise/services/captain/copilot/chat_service_spec.rb+++ b/spec/enterprise/services/captain/copilot/chat_service_spec.rb@@ -64,11 +64,26 @@ RSpec.describe Captain::Copilot::ChatService doexpect(messages.second[:role]).to eq('system')expect(messages.second[:content]).to include(account.id.to_s)end++ it 'uses the account model ahead of the Copilot default and installation model' do+ InstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_MODEL').update!(value: 'gpt-6-luna')+ account.update!(captain_models: { 'copilot' => 'gpt-5-mini' })++ expect(described_class.new(assistant, config).model).to eq('gpt-5-mini')+ endenddescribe '#generate_response' dolet(:service) { described_class.new(assistant, config) }+ it 'uses the Copilot default ahead of the installation model' do+ InstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_MODEL').update!(value: 'gpt-6-luna')++ expect(RubyLLM).to receive(:chat).with(model: 'gpt-5.2', protocol: :responses).and_return(mock_chat)++ service.generate_response('Hello')+ end+it 'uses the copilot feature model' doaccount.update!(captain_models: { 'copilot' => 'gpt-5.2' })@@ -114,6 +129,12 @@ RSpec.describe Captain::Copilot::ChatService doallow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(false)end+ it 'uses the Copilot default ahead of the installation model' do+ InstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_MODEL').update!(value: 'gpt-6-luna')++ expect(service.model).to eq('gpt-5.2')+ end+it 'does not increment response usage' doexpect doservice.generate_response('Hello')diff --git a/spec/enterprise/services/captain/llm/article_translation_service_spec.rb b/spec/enterprise/services/captain/llm/article_translation_service_spec.rbindex c31846f68b1..d081b820a77 100644--- a/spec/enterprise/services/captain/llm/article_translation_service_spec.rb+++ b/spec/enterprise/services/captain/llm/article_translation_service_spec.rb@@ -30,12 +30,12 @@ RSpec.describe Captain::Llm::ArticleTranslationService doendit 'uses the installation model when no account override is configured' do- create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-4.1-nano')+ create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-5-mini')expect(service).to receive(:make_api_call).with(hash_including(feature: 'help_center_article_generation',- model: 'gpt-4.1-nano'+ model: 'gpt-5-mini')).and_return(message: 'Primeros pasos')diff --git a/spec/enterprise/services/captain/llm/conversation_faq_service_spec.rb b/spec/enterprise/services/captain/llm/conversation_faq_service_spec.rbindex 83ada949f48..2e3b4968bf8 100644--- a/spec/enterprise/services/captain/llm/conversation_faq_service_spec.rb+++ b/spec/enterprise/services/captain/llm/conversation_faq_service_spec.rb@@ -23,6 +23,7 @@ RSpec.describe Captain::Llm::ConversationFaqService doallow(Captain::Llm::EmbeddingService).to receive(:new).and_return(embedding_service)allow(RubyLLM).to receive(:chat).and_return(mock_chat)allow(mock_chat).to receive(:with_temperature).and_return(mock_chat)+ allow(mock_chat).to receive(:with_thinking).and_return(mock_chat)allow(mock_chat).to receive(:with_provider_options).and_return(mock_chat)allow(mock_chat).to receive(:add_message).with(role: :user, content: 'Respond with valid JSON.')allow(mock_chat).to receive(:with_instructions).and_return(mock_chat)@@ -44,7 +45,7 @@ RSpec.describe Captain::Llm::ConversationFaqService doendit 'uses the conversation FAQ default ahead of the legacy global installation model' do- InstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_MODEL').update!(value: 'gpt-4.1-mini')+ InstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_MODEL').update!(value: 'gpt-5-mini')expect(RubyLLM).to receive(:chat).with(model: Llm::Models.default_model_for('conversation_faq_generation'), protocol: :responses@@ -54,10 +55,10 @@ RSpec.describe Captain::Llm::ConversationFaqService doendit 'keeps account conversation FAQ model overrides ahead of the feature default' do- InstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_MODEL').update!(value: 'gpt-4.1')- conversation.account.update!(captain_models: { 'conversation_faq_generation' => 'gpt-4.1-mini' })+ InstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_MODEL').update!(value: 'gpt-5.1')+ conversation.account.update!(captain_models: { 'conversation_faq_generation' => 'gpt-5-mini' })- expect(RubyLLM).to receive(:chat).with(model: 'gpt-4.1-mini', protocol: :responses).and_return(mock_chat)+ expect(RubyLLM).to receive(:chat).with(model: 'gpt-5-mini', protocol: :responses).and_return(mock_chat)described_class.new(captain_assistant, conversation).generate_suggestionsenddiff --git a/spec/enterprise/services/captain/llm/faq_generator_service_spec.rb b/spec/enterprise/services/captain/llm/faq_generator_service_spec.rbindex 5e1d24d0e12..a93f57cfc3b 100644--- a/spec/enterprise/services/captain/llm/faq_generator_service_spec.rb+++ b/spec/enterprise/services/captain/llm/faq_generator_service_spec.rb@@ -19,6 +19,7 @@ RSpec.describe Captain::Llm::FaqGeneratorService doInstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_API_KEY').update!(value: 'test-key')allow(RubyLLM).to receive(:chat).and_return(mock_chat)allow(mock_chat).to receive(:with_temperature).and_return(mock_chat)+ allow(mock_chat).to receive(:with_thinking).and_return(mock_chat)allow(mock_chat).to receive(:with_provider_options).and_return(mock_chat)allow(mock_chat).to receive(:add_message).with(role: :user, content: 'Respond with valid JSON.')allow(mock_chat).to receive(:with_instructions).and_return(mock_chat)diff --git a/spec/enterprise/services/captain/onboarding/website_analyzer_service_spec.rb b/spec/enterprise/services/captain/onboarding/website_analyzer_service_spec.rbindex b37e26f54ff..f462b8bcbdd 100644--- a/spec/enterprise/services/captain/onboarding/website_analyzer_service_spec.rb+++ b/spec/enterprise/services/captain/onboarding/website_analyzer_service_spec.rb@@ -21,6 +21,7 @@ RSpec.describe Captain::Onboarding::WebsiteAnalyzerService doallow(Captain::Tools::SimplePageCrawlService).to receive(:new).and_return(mock_crawler)allow(RubyLLM).to receive(:chat).and_return(mock_chat)allow(mock_chat).to receive(:with_temperature).and_return(mock_chat)+ allow(mock_chat).to receive(:with_thinking).and_return(mock_chat)allow(mock_chat).to receive(:with_provider_options).and_return(mock_chat)allow(mock_chat).to receive(:add_message).with(role: :user, content: 'Respond with valid JSON.')allow(mock_chat).to receive(:with_max_output_tokens).and_return(mock_chat)diff --git a/spec/enterprise/services/llm/base_ai_service_spec.rb b/spec/enterprise/services/llm/base_ai_service_spec.rbindex 4f8c1cfb871..cb3e717fc0b 100644--- a/spec/enterprise/services/llm/base_ai_service_spec.rb+++ b/spec/enterprise/services/llm/base_ai_service_spec.rb@@ -12,26 +12,26 @@ RSpec.describe Llm::BaseAiService dodescribe '#initialize' doit 'uses the installation model when no feature is provided' do- create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-4.1-nano')+ create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-5-mini')- expect(described_class.new.model).to eq('gpt-4.1-nano')+ expect(described_class.new.model).to eq('gpt-5-mini')endit 'uses the account override when feature context is provided' do- create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-4.1-nano')+ create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-5-mini')account.update!(captain_models: { 'assistant' => 'gpt-5.2' })expect(described_class.new(feature: 'assistant', account: account).model).to eq('gpt-5.2')endit 'uses the installation model when feature context has no account override' do- create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-4.1-nano')+ create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-5-mini')- expect(described_class.new(feature: 'assistant', account: account).model).to eq('gpt-4.1-nano')+ expect(described_class.new(feature: 'assistant', account: account).model).to eq('gpt-5-mini')endit 'uses the Captain V2 assistant default ahead of the installation model' do- create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-4.1-nano')+ create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-5-mini')account.enable_features!('captain_integration')expect(described_class.new(feature: 'assistant', account: account).model).to eq('gpt-5.2')@@ -58,7 +58,7 @@ RSpec.describe Llm::BaseAiService doit 'retains the existing JSON format and protocol on custom endpoints' doInstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_ENDPOINT').update!(value: 'https://custom.example')- chat = described_class.new(feature: 'document_faq_generation', account: account).json_chat(model: 'gpt-4.1')+ chat = described_class.new(feature: 'document_faq_generation', account: account).json_chat(model: 'gpt-6-luna')chat.add_message(role: :user, content: 'Generate JSON FAQs.')expect(chat.render).to include(messages: an_instance_of(Array), response_format: { type: 'json_object' })@@ -107,10 +107,11 @@ RSpec.describe Llm::BaseAiService doit 'sets temperature when the model registry marks it supported' dollm_chat = instance_double(RubyLLM::Chat)configured_chat = instance_double(RubyLLM::Chat)- allow(RubyLLM).to receive(:chat).with(model: 'gpt-4.1-mini', protocol: :responses).and_return(llm_chat)+ allow(RubyLLM).to receive(:chat).with(model: 'gpt-6-luna', protocol: :responses).and_return(llm_chat)+ allow(llm_chat).to receive(:with_thinking).with(effort: :none).and_return(llm_chat)allow(llm_chat).to receive(:with_temperature).with(0.7).and_return(configured_chat)- expect(service.chat(model: 'gpt-4.1-mini', temperature: 0.7)).to eq(configured_chat)+ expect(service.chat(model: 'gpt-6-luna', temperature: 0.7)).to eq(configured_chat)endendenddiff --git a/spec/enterprise/services/llm/speech_to_text_service_spec.rb b/spec/enterprise/services/llm/speech_to_text_service_spec.rbindex ebf7518da9c..512115999d5 100644--- a/spec/enterprise/services/llm/speech_to_text_service_spec.rb+++ b/spec/enterprise/services/llm/speech_to_text_service_spec.rb@@ -9,7 +9,7 @@ RSpec.describe Llm::SpeechToTextService, type: :service dobefore doInstallationConfig.find_or_create_by!(name: 'CAPTAIN_OPEN_AI_API_KEY') { |config| config.value = 'test-api-key' }- InstallationConfig.find_or_create_by!(name: 'CAPTAIN_OPEN_AI_MODEL') { |config| config.value = 'gpt-4o-mini' }+ InstallationConfig.find_or_create_by!(name: 'CAPTAIN_OPEN_AI_MODEL') { |config| config.value = 'gpt-6-luna' }attachment.file.attach(io: File.open(Rails.public_path.join('audio/widget/ding.mp3')),@@ -108,7 +108,7 @@ RSpec.describe Llm::SpeechToTextService, type: :service doit 'uses the audio transcription feature model' doexpect(audio_api).to receive(:transcribe).with(- parameters: hash_including(model: 'gpt-4o-mini-transcribe', temperature: 0.0)+ parameters: hash_including(model: 'gpt-transcribe', temperature: 0.0)).and_return({ 'text' => 'Audio transcript' })expect(service.perform).to eq('Audio transcript')diff --git a/spec/enterprise/services/messages/audio_transcription_service_spec.rb b/spec/enterprise/services/messages/audio_transcription_service_spec.rbindex b2d18b7bb2b..a3fac875152 100644--- a/spec/enterprise/services/messages/audio_transcription_service_spec.rb+++ b/spec/enterprise/services/messages/audio_transcription_service_spec.rb@@ -9,7 +9,7 @@ RSpec.describe Messages::AudioTranscriptionService, type: :service dobefore do# Create required installation configsInstallationConfig.find_or_create_by!(name: 'CAPTAIN_OPEN_AI_API_KEY') { |config| config.value = 'test-api-key' }- InstallationConfig.find_or_create_by!(name: 'CAPTAIN_OPEN_AI_MODEL') { |config| config.value = 'gpt-4o-mini' }+ InstallationConfig.find_or_create_by!(name: 'CAPTAIN_OPEN_AI_MODEL') { |config| config.value = 'gpt-6-luna' }# Mock usage limits for transcription to be availableallow(account).to receive(:usage_limits).and_return(diff --git a/spec/lib/captain/base_task_service_spec.rb b/spec/lib/captain/base_task_service_spec.rbindex 2b5890f035a..ba040f6ce5c 100644--- a/spec/lib/captain/base_task_service_spec.rb+++ b/spec/lib/captain/base_task_service_spec.rb@@ -113,7 +113,7 @@ RSpec.describe Captain::BaseTaskService doenddescribe '#make_api_call' do- let(:model) { 'gpt-4' }+ let(:model) { 'gpt-5.2' }let(:messages) { [{ role: 'system', content: 'Test' }, { role: 'user', content: 'Hello' }] }let(:mock_chat) { instance_double(RubyLLM::Chat) }let(:mock_context) { instance_double(RubyLLM::Context, chat: mock_chat) }@@ -122,6 +122,7 @@ RSpec.describe Captain::BaseTaskService dobefore doallow(Llm::Config).to receive(:with_api_key).and_yield(mock_context)allow(mock_chat).to receive(:with_instructions)+ allow(mock_chat).to receive(:with_thinking).and_return(mock_chat)allow(mock_chat).to receive(:ask).and_return(mock_response)end@@ -169,11 +170,11 @@ RSpec.describe Captain::BaseTaskService doendit 'uses the resolved feature model for the request and instrumentation' do- account.update!(captain_models: { 'editor' => 'gpt-4.1' })+ account.update!(captain_models: { 'editor' => 'gpt-5.1' })- expect(mock_context).to receive(:chat).with(model: 'gpt-4.1', protocol: :responses).and_return(mock_chat)+ expect(mock_context).to receive(:chat).with(model: 'gpt-5.1', protocol: :responses).and_return(mock_chat)expect(service).to receive(:instrument_llm_call).with(- hash_including(model: 'gpt-4.1', feature_name: 'test_event')+ hash_including(model: 'gpt-5.1', feature_name: 'test_event')).and_call_originalservice.send(:make_api_call, feature: 'editor', messages: messages)@@ -192,9 +193,9 @@ RSpec.describe Captain::BaseTaskService doendit 'prefers account overrides over supplied feature fallback models' do- account.update!(captain_models: { 'help_center_article_generation' => 'gpt-4.1' })+ account.update!(captain_models: { 'help_center_article_generation' => 'gpt-5.1' })- expect(mock_context).to receive(:chat).with(model: 'gpt-4.1', protocol: :responses).and_return(mock_chat)+ expect(mock_context).to receive(:chat).with(model: 'gpt-5.1', protocol: :responses).and_return(mock_chat)service.send(:make_api_call, feature: 'help_center_article_generation', model: 'gpt-5.2', messages: messages)end@@ -228,7 +229,7 @@ RSpec.describe Captain::BaseTaskService doenddescribe 'chat setup' do- let(:model) { 'gpt-4' }+ let(:model) { 'gpt-5.2' }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: 'Response', tokens: RubyLLM::Tokens.new(input: 10, output: 20)) }@@ -282,7 +283,7 @@ RSpec.describe Captain::BaseTaskService doenddescribe 'error handling' do- let(:model) { 'gpt-4' }+ let(:model) { 'gpt-5.2' }let(:messages) { [{ role: 'user', content: 'Hello' }] }let(:error) { StandardError.new('API Error') }let(:exception_tracker) { instance_double(ChatwootExceptionTracker) }diff --git a/spec/lib/captain/reply_suggestion_service_spec.rb b/spec/lib/captain/reply_suggestion_service_spec.rbindex 0874ab27b1f..2bcfdfc6c10 100644--- a/spec/lib/captain/reply_suggestion_service_spec.rb+++ b/spec/lib/captain/reply_suggestion_service_spec.rb@@ -23,6 +23,7 @@ RSpec.describe Captain::ReplySuggestionService doallow(mock_chat).to receive(:with_tools).and_return(mock_chat)allow(mock_chat).to receive(:after_message).and_return(mock_chat)allow(mock_chat).to receive(:with_instructions) { |msg| captured_messages << { role: 'system', content: msg } }+ allow(mock_chat).to receive(:with_thinking).and_return(mock_chat)allow(mock_chat).to receive(:add_message) { |args| captured_messages << args }allow(mock_chat).to receive(:ask) do |msg|captured_messages << { role: 'user', content: msg }diff --git a/spec/lib/captain/rewrite_service_spec.rb b/spec/lib/captain/rewrite_service_spec.rbindex 41d879fbac8..7fdf4255ee1 100644--- a/spec/lib/captain/rewrite_service_spec.rb+++ b/spec/lib/captain/rewrite_service_spec.rb@@ -15,6 +15,7 @@ RSpec.describe Captain::RewriteService doInstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_API_KEY').update!(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(:with_thinking).and_return(mock_chat)allow(mock_chat).to receive(:ask).and_return(mock_response)# Stub captain enabled check to allow specs to test base functionality# without enterprise module interferencediff --git a/spec/lib/captain/summary_service_spec.rb b/spec/lib/captain/summary_service_spec.rbindex 0d98128be1b..ba9959707ff 100644--- a/spec/lib/captain/summary_service_spec.rb+++ b/spec/lib/captain/summary_service_spec.rb@@ -13,6 +13,7 @@ RSpec.describe Captain::SummaryService doInstallationConfig.find_or_initialize_by(name: 'CAPTAIN_OPEN_AI_API_KEY').update!(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(:with_thinking).and_return(mock_chat)allow(mock_chat).to receive(:ask).and_return(mock_response)# Stub captain enabled check to allow specs to test base functionality# without enterprise module interferencediff --git a/spec/lib/integrations/llm_base_service_spec.rb b/spec/lib/integrations/llm_base_service_spec.rbindex 8f50156503a..9ca46f4109a 100644--- a/spec/lib/integrations/llm_base_service_spec.rb+++ b/spec/lib/integrations/llm_base_service_spec.rb@@ -8,7 +8,7 @@ RSpec.describe Integrations::LlmBaseService dolet(:event) { { 'name' => 'summarize', 'data' => { 'conversation_display_id' => conversation.display_id } } }let(:service) { described_class.new(hook: hook, event: event) }let(:error) { StandardError.new('API Error') }- let(:body) { { model: 'gpt-4', messages: [{ role: 'user', content: 'Hello' }] }.to_json }+ let(:body) { { model: 'gpt-6-luna', messages: [{ role: 'user', content: 'Hello' }] }.to_json }before { allow(Integrations::Openai::KeyValidator).to receive(:valid?).and_return(true) }diff --git a/spec/lib/integrations/llm_instrumentation_spec.rb b/spec/lib/integrations/llm_instrumentation_spec.rbindex 031d6e47e1f..2d65547afbd 100644--- a/spec/lib/integrations/llm_instrumentation_spec.rb+++ b/spec/lib/integrations/llm_instrumentation_spec.rb@@ -26,7 +26,7 @@ RSpec.describe Integrations::LlmInstrumentation doaccount_id: 123,conversation_id: 456,feature_name: 'reply_suggestion',- model: 'gpt-4o-mini',+ model: 'gpt-6-luna',messages: [{ 'role' => 'user', 'content' => 'Hello' }],temperature: 0.7}@@ -141,7 +141,7 @@ RSpec.describe Integrations::LlmInstrumentation doinstance.instrument_llm_call(params) { 'result' }expect(mock_span).to have_received(:set_attribute).with('gen_ai.provider.name', 'openai')- expect(mock_span).to have_received(:set_attribute).with('gen_ai.request.model', 'gpt-4o-mini')+ expect(mock_span).to have_received(:set_attribute).with('gen_ai.request.model', 'gpt-6-luna')expect(mock_span).to have_received(:set_attribute).with('gen_ai.request.temperature', 0.7)enddiff --git a/spec/lib/llm/feature_router_spec.rb b/spec/lib/llm/feature_router_spec.rbindex f6fdff2cbbc..0b2dde938ca 100644--- a/spec/lib/llm/feature_router_spec.rb+++ b/spec/lib/llm/feature_router_spec.rb@@ -16,20 +16,20 @@ RSpec.describe Llm::FeatureRouter doexpect(resolved).to eq(feature: 'editor',provider: 'openai',- model: 'gpt-4.1-mini',+ model: 'gpt-6-luna',source: :default)endit 'uses a valid account model override' do- account.update!(captain_models: { 'editor' => 'gpt-4.1' })+ account.update!(captain_models: { 'editor' => 'gpt-5.1' })resolved = described_class.resolve(feature: 'editor', account: account)expect(resolved).to include(feature: 'editor',provider: 'openai',- model: 'gpt-4.1',+ model: 'gpt-5.1',source: :account_override)end@@ -119,7 +119,7 @@ RSpec.describe Llm::FeatureRouter doresolved = described_class.resolve(feature: 'editor', account: account)expect(resolved).to include(- model: 'gpt-4.1-mini',+ model: 'gpt-6-luna',source: :default)end@@ -130,7 +130,7 @@ RSpec.describe Llm::FeatureRouter doresolved = described_class.resolve(feature: 'editor', account: account)expect(resolved).to include(- model: 'gpt-4.1-mini',+ model: 'gpt-6-luna',source: :default)enddiff --git a/spec/lib/llm/models_spec.rb b/spec/lib/llm/models_spec.rbindex 522407da226..751418cd693 100644--- a/spec/lib/llm/models_spec.rb+++ b/spec/lib/llm/models_spec.rb@@ -27,14 +27,14 @@ RSpec.describe Llm::Models doendit 'routes each FAQ operation independently' do- expect(described_class.default_model_for('document_faq_generation')).to eq('gpt-4.1-mini')+ expect(described_class.default_model_for('document_faq_generation')).to eq('gpt-6-luna')expect(described_class.default_model_for('conversation_faq_generation')).to eq('gpt-5.2')- expect(described_class.default_model_for('conversation_faq_matching')).to eq('gpt-4.1-mini')+ expect(described_class.default_model_for('conversation_faq_matching')).to eq('gpt-6-luna')endit 'offers only supported OpenAI models for conversation completion' doexpect(described_class.models_for('conversation_completion')).to eq(- %w[gpt-4.1-mini gpt-5-mini gpt-4.1 gpt-5.1 gpt-5.2]+ %w[gpt-6-luna gpt-5-mini gpt-5.1 gpt-5.2])endend@@ -56,10 +56,10 @@ RSpec.describe Llm::Models doit 'returns model metadata for a feature' doconfig = described_class.feature_config('editor')- expect(config[:default]).to eq('gpt-4.1-mini')+ expect(config[:default]).to eq('gpt-6-luna')expect(config[:models].first).to include(- id: 'gpt-4.1-mini',- display_name: 'GPT-4.1 Mini',+ id: 'gpt-6-luna',+ display_name: 'GPT-6 Luna',provider: 'openai',credit_multiplier: 1)diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rbindex bff67193c43..4107bab759b 100644--- a/spec/models/account_spec.rb+++ b/spec/models/account_spec.rb@@ -495,11 +495,11 @@ RSpec.describe Account dodescribe 'with saved model preferences' doit 'returns saved preferences merged with defaults' do- account.update!(captain_models: { 'editor' => 'gpt-4.1-mini', 'assistant' => 'gpt-5.2' })+ account.update!(captain_models: { 'editor' => 'gpt-5-mini', 'assistant' => 'gpt-5.2' })prefs = account.captain_preferences- expect(prefs[:models]['editor']).to eq('gpt-4.1-mini')+ expect(prefs[:models]['editor']).to eq('gpt-5-mini')expect(prefs[:models]['assistant']).to eq('gpt-5.2')expect(prefs[:models]['copilot']).to eq(Llm::Models.default_model_for('copilot'))end@@ -526,13 +526,13 @@ RSpec.describe Account doendit 'accepts valid model for a feature' do- account.captain_models = { 'editor' => 'gpt-4.1-mini', 'help_center_query_translation' => 'gpt-4.1-nano' }+ account.captain_models = { 'editor' => 'gpt-5-mini', 'help_center_query_translation' => 'gpt-5-mini' }expect(account).to be_validendit 'rejects unknown feature keys' do- account.captain_models = { 'unknown_feature' => 'gpt-4.1' }+ account.captain_models = { 'unknown_feature' => 'gpt-5.1' }expect(account).not_to be_validexpect(account.errors[:captain_models]).to include("'unknown_feature' is not a known feature")diff --git a/spec/models/concerns/captain_featurable_spec.rb b/spec/models/concerns/captain_featurable_spec.rbindex 62206aee70a..2a05a492f1c 100644--- a/spec/models/concerns/captain_featurable_spec.rb+++ b/spec/models/concerns/captain_featurable_spec.rb@@ -61,16 +61,16 @@ RSpec.describe CaptainFeaturable docontext 'when models are explicitly configured' dobefore doaccount.update!(captain_models: {- 'editor' => 'gpt-4.1-mini',+ 'editor' => 'gpt-5-mini','assistant' => 'gpt-5.1',- 'help_center_query_translation' => 'gpt-4.1-mini'+ 'help_center_query_translation' => 'gpt-5-mini'})endit 'returns configured models for configured features' do- expect(account.captain_editor_model).to eq('gpt-4.1-mini')+ expect(account.captain_editor_model).to eq('gpt-5-mini')expect(account.captain_assistant_model).to eq('gpt-5.1')- expect(account.captain_help_center_query_translation_model).to eq('gpt-4.1-mini')+ expect(account.captain_help_center_query_translation_model).to eq('gpt-5-mini')endit 'returns default models for unconfigured features' do@@ -87,6 +87,13 @@ RSpec.describe CaptainFeaturable doit 'falls back to default model' doexpect(account.captain_editor_model).to eq(Llm::Models.default_model_for('editor'))end++ it 'rejects the change but still saves other attributes once stored' do+ expect(account).not_to be_valid++ account.save(validate: false)+ expect(account.reload.update(name: 'Renamed')).to be(true)+ endendcontext 'when captain_models is nil' do@@ -114,7 +121,7 @@ RSpec.describe CaptainFeaturable doendit 'model methods use the same logic as captain_preferences[:models]' do- account.update!(captain_models: { 'editor' => 'gpt-4.1-mini', 'assistant' => 'gpt-5.2' })+ account.update!(captain_models: { 'editor' => 'gpt-5-mini', 'assistant' => 'gpt-5.2' })prefs = account.captain_preferencesLlm::Models.feature_keys.each do |feature_key|