FIX: call the right method to summarize with truncation (#328)

This commit is contained in:
Roman Rizzi 2023-12-01 10:17:24 -03:00 committed by GitHub
parent 7f36175ad3
commit 3bc010b686
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 2 deletions

View File

@ -20,8 +20,7 @@ module DiscourseAi
opts = content.except(:contents) opts = content.except(:contents)
{ {
summary: summary: summarize_with_truncation(content[:contents], opts, &on_partial_blk),
completion_model.summarize_with_truncation(content[:contents], opts, &on_partial_blk),
chunks: [], chunks: [],
} }
end end

View File

@ -0,0 +1,46 @@
# frozen_string_literal: true
RSpec.describe DiscourseAi::Summarization::Strategies::TruncateContent do
subject(:strategy) { described_class.new(model) }
before { SiteSetting.ai_summarization_discourse_service_api_endpoint = "https://test.com" }
let(:summarize_text) { "This is a text" }
let(:full_text) { "(1 asd said: #{summarize_text} " }
let(:model_tokens) { ::DiscourseAi::Tokenizer::BertTokenizer.size(full_text) - 5 }
let(:model) do
DiscourseAi::Summarization::Models::Discourse.new(
"flan-t5-base-samsum",
max_tokens: model_tokens,
)
end
let(:content) { { contents: [{ poster: "asd", id: 1, text: summarize_text }] } }
let(:summarized_text) { "this is a single summary" }
let(:user) { User.new }
describe "#summary" do
it "truncates the content and requests a summary" do
truncated =
::DiscourseAi::Tokenizer::BertTokenizer.truncate(
"(1 asd said: This is a text ",
model_tokens,
)
WebMock
.stub_request(
:post,
"#{SiteSetting.ai_summarization_discourse_service_api_endpoint}/api/v1/classify",
)
.with(body: JSON.dump(model: model.model, content: truncated))
.to_return(status: 200, body: JSON.dump({ summary_text: summarized_text }))
summary = strategy.summarize(content, user).dig(:summary)
expect(summary).to eq(summarized_text)
end
end
end