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

Commit e8eed71

Browse files
authored
FIX: Truncate OP for gists to help the model focus on the latest posts (#883)
1 parent 32fb023 commit e8eed71

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

lib/summarization/fold_content.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ def fold(items, summary, cursor, user, &on_partial_blk)
121121
prompt =
122122
(
123123
if summary.blank?
124-
strategy.first_summary_prompt(iteration_content)
124+
strategy.first_summary_prompt(iteration_content, tokenizer)
125125
else
126-
strategy.summary_extension_prompt(summary, iteration_content)
126+
strategy.summary_extension_prompt(summary, iteration_content, tokenizer)
127127
end
128128
)
129129

lib/summarization/strategies/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def targets_data
3434
end
3535

3636
# @returns { DiscourseAi::Completions::Prompt } - Prompt passed to the LLM when extending an existing summary.
37-
def summary_extension_prompt(_summary, _texts_to_summarize)
37+
def summary_extension_prompt(_summary, _texts_to_summarize, _tokenizer)
3838
raise NotImplementedError
3939
end
4040

4141
# @returns { DiscourseAi::Completions::Prompt } - Prompt passed to the LLM for summarizing a single chunk of content.
42-
def first_summary_prompt(_input)
42+
def first_summary_prompt(_input, _tokenizer)
4343
raise NotImplementedError
4444
end
4545

lib/summarization/strategies/chat_messages.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def targets_data
2323
.map { { id: _1, poster: _2, text: _3 } }
2424
end
2525

26-
def summary_extension_prompt(summary, contents)
26+
def summary_extension_prompt(summary, contents, _tokenizer)
2727
input =
2828
contents
2929
.map { |item| "(#{item[:id]} #{item[:poster]} said: #{item[:text]} " }
@@ -63,7 +63,7 @@ def summary_extension_prompt(summary, contents)
6363
prompt
6464
end
6565

66-
def first_summary_prompt(contents)
66+
def first_summary_prompt(contents, _tokenizer)
6767
content_title = target.name
6868
input =
6969
contents.map { |item| "(#{item[:id]} #{item[:poster]} said: #{item[:text]} " }.join

lib/summarization/strategies/hot_topic_gists.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def targets_data
5757
end
5858
end
5959

60-
def summary_extension_prompt(summary, contents)
60+
def summary_extension_prompt(summary, contents, _tokenizer)
6161
statements =
6262
contents
6363
.to_a
@@ -98,11 +98,22 @@ def summary_extension_prompt(summary, contents)
9898
prompt
9999
end
100100

101-
def first_summary_prompt(contents)
101+
def first_summary_prompt(contents, tokenizer)
102102
content_title = target.title
103103
statements =
104104
contents.to_a.map { |item| "(#{item[:id]} #{item[:poster]} said: #{item[:text]} " }
105105

106+
op_statement = statements.shift.to_s
107+
split_1, split_2 =
108+
[op_statement[0, op_statement.size / 2], op_statement[(op_statement.size / 2)..-1]]
109+
110+
truncation_length = 500
111+
112+
op_statement = [
113+
tokenizer.truncate(split_1, truncation_length),
114+
tokenizer.truncate(split_2.reverse, truncation_length).reverse,
115+
].join(" ")
116+
106117
prompt = DiscourseAi::Completions::Prompt.new(<<~TEXT.strip)
107118
You are an advanced summarization bot. Analyze a given conversation and produce a concise,
108119
single-sentence summary that conveys the main topic and current developments to someone with no prior context.
@@ -127,7 +138,7 @@ def first_summary_prompt(contents)
127138
128139
The conversation began with the following statement:
129140
130-
#{statements.shift}\n
141+
#{op_statement}\n
131142
TEXT
132143

133144
if statements.present?

lib/summarization/strategies/topic_summary.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def targets_data
2727
end
2828
end
2929

30-
def summary_extension_prompt(summary, contents)
30+
def summary_extension_prompt(summary, contents, _tokenizer)
3131
resource_path = "#{Discourse.base_path}/t/-/#{target.id}"
3232
content_title = target.title
3333
input =
@@ -70,7 +70,7 @@ def summary_extension_prompt(summary, contents)
7070
prompt
7171
end
7272

73-
def first_summary_prompt(contents)
73+
def first_summary_prompt(contents, _tokenizer)
7474
resource_path = "#{Discourse.base_path}/t/-/#{target.id}"
7575
content_title = target.title
7676
input =

0 commit comments

Comments
 (0)