From 6d0493cbc78a3399291a1fe7add40e97f7c21a1b Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sat, 20 Sep 2025 03:07:27 +0000
Subject: [PATCH 1/3] Initial plan
From 7044e74b660c4477359aeaa87541702e11493672 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sat, 20 Sep 2025 03:11:51 +0000
Subject: [PATCH 2/3] Implement retry button functionality to replace delete
chat button
Co-authored-by: SamHou0 <61927273+SamHou0@users.noreply.github.com>
---
AI.NET/Resources/Strings/Strings.resx | 4 +--
AI.NET/Service/AI.cs | 48 +++++++++++++++++++++++++--
AI.NET/Windows/MainWindow.xaml | 4 +--
AI.NET/Windows/MainWindow.xaml.cs | 27 ++++++++++-----
4 files changed, 68 insertions(+), 15 deletions(-)
diff --git a/AI.NET/Resources/Strings/Strings.resx b/AI.NET/Resources/Strings/Strings.resx
index 307f96a..e11d51b 100644
--- a/AI.NET/Resources/Strings/Strings.resx
+++ b/AI.NET/Resources/Strings/Strings.resx
@@ -120,8 +120,8 @@
About
-
- Delete Current Chat (Ctrl+D)
+
+ Retry Last AI Response (Ctrl+R)
Mem0 Server URL
diff --git a/AI.NET/Service/AI.cs b/AI.NET/Service/AI.cs
index 6a79882..644b31b 100644
--- a/AI.NET/Service/AI.cs
+++ b/AI.NET/Service/AI.cs
@@ -40,11 +40,53 @@ public static async Task RequestAIAsync(string message, MarkdownScrollViewer out
TopicsHelper.SaveTopicsAsync(Topics);
}
///
- /// Delete a chat session
+ /// Retry generating the last AI response
///
- public static void DeleteMessages()
+ /// The UI element to update
+ public static async Task RetryLastResponseAsync(MarkdownScrollViewer outputBox)
{
- Topics.RemoveAt(Topics.CurrentTopicIndex);
+ var messages = Topics.CurrentTopic.MessageList;
+
+ // Find the last user message and remove any subsequent AI/system messages
+ int lastUserIndex = -1;
+ for (int i = messages.Count - 1; i >= 0; i--)
+ {
+ if (messages[i].Role == ChatMessageRole.User)
+ {
+ lastUserIndex = i;
+ break;
+ }
+ }
+
+ if (lastUserIndex == -1)
+ {
+ return; // No user message found to retry
+ }
+
+ // Remove all messages after the last user message
+ while (messages.Count > lastUserIndex + 1)
+ {
+ messages.RemoveAt(messages.Count - 1);
+ }
+
+ string lastUserMessage = messages[lastUserIndex].Content;
+
+ // Update the output box to show we're retrying
+ string currentMarkdown = await Topics.CurrentTopic.GetMarkdownAsync();
+ outputBox.Markdown = currentMarkdown + "AI:";
+
+ // Handle memory if enabled
+ if (Mem0.IsEnabled)
+ await HandleMemoryAsync(lastUserMessage);
+
+ // Generate new AI response
+ Topics.CurrentTopic.Add(new Chat()
+ {
+ Content = await OpenAI.GenerateReplyAsync(outputBox),
+ Role = ChatMessageRole.Assistant
+ });
+
+ // Save topics to file
TopicsHelper.SaveTopicsAsync(Topics);
}
public static void NewChat(Data.SystemPrompt prompt)
diff --git a/AI.NET/Windows/MainWindow.xaml b/AI.NET/Windows/MainWindow.xaml
index 75823f5..c1460dc 100644
--- a/AI.NET/Windows/MainWindow.xaml
+++ b/AI.NET/Windows/MainWindow.xaml
@@ -64,8 +64,8 @@
-