Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 1b6c1ba

Browse files
committed
DEV: Add eval for summarization
1 parent af47873 commit 1b6c1ba

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

evals/lib/eval.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def run(llm:)
6060
prompt_call(llm, **args)
6161
when "edit_artifact"
6262
edit_artifact(llm, **args)
63+
when "summarization"
64+
summarization(llm, **args)
6365
end
6466

6567
if expected_output
@@ -312,4 +314,35 @@ def valid_javascript?(str)
312314
rescue StandardError
313315
false
314316
end
317+
318+
def summarization(llm, input:)
319+
topic =
320+
Topic.create!(
321+
category: Category.last,
322+
title: "Eval topic for topic summarization",
323+
id: -99,
324+
user_id: Discourse.system_user.id,
325+
)
326+
post = Post.create!(topic: topic, id: -99, user_id: Discourse.system_user.id, raw: input)
327+
328+
strategy =
329+
DiscourseAi::Summarization::FoldContent.new(
330+
llm.llm_proxy,
331+
DiscourseAi::Summarization::Strategies::TopicSummary.new(topic),
332+
)
333+
334+
result = []
335+
336+
summary =
337+
DiscourseAi::TopicSummarization
338+
.new(strategy, Discourse.system_user)
339+
.summarize { |partial| result << partial }
340+
341+
summarized_text = summary.summarized_text
342+
343+
topic.destroy
344+
post.destroy
345+
346+
summarized_text
347+
end
315348
end

0 commit comments

Comments
 (0)