DEV: Use explicit serializers for all models (#691)
This commit is contained in:
parent
b863ddc94b
commit
8e83c091a2
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue