mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-24 23:13:27 +00:00
This is an interim fix so we can at least tell what feature is being used for what LLM. It also adds some test coverage to the feature page.
69 lines
1.7 KiB
Ruby
69 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Admin
|
|
class AiFeaturesController < ::Admin::AdminController
|
|
requires_plugin ::DiscourseAi::PLUGIN_NAME
|
|
|
|
def index
|
|
render json: serialize_modules(DiscourseAi::Configuration::Module.all)
|
|
end
|
|
|
|
def edit
|
|
raise Discourse::InvalidParameters.new(:id) if params[:id].blank?
|
|
|
|
a_module = DiscourseAi::Configuration::Module.find_by(id: params[:id].to_i)
|
|
|
|
render json: serialize_module(a_module)
|
|
end
|
|
|
|
private
|
|
|
|
def serialize_modules(modules)
|
|
modules.map { |a_module| serialize_module(a_module) }
|
|
end
|
|
|
|
def serialize_module(a_module)
|
|
return nil if a_module.blank?
|
|
|
|
{
|
|
id: a_module.id,
|
|
module_name: a_module.name,
|
|
module_enabled: a_module.enabled?,
|
|
features: a_module.features.map { |f| serialize_feature(f) },
|
|
}
|
|
end
|
|
|
|
def serialize_feature(feature)
|
|
{
|
|
name: feature.name,
|
|
persona: serialize_persona(persona_id_obj_hash[feature.persona_id]),
|
|
llm_model: {
|
|
id: feature.llm_model&.id,
|
|
name: feature.llm_model&.name,
|
|
},
|
|
enabled: feature.enabled?,
|
|
}
|
|
end
|
|
|
|
def serialize_persona(persona)
|
|
return nil if persona.blank?
|
|
|
|
serialize_data(persona, AiFeaturesPersonaSerializer, root: false)
|
|
end
|
|
|
|
private
|
|
|
|
def persona_id_obj_hash
|
|
@persona_id_obj_hash ||=
|
|
begin
|
|
setting_names = DiscourseAi::Configuration::Feature.all_persona_setting_names
|
|
ids = setting_names.map { |sn| SiteSetting.public_send(sn) }
|
|
|
|
AiPersona.where(id: ids).index_by(&:id)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|