Skip to content

Commit 4b9435d

Browse files
committed
Failed attempt to split note tool
1 parent 7a06c43 commit 4b9435d

File tree

1 file changed

+55
-24
lines changed

1 file changed

+55
-24
lines changed

src/Return.Web/Components/NoteLaneBase.cs

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,29 @@ protected async Task AutoGroupNotes()
276276
this.MakeNoteGroup,
277277
new AIFunctionFactoryCreateOptions
278278
{
279-
Name = "Create note group",
280-
Description = "Makes a group with a specified title and IDs of the relevant notes.",
279+
Name = "Create group",
281280
Parameters = [
282281
new("title") { Description = "The name of the group to create", IsRequired = true, ParameterType = typeof(string)},
283-
new("noteIds") { Description = "An array of note IDs of the notes to put into this group", IsRequired = true, ParameterType = typeof(int[])},
282+
]
283+
}
284+
),
285+
AIFunctionFactory.Create(
286+
this.AddNoteToGroup,
287+
new AIFunctionFactoryCreateOptions
288+
{
289+
Name = "Assign note to group",
290+
Parameters = [
291+
new("noteGroup") { Description = "Title of the group created with the \"Create note group\" tool", IsRequired = true, ParameterType = typeof(int)},
292+
new("noteId") { Description = "Integer ID of the note to move to the group", IsRequired = true, ParameterType = typeof(int)},
284293
],
285-
ReturnParameter = null
286-
294+
ReturnParameter = new() {
295+
Description = "Returns if the move was successful",
296+
ParameterType = typeof(string)
297+
}
287298
}
288-
)
299+
),
289300
],
290-
ToolMode = ChatToolMode.RequireSpecific("Create note group"),
301+
ToolMode = ChatToolMode.RequireAny,
291302
TopP = 0.9f,
292303
Temperature = 0.2f,
293304
TopK = 10
@@ -303,7 +314,10 @@ protected async Task AutoGroupNotes()
303314
- Ignore any note that does not fit into a group.
304315
- Do not include the same note in more than one group.
305316
- Assign each group a concise title (maximum of 5 words) summarizing its content.
306-
- Use the ""Create note group"" tool to make the groups.
317+
318+
Workflow:
319+
1. Create group with a title
320+
2. For each note belonging to the group: invoke the ""add note to group"" tool
307321
308322
What now follows is a list of notes to divide into groups. Do not response with a summary, invoke the tool.
309323
Each note is starts with [NOTE ID]. Each note ends with [END NOTE].
@@ -352,39 +366,56 @@ [NOTE 123] Some text here [END NOTE]"
352366
}
353367

354368

355-
private async Task MakeNoteGroup(string title, int[] noteIds)
369+
private async Task MakeNoteGroup(string title)
356370
{
357371
try
358372
{
359-
Logger.LogInformation("AI tool callback: Make note group with title {Title} and ids {@NoteIds}",
360-
title,
361-
noteIds);
362-
363-
IEnumerable<string> notes = this.Contents.Notes.Where(x => noteIds.Contains(x.Id)).Select(x => x.Text);
364-
foreach (string note in notes) {
365-
Logger.LogDebug("Note selected for group {Title}: {NoteText}", title, note);
366-
}
373+
Logger.LogInformation("AI tool callback: Make note group with title {Title}", title);
367374

368375
RetrospectiveNoteGroup result = await this.Mediator.Send(new AddNoteGroupCommand(this.RetroId.StringId, this.Lane.Id));
369-
result.Title = title;
370376

371377
this.Contents.Groups.Add(result);
372378
await this.Mediator.Send(new UpdateNoteGroupCommand(this.RetroId.StringId, result.Id, title));
373379

374-
foreach (int noteId in noteIds)
375-
{
376-
if (this.ExecuteNoteMove(noteId, result.Id))
377-
{
378-
await this.Mediator.Send(new MoveNoteCommand(noteId, result.Id));
379-
}
380+
result = this.Contents.Groups.FirstOrDefault(x => x.Id == result.Id) ?? result;
381+
result.Title = title;
382+
}
383+
catch (Exception ex)
384+
{
385+
Logger.LogError(ex, "Error processing AI invocation");
386+
throw;
387+
}
388+
}
389+
390+
private async Task<string> AddNoteToGroup(string noteGroup, int noteId)
391+
{
392+
try
393+
{
394+
Logger.LogInformation("AI tool callback: Move note {NoteId} to group {GroupTitle}",
395+
noteId,
396+
noteGroup);
397+
398+
RetrospectiveNoteGroup noteGroupInstance = this.Contents.Groups.FirstOrDefault(x => String.Equals(noteGroup.Trim(), x.Title.Trim(), StringComparison.OrdinalIgnoreCase));
399+
if (noteGroupInstance is null) return $"Note group \"{noteGroup}\" does not exist";
400+
401+
IEnumerable<string> notes = this.Contents.Notes.Where(x => x.Id == noteId).Select(x => x.Text);
402+
foreach (string note in notes) {
403+
Logger.LogDebug("Note selected for group {Title}: {NoteText}", noteGroupInstance.Title, note);
380404
}
381405

406+
if (this.ExecuteNoteMove(noteId, noteGroupInstance.Id))
407+
{
408+
await this.Mediator.Send(new MoveNoteCommand(noteId, noteGroupInstance.Id));
409+
return "Success";
410+
}
382411
}
383412
catch (Exception ex)
384413
{
385414
Logger.LogError(ex, "Error processing AI invocation");
386415
throw;
387416
}
417+
418+
return "Invalid move";
388419
}
389420

390421
public Task OnNoteAdded(NoteAddedNotification notification) {

0 commit comments

Comments
 (0)