Files
moreminimore-chat/lib/llm/feature_router.rb
Aakash Bakhle 13de83d1dc refactor(captain): route conversation completion by feature (#15317)
Conversation completion evaluations now use a dedicated internal LLM
feature with GPT 4.1 as the default. The internal route keeps the
completion model separate from the installation wide Captain model
override and from the assistant route, which can use GPT 5.2 for Captain
V2 accounts. Evaluations continue to use the installation API key and do
not consume Captain response credits.

## What changed

Added an internal `conversation_completion` feature to the LLM model
config and excluded internal features from account preferences, the
Captain settings API, and Super Admin model overrides.

Updated `Captain::ConversationCompletionService` to resolve its model
through `Llm::FeatureRouter`.

Added focused service and request coverage for model routing and
settings visibility.
2026-08-13 13:54:35 +05:30

42 lines
1.2 KiB
Ruby

module Llm::FeatureRouter
class UnknownFeatureError < StandardError; end
CAPTAIN_V2_ASSISTANT_MODEL = 'gpt-5.2'.freeze
class << self
def resolve(feature:, account: nil)
feature_key = feature.to_s
raise UnknownFeatureError, "Unknown LLM feature: #{feature_key}" unless Llm::Models.feature?(feature_key)
model = account_model_override(account, feature_key)
source = model.present? ? :account_override : :default
model ||= captain_v2_assistant_model(account, feature_key)
model ||= Llm::Models.default_model_for(feature_key)
{
feature: feature_key,
provider: Llm::Models.provider_for(model),
model: model,
source: source
}
end
private
def account_model_override(account, feature_key)
return if Llm::Models.internal_feature?(feature_key)
model = account&.captain_models&.[](feature_key).presence
return unless model
return model if Llm::Models.valid_model_for?(feature_key, model)
end
def captain_v2_assistant_model(account, feature_key)
return unless feature_key == 'assistant'
return unless account&.feature_enabled?('captain_integration_v2')
CAPTAIN_V2_ASSISTANT_MODEL
end
end
end