Skip to content

Commit aada445

Browse files
committed
Summarizer attempt 2
1 parent b9de4e0 commit aada445

File tree

2 files changed

+63
-51
lines changed

2 files changed

+63
-51
lines changed

src/Return.Web/Components/RetrospectiveSummarizer.razor

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -68,36 +68,41 @@ else
6868
ResponseFormat = ChatResponseFormat.Text,
6969
};
7070

71-
string laneNames = String.Join("/", this.Data.Items.Select(x => x.Lane.Name).Distinct());
72-
List<ChatMessage> chatMessages =
73-
[
74-
new(
75-
ChatRole.System,
76-
$@"A retrospective has been performed. Summarize the following messages, prefixed with categories '{laneNames}', in a maximum of 60 words per category. Spend more words on highly voted notes and less on lower voted notes.
77-
Don't call out individual notes, just summarize the general sentiment. Limit making up additional context or words, keep it to the given messages. Use markdown syntax for headings, subheadings and lists.
78-
"
79-
)
80-
];
71+
string rawSummary = String.Empty;
8172

82-
Logger.LogInformation("Compose system message: {Msg}", chatMessages[0].Text);
83-
8473
var byLane =
85-
from item in this.Data.Items
74+
(from item in this.Data.Items
8675
group item by item.Lane.Name into g
87-
select new { Lane = g.Key, Notes = g.OrderByDescending(x => x.Votes.Count) };
76+
select new { Lane = g.Key, Notes = g.OrderByDescending(x => x.Votes.Count).ToList() }).ToList();
77+
78+
Logger.LogDebug("Summarizing {Count} lanes", byLane.Count);
8879

8980
StringBuilder msgBuilder = new();
9081
foreach (var group in byLane)
9182
{
83+
if (group.Notes.Count is 0) continue;
84+
85+
List<ChatMessage> chatMessages =
86+
[
87+
new(
88+
ChatRole.System,
89+
$@"A retrospective has been performed. Summarize the following '{group.Lane}' lane notes, in a maximum of 60 words.
90+
Don't call out individual notes, just summarize the general sentiment of the most highly voted notes in a concise summary. Do not mention the amount of votes.
91+
Limit making up additional context or words, keep it to the given messages. If items are grouped together, then summarize the group.
92+
Use markdown syntax for lists. Use no headings.
93+
"
94+
)
95+
];
96+
97+
rawSummary += $"## Lane \"{group.Lane}\"{Environment.NewLine}";
98+
9299
foreach (var item in group.Notes)
93100
{
94101
msgBuilder.Clear();
95102

96-
msgBuilder.Append($"Category \"{item.Lane.Name}\" ");
97-
98103
if (item is { NoteGroup: { } ng })
99104
{
100-
msgBuilder.AppendLine($" - multiple items grouped \"{item.NoteGroup.Title}\" (voted {item.Votes.Count} times): ");
105+
msgBuilder.AppendLine($"Multiple items grouped \"{item.NoteGroup.Title}\" (voted {item.Votes.Count} times): ");
101106
foreach (RetrospectiveNote note in ng.Notes)
102107
{
103108
msgBuilder.Append($"- {note.Text}");
@@ -106,54 +111,60 @@ Don't call out individual notes, just summarize the general sentiment. Limit mak
106111

107112
if (item is { Note: { } n })
108113
{
109-
msgBuilder.AppendLine($"- voted {item.Votes.Count} times: ");
114+
msgBuilder.AppendLine($"Voted {item.Votes.Count} times: ");
110115
msgBuilder.AppendLine(n.Text);
111116
}
117+
118+
Logger.LogInformation("Compose system message: {Msg}", chatMessages[0].Text);
112119

113120
chatMessages.Add(
114121
new(
115122
ChatRole.User,
116123
msgBuilder.ToString()
117124
)
118125
);
119-
126+
120127
Logger.LogDebug("Composed sub-chatmessage: {Msg}", msgBuilder.ToString());
121128
}
122-
}
123-
124-
long startTime = Stopwatch.GetTimestamp();
125-
126-
Logger.LogDebug("Invoking AI with {Count} messages", chatMessages.Count);
127-
try
128-
{
129-
Summary = null;
130-
131-
Markdown markdown = new();
132-
string rawSummary = String.Empty;
133129

134-
await foreach (StreamingChatCompletionUpdate subText in this.ChatClient.CompleteStreamingAsync(chatMessages, chatOptions))
130+
long startTime = Stopwatch.GetTimestamp();
131+
132+
Logger.LogDebug("Invoking AI with {Count} messages", chatMessages.Count);
133+
try
135134
{
136-
//Logger.LogTrace("Streamed sub text: {@Update}", subText.Text);
137-
138-
if (subText is { Text: { } text })
135+
Summary = null;
136+
137+
Markdown markdown = new();
138+
139+
await foreach (StreamingChatCompletionUpdate subText in this.ChatClient.CompleteStreamingAsync(chatMessages, chatOptions))
139140
{
140-
rawSummary += text;
141-
this.Summary = markdown.Transform(rawSummary);
141+
//Logger.LogTrace("Streamed sub text: {@Update}", subText.Text);
142+
143+
if (subText is { Text: { } text })
144+
{
145+
rawSummary += text;
146+
this.Summary = markdown.Transform(rawSummary);
142147

143-
StateHasChanged();
148+
StateHasChanged();
149+
}
144150
}
145-
}
146151

147-
this.Summary = markdown.Transform(rawSummary);
148-
Logger.LogTrace("Total generated summary: {RawSummary}", rawSummary);
149-
}
150-
catch (Exception ex)
151-
{
152-
Logger.LogError(ex, "Error invoking AI");
153-
Summary = ex.ToString();
154-
}
152+
this.Summary = markdown.Transform(rawSummary);
153+
Logger.LogTrace("Total generated summary: {RawSummary}", rawSummary);
154+
}
155+
catch (Exception ex)
156+
{
157+
Logger.LogError(ex, "Error invoking AI");
158+
Summary = ex.ToString();
159+
}
155160

156-
Logger.LogDebug("Completed AI invocation in {Elapsed}", Stopwatch.GetElapsedTime(startTime));
161+
Logger.LogDebug("Completed AI invocation in {Elapsed}", Stopwatch.GetElapsedTime(startTime));
162+
163+
rawSummary += Environment.NewLine;
164+
rawSummary += Environment.NewLine;
165+
}
166+
167+
157168
IsLoadingSummary = false;
158169
}
159170

src/Return.Web/_scss/_summarizer.scss

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
}
1212

1313
h1 {
14-
font-size: 140%;
14+
font-size: 120%;
1515
}
1616

1717
h2 {
18-
font-size: 130%;
18+
font-size: 110%;
19+
font-weight: 250;
1920
}
2021

2122
h3 {
22-
font-size: 120%;
23+
font-size: 105%;
2324
}
2425

2526
h4 {
26-
font-size: 110%;
27+
font-size: 100%;
2728
}
2829
}

0 commit comments

Comments
 (0)