Skip to content

Commit 8671768

Browse files
committed
Summarize group titles
1 parent aada445 commit 8671768

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

src/Return.Web/Components/NoteGroup.razor

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
placeholder="Group name"
2121
@bind="@this.DataTitle" />
2222
</div>
23+
<div class="control">
24+
<button class="button is-link is-outlined" @onclick="@AutoSummarizeNoteGroupTitle">
25+
<i class="fa-solid fa-quote-left"></i>
26+
</button>
27+
</div>
2328
<div class="control">
2429
<button class="button is-danger is-outlined" @onclick="@DeleteNoteGroup">
2530
<i class="fas fa-trash is-danger"></i>

src/Return.Web/Components/NoteGroupBase.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
// ******************************************************************************
22
// © 2019 Sebastiaan Dammann | damsteen.nl
3-
//
3+
//
44
// File: : NoteGroupBase.cs
55
// Project : Return.Web
66
// ******************************************************************************
77

88
namespace Return.Web.Components;
99

1010
using System;
11+
using System.Collections.Generic;
1112
using System.ComponentModel;
13+
using System.Diagnostics;
1214
using System.Diagnostics.CodeAnalysis;
1315
using System.Threading.Tasks;
1416
using Application.Common.Models;
1517
using Application.NoteGroups.Commands;
1618
using Domain.ValueObjects;
1719
using Microsoft.AspNetCore.Components;
20+
using Microsoft.Extensions.AI;
1821
using Microsoft.Extensions.Logging;
1922

2023
#nullable disable
@@ -27,6 +30,9 @@ public class NoteGroupBase : MediatorComponent {
2730
[Inject]
2831
public ILogger<NoteGroup> Logger { get; set; }
2932

33+
[Inject]
34+
public IChatClient ChatClient { get; set; }
35+
3036
[Parameter]
3137
public RetrospectiveNoteGroup Data { get; set; } = new RetrospectiveNoteGroup();
3238

@@ -67,6 +73,47 @@ protected async Task UpdateTitle() {
6773
}
6874
}
6975

76+
protected async Task AutoSummarizeNoteGroupTitle()
77+
{
78+
ChatOptions chatOptions = new()
79+
{
80+
Temperature = 0.2f,
81+
ResponseFormat = ChatResponseFormat.Text,
82+
};
83+
84+
List<ChatMessage> chatMessages =
85+
[
86+
new(
87+
ChatRole.System,
88+
$@"A retrospective has been performed. Summarize the sentiment following notes grouped in the '{this.Container.Lane.Name}' lane. Use a maximum of 5 words. Don't prefix anything.
89+
Only write a 5 word summary of the notes group. Do not use punctuations. Do not mention 'Notes' - only give a short 5 word title for these notes."
90+
)
91+
];
92+
93+
foreach (RetrospectiveNote note in this.Data.Notes)
94+
{
95+
chatMessages.Add(new(ChatRole.User, $"Note: {note.Text}"));
96+
}
97+
98+
long startTime = Stopwatch.GetTimestamp();
99+
100+
Logger.LogDebug("Invoking AI with {Count} messages", chatMessages.Count);
101+
try
102+
{
103+
ChatCompletion response = await this.ChatClient.CompleteAsync(chatMessages, chatOptions);
104+
this.Data.Title = response.ToString();
105+
Logger.LogTrace("Total generated summary: {RawSummary}", this.Data.Title);
106+
}
107+
catch (Exception ex)
108+
{
109+
Logger.LogError(ex, "Error invoking AI");
110+
}
111+
112+
Logger.LogDebug("Completed AI invocation in {Elapsed}", Stopwatch.GetElapsedTime(startTime));
113+
114+
await this.UpdateTitle();
115+
}
116+
70117
protected async Task DeleteNoteGroup() {
71118
try {
72119
await this.Mediator.Send(new DeleteNoteGroupCommand(this.RetroId.StringId, this.Data.Id));

src/Return.Web/Components/NoteLaneBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ******************************************************************************
22
// © 2019 Sebastiaan Dammann | damsteen.nl
3-
//
3+
//
44
// File: : NoteLaneBase.cs
55
// Project : Return.Web
66
// ******************************************************************************
@@ -25,6 +25,7 @@ namespace Return.Web.Components;
2525
using Application.Retrospectives.Queries.GetRetrospectiveStatus;
2626
using Domain.ValueObjects;
2727
using Microsoft.AspNetCore.Components;
28+
using Microsoft.Extensions.AI;
2829
using Microsoft.Extensions.Logging;
2930
using Services;
3031

@@ -45,6 +46,9 @@ public abstract class NoteLaneBase : MediatorComponent, IDisposable, INoteAddedS
4546
[Inject]
4647
public INotificationSubscription<INoteDeletedSubscriber> NoteDeletedSubscription { get; set; }
4748

49+
[Inject]
50+
public IChatClient ChatClient { get; set; }
51+
4852
[Inject]
4953
public ILogger<NoteLane> Logger { get; set; }
5054

@@ -301,6 +305,8 @@ public Task OnNoteDeleted(NoteDeletedNotification notification) {
301305
return Task.CompletedTask;
302306
}
303307

308+
309+
304310
protected override void OnAfterRender(bool firstRender) {
305311
// Reset last added note - this prevents refocus if someone else adds a new note in a different lane even
306312
this.LastAddedNote = null;

0 commit comments

Comments
 (0)