DEV: Updates to the summarization strategy API (#301)
Introduced by discourse/discourse#24489 In the future, this change will let us log who requested the summary in the `AiApiAuditLog`.:
This commit is contained in:
parent
493b48477a
commit
e0691e70e8
|
@ -1,3 +1,4 @@
|
|||
< 3.2.0.beta4-dev: 493b48477a9288f2f1b6f021954088705a6673d6
|
||||
< 3.2.0.beta2-dev: 3bced1c6f525553fe2b5b79d29bd66c1cf2a47d5
|
||||
3.1.999: c0415bb7eb878b1b7abf112d65cba981030df8df
|
||||
< 3.2.0.beta1-dev: 3e7c99de894b03e9161d9481da118fe893991a1d
|
||||
|
|
|
@ -16,7 +16,7 @@ module DiscourseAi
|
|||
:model,
|
||||
to: :completion_model
|
||||
|
||||
def summarize(content, &on_partial_blk)
|
||||
def summarize(content, _user, &on_partial_blk)
|
||||
opts = content.except(:contents)
|
||||
|
||||
chunks = split_into_chunks(content[:contents])
|
||||
|
|
|
@ -16,7 +16,7 @@ module DiscourseAi
|
|||
:model,
|
||||
to: :completion_model
|
||||
|
||||
def summarize(content, &on_partial_blk)
|
||||
def summarize(content, _user, &on_partial_blk)
|
||||
opts = content.except(:contents)
|
||||
|
||||
{
|
||||
|
|
|
@ -13,11 +13,13 @@ RSpec.describe DiscourseAi::Summarization::Strategies::FoldContent do
|
|||
DiscourseAi::Tokenizer::BertTokenizer.size("(1 asd said: This is a text ") + 3
|
||||
end
|
||||
|
||||
let(:user) { User.new }
|
||||
|
||||
let(:content) { { contents: [{ poster: "asd", id: 1, text: summarize_text }] } }
|
||||
|
||||
context "when the content to summarize fits in a single call" do
|
||||
it "does one call to summarize content" do
|
||||
result = strategy.summarize(content)
|
||||
result = strategy.summarize(content, user)
|
||||
|
||||
expect(model.summarization_calls).to eq(1)
|
||||
expect(result[:summary]).to eq(DummyCompletionModel::SINGLE_SUMMARY)
|
||||
|
@ -28,7 +30,7 @@ RSpec.describe DiscourseAi::Summarization::Strategies::FoldContent do
|
|||
it "summarizes each chunk and then concatenates them" do
|
||||
content[:contents] << { poster: "asd2", id: 2, text: summarize_text }
|
||||
|
||||
result = strategy.summarize(content)
|
||||
result = strategy.summarize(content, user)
|
||||
|
||||
expect(model.summarization_calls).to eq(3)
|
||||
expect(result[:summary]).to eq(DummyCompletionModel::CONCATENATED_SUMMARIES)
|
||||
|
|
|
@ -10,13 +10,15 @@ RSpec.describe DiscourseAi::Summarization::Strategies::TruncateContent do
|
|||
let(:model_tokens) { summarize_text.length }
|
||||
let(:model) { DummyCompletionModel.new(model_tokens) }
|
||||
|
||||
let(:user) { User.new }
|
||||
|
||||
let(:content) { { contents: [{ poster: "asd", id: 1, text: summarize_text }] } }
|
||||
|
||||
context "when the content to summarize doesn't fit in a single call" do
|
||||
it "summarizes a truncated version" do
|
||||
content[:contents] << { poster: "asd2", id: 2, text: summarize_text }
|
||||
|
||||
result = strategy.summarize(content)
|
||||
result = strategy.summarize(content, user)
|
||||
|
||||
expect(model.summarization_calls).to eq(1)
|
||||
expect(result[:summary]).to eq(DummyCompletionModel::SINGLE_SUMMARY)
|
||||
|
|
Loading…
Reference in New Issue