DEV: Pass the user who requested the summary to the strategy. (#24489)

This change allows the `discourse-ai` plugin to log the user who requested the summary in the `AiApiAuditLog`.
This commit is contained in:
Roman Rizzi 2023-11-21 13:27:27 -03:00 committed by GitHub
parent 18cbb37e23
commit 75e2c6b506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 4 deletions

View File

@ -35,7 +35,7 @@ class TopicSummarization
content[:contents] << { poster: username, id: pn, text: raw }
end
summarization_result = strategy.summarize(content, &on_partial_blk)
summarization_result = strategy.summarize(content, user, &on_partial_blk)
cache_summary(summarization_result, targets_data.map(&:first), topic)
end

View File

@ -75,6 +75,8 @@ module Summarization
# @param &on_partial_blk { Block - Optional } - If the strategy supports it, the passed block
# will get called with partial summarized text as its generated.
#
# @param current_user { User } - User requesting the summary.
#
# @returns { Hash } - The summarized content, plus chunks if the content couldn't be summarized in one pass. Example:
# {
# summary: "This is the final summary",
@ -83,7 +85,7 @@ module Summarization
# { ids: [post_1.post_number, post_2.post_number], summary: "this is the second chunk" },
# ],
# }
def summarize(content)
def summarize(content, current_user)
raise NotImplemented
end

View File

@ -31,7 +31,7 @@ class Chat::Api::SummariesController < Chat::ApiController
if content[:contents].empty?
I18n.t("chat.summaries.no_targets")
else
strategy.summarize(content).dig(:summary)
strategy.summarize(content, current_user).dig(:summary)
end
render json: { summary: summarized_text }

View File

@ -21,7 +21,7 @@ class DummyCustomSummarization < Summarization::Base
"dummy"
end
def summarize(_content)
def summarize(_content, _user)
@summarization_result.tap { |result| yield(result[:summary]) if block_given? }
end
end