diff --git a/app/controllers/discourse_ai/admin/ai_llms_controller.rb b/app/controllers/discourse_ai/admin/ai_llms_controller.rb index 2d6e087e..9098f305 100644 --- a/app/controllers/discourse_ai/admin/ai_llms_controller.rb +++ b/app/controllers/discourse_ai/admin/ai_llms_controller.rb @@ -36,9 +36,9 @@ module DiscourseAi llm_model = LlmModel.new(ai_llm_params) if llm_model.save llm_model.toggle_companion_user - render json: { ai_persona: llm_model }, status: :created + render json: { ai_persona: LlmModelSerializer.new(llm_model) }, status: :created else - render_json_error llm_model + render_json_error LlmModelSerializer.new(llm_model) end end @@ -47,9 +47,9 @@ module DiscourseAi if llm_model.update(ai_llm_params(updating: llm_model)) llm_model.toggle_companion_user - render json: llm_model + render json: LlmModelSerializer.new(llm_model) else - render_json_error llm_model + render_json_error LlmModelSerializer.new(llm_model) end end diff --git a/app/controllers/discourse_ai/admin/ai_personas_controller.rb b/app/controllers/discourse_ai/admin/ai_personas_controller.rb index fbd3dce7..7dee516d 100644 --- a/app/controllers/discourse_ai/admin/ai_personas_controller.rb +++ b/app/controllers/discourse_ai/admin/ai_personas_controller.rb @@ -43,7 +43,10 @@ module DiscourseAi if ai_persona.save RagDocumentFragment.link_persona_and_uploads(ai_persona, attached_upload_ids) - render json: { ai_persona: ai_persona }, status: :created + render json: { + ai_persona: LocalizedAiPersonaSerializer.new(ai_persona, root: false), + }, + status: :created else render_json_error ai_persona end @@ -58,9 +61,9 @@ module DiscourseAi if @ai_persona.update(ai_persona_params.except(:rag_uploads)) RagDocumentFragment.update_persona_uploads(@ai_persona, attached_upload_ids) - render json: @ai_persona + render json: LocalizedAiPersonaSerializer.new(@ai_persona, root: false) else - render_json_error @ai_persona + render_json_error LocalizedAiPersonaSerializer.new(@ai_persona, root: false) end end @@ -68,7 +71,7 @@ module DiscourseAi if @ai_persona.destroy head :no_content else - render_json_error @ai_persona + render_json_error LocalizedAiPersonaSerializer.new(@ai_persona, root: false) end end diff --git a/app/controllers/discourse_ai/ai_bot/bot_controller.rb b/app/controllers/discourse_ai/ai_bot/bot_controller.rb index 1a24215e..e5d5bcf0 100644 --- a/app/controllers/discourse_ai/ai_bot/bot_controller.rb +++ b/app/controllers/discourse_ai/ai_bot/bot_controller.rb @@ -18,7 +18,7 @@ module DiscourseAi debug_info = AiApiAuditLog.where(post: posts).order(created_at: :desc).first - render json: debug_info, status: 200 + render json: AiApiAuditLogSerializer.new(debug_info, root: false), status: 200 end def stop_streaming_response diff --git a/app/serializers/ai_api_audit_log_serializer.rb b/app/serializers/ai_api_audit_log_serializer.rb new file mode 100644 index 00000000..0c438a7b --- /dev/null +++ b/app/serializers/ai_api_audit_log_serializer.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AiApiAuditLogSerializer < ApplicationSerializer + attributes :id, + :provider_id, + :user_id, + :request_tokens, + :response_tokens, + :raw_request_payload, + :raw_response_payload, + :topic_id, + :post_id, + :feature_name, + :language_model, + :created_at +end diff --git a/app/serializers/ai_chat_channel_serializer.rb b/app/serializers/ai_chat_channel_serializer.rb index 260f4b3f..4f9869c4 100644 --- a/app/serializers/ai_chat_channel_serializer.rb +++ b/app/serializers/ai_chat_channel_serializer.rb @@ -3,6 +3,17 @@ class AiChatChannelSerializer < ApplicationSerializer attributes :id, :chatable, :chatable_type, :chatable_url, :slug + def chatable + case object.chatable_type + when "Category" + BasicCategorySerializer.new(object.chatable, root: false).as_json + when "DirectMessage" + Chat::DirectMessageSerializer.new(object.chatable, scope: scope, root: false).as_json + when "Site" + nil + end + end + def title # Display all participants for a DM. # For category channels, the argument is ignored.