Implemented send to chat feature

This commit is contained in:
Thorsten Sommer 2024-08-18 15:55:12 +02:00
parent f24143c1ae
commit 5e4768584b
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
12 changed files with 76 additions and 8 deletions

View File

@ -45,6 +45,8 @@ public abstract partial class AssistantBase : ComponentBase
protected virtual bool ShowDedicatedProgress => false; protected virtual bool ShowDedicatedProgress => false;
protected virtual ChatThread ConvertToChatThread => this.chatThread ?? new();
protected virtual IReadOnlyList<IButtonData> FooterButtons => []; protected virtual IReadOnlyList<IButtonData> FooterButtons => [];
protected static readonly Dictionary<string, object?> USER_INPUT_ATTRIBUTES = new(); protected static readonly Dictionary<string, object?> USER_INPUT_ATTRIBUTES = new();
@ -53,7 +55,7 @@ public abstract partial class AssistantBase : ComponentBase
protected MudForm? form; protected MudForm? form;
protected bool inputIsValid; protected bool inputIsValid;
private ChatThread? chatThread; protected ChatThread? chatThread;
private ContentBlock? resultingContentBlock; private ContentBlock? resultingContentBlock;
private string[] inputIssues = []; private string[] inputIssues = [];
private bool isProcessing; private bool isProcessing;
@ -164,7 +166,7 @@ public abstract partial class AssistantBase : ComponentBase
return icon; return icon;
} }
private Task SendToAssistant(SendTo assistant, SendToButton sendToButton) private Task SendToAssistant(SendTo destination, SendToButton sendToButton)
{ {
var contentToSend = sendToButton.UseResultingContentBlockData switch var contentToSend = sendToButton.UseResultingContentBlockData switch
{ {
@ -176,7 +178,7 @@ public abstract partial class AssistantBase : ComponentBase
}, },
}; };
var (eventItem, path) = assistant switch var (eventItem, path) = destination switch
{ {
SendTo.AGENDA_ASSISTANT => (Event.SEND_TO_AGENDA_ASSISTANT, Path.ASSISTANT_AGENDA), SendTo.AGENDA_ASSISTANT => (Event.SEND_TO_AGENDA_ASSISTANT, Path.ASSISTANT_AGENDA),
SendTo.CODING_ASSISTANT => (Event.SEND_TO_CODING_ASSISTANT, Path.ASSISTANT_CODING), SendTo.CODING_ASSISTANT => (Event.SEND_TO_CODING_ASSISTANT, Path.ASSISTANT_CODING),
@ -186,10 +188,22 @@ public abstract partial class AssistantBase : ComponentBase
SendTo.GRAMMAR_SPELLING_ASSISTANT => (Event.SEND_TO_GRAMMAR_SPELLING_ASSISTANT, Path.ASSISTANT_GRAMMAR_SPELLING), SendTo.GRAMMAR_SPELLING_ASSISTANT => (Event.SEND_TO_GRAMMAR_SPELLING_ASSISTANT, Path.ASSISTANT_GRAMMAR_SPELLING),
SendTo.TEXT_SUMMARIZER_ASSISTANT => (Event.SEND_TO_TEXT_SUMMARIZER_ASSISTANT, Path.ASSISTANT_SUMMARIZER), SendTo.TEXT_SUMMARIZER_ASSISTANT => (Event.SEND_TO_TEXT_SUMMARIZER_ASSISTANT, Path.ASSISTANT_SUMMARIZER),
SendTo.CHAT => (Event.SEND_TO_CHAT, Path.CHAT),
_ => (Event.NONE, Path.ASSISTANTS), _ => (Event.NONE, Path.ASSISTANTS),
}; };
switch (destination)
{
case SendTo.CHAT:
MessageBus.INSTANCE.DeferMessage(this, eventItem, this.ConvertToChatThread);
break;
default:
MessageBus.INSTANCE.DeferMessage(this, eventItem, contentToSend); MessageBus.INSTANCE.DeferMessage(this, eventItem, contentToSend);
break;
}
this.NavigationManager.NavigateTo(path); this.NavigationManager.NavigateTo(path);
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -1,5 +1,6 @@
using System.Text; using System.Text;
using AIStudio.Chat;
using AIStudio.Tools; using AIStudio.Tools;
namespace AIStudio.Components.Pages.Agenda; namespace AIStudio.Components.Pages.Agenda;
@ -101,6 +102,11 @@ public partial class AssistantAgenda : AssistantBaseCore
}, },
]; ];
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
{
SystemPrompt = SystemPrompts.DEFAULT,
};
private string inputTopic = string.Empty; private string inputTopic = string.Empty;
private string inputName = string.Empty; private string inputName = string.Empty;
private string inputContent = string.Empty; private string inputContent = string.Empty;

View File

@ -62,6 +62,24 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Chat.PreselectedProvider); this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Chat.PreselectedProvider);
} }
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<ChatThread>(Event.SEND_TO_CHAT).FirstOrDefault();
if (deferredContent is not null)
{
this.chatThread = deferredContent;
if (this.chatThread is not null)
{
var firstUserBlock = this.chatThread.Blocks.FirstOrDefault(x => x.Role == ChatRole.USER);
if (firstUserBlock is not null)
{
this.chatThread.Name = firstUserBlock.Content switch
{
ContentText textBlock => this.ExtractThreadName(textBlock.Text),
_ => "Thread"
};
}
}
}
await base.OnInitializedAsync(); await base.OnInitializedAsync();
} }

View File

@ -1,3 +1,4 @@
using AIStudio.Chat;
using AIStudio.Tools; using AIStudio.Tools;
namespace AIStudio.Components.Pages.GrammarSpelling; namespace AIStudio.Components.Pages.GrammarSpelling;
@ -36,6 +37,11 @@ public partial class AssistantGrammarSpelling : AssistantBaseCore
}, },
]; ];
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
{
SystemPrompt = SystemPrompts.DEFAULT,
};
#region Overrides of ComponentBase #region Overrides of ComponentBase
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()

View File

@ -1,3 +1,4 @@
using AIStudio.Chat;
using AIStudio.Tools; using AIStudio.Tools;
namespace AIStudio.Components.Pages.RewriteImprove; namespace AIStudio.Components.Pages.RewriteImprove;
@ -37,6 +38,11 @@ public partial class AssistantRewriteImprove : AssistantBaseCore
}, },
]; ];
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
{
SystemPrompt = SystemPrompts.DEFAULT,
};
#region Overrides of ComponentBase #region Overrides of ComponentBase
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()

View File

@ -11,4 +11,6 @@ public enum SendTo
AGENDA_ASSISTANT, AGENDA_ASSISTANT,
CODING_ASSISTANT, CODING_ASSISTANT,
TEXT_SUMMARIZER_ASSISTANT, TEXT_SUMMARIZER_ASSISTANT,
CHAT,
} }

View File

@ -14,6 +14,8 @@ public static class SendToExtensions
SendTo.AGENDA_ASSISTANT => "Agenda Assistant", SendTo.AGENDA_ASSISTANT => "Agenda Assistant",
SendTo.CODING_ASSISTANT => "Coding Assistant", SendTo.CODING_ASSISTANT => "Coding Assistant",
SendTo.CHAT => "New Chat",
_ => "Send to ...", _ => "Send to ...",
}; };
} }

View File

@ -1,3 +1,4 @@
using AIStudio.Chat;
using AIStudio.Tools; using AIStudio.Tools;
namespace AIStudio.Components.Pages.TextSummarizer; namespace AIStudio.Components.Pages.TextSummarizer;
@ -31,6 +32,11 @@ public partial class AssistantTextSummarizer : AssistantBaseCore
}, },
]; ];
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
{
SystemPrompt = SystemPrompts.DEFAULT,
};
private string inputText = string.Empty; private string inputText = string.Empty;
private bool isAgentRunning; private bool isAgentRunning;
private CommonLanguages selectedTargetLanguage; private CommonLanguages selectedTargetLanguage;

View File

@ -1,3 +1,4 @@
using AIStudio.Chat;
using AIStudio.Tools; using AIStudio.Tools;
namespace AIStudio.Components.Pages.Translation; namespace AIStudio.Components.Pages.Translation;
@ -27,6 +28,11 @@ public partial class AssistantTranslation : AssistantBaseCore
}, },
]; ];
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
{
SystemPrompt = SystemPrompts.DEFAULT,
};
private bool liveTranslation; private bool liveTranslation;
private bool isAgentRunning; private bool isAgentRunning;
private string inputText = string.Empty; private string inputText = string.Empty;

View File

@ -16,7 +16,7 @@ public enum Event
HAS_CHAT_UNSAVED_CHANGES, HAS_CHAT_UNSAVED_CHANGES,
RESET_CHAT_STATE, RESET_CHAT_STATE,
// Send assistant events: // Send events:
SEND_TO_GRAMMAR_SPELLING_ASSISTANT, SEND_TO_GRAMMAR_SPELLING_ASSISTANT,
SEND_TO_ICON_FINDER_ASSISTANT, SEND_TO_ICON_FINDER_ASSISTANT,
SEND_TO_REWRITE_ASSISTANT, SEND_TO_REWRITE_ASSISTANT,
@ -24,4 +24,5 @@ public enum Event
SEND_TO_AGENDA_ASSISTANT, SEND_TO_AGENDA_ASSISTANT,
SEND_TO_CODING_ASSISTANT, SEND_TO_CODING_ASSISTANT,
SEND_TO_TEXT_SUMMARIZER_ASSISTANT, SEND_TO_TEXT_SUMMARIZER_ASSISTANT,
SEND_TO_CHAT,
} }

View File

@ -178,6 +178,6 @@
"contentHash": "FHNOatmUq0sqJOkTx+UF/9YK1f180cnW5FVqnQMvYUN0elp6wFzbtPSiqbo1/ru8ICp43JM1i7kKkk6GsNGHlA==" "contentHash": "FHNOatmUq0sqJOkTx+UF/9YK1f180cnW5FVqnQMvYUN0elp6wFzbtPSiqbo1/ru8ICp43JM1i7kKkk6GsNGHlA=="
} }
}, },
"net8.0/osx-x64": {} "net8.0/osx-arm64": {}
} }
} }

View File

@ -1,2 +1,3 @@
# v0.8.10, build 172 # v0.8.10, build 172
- Added the possibility to send any assistant context to a new chat session for further questions
- Improved the coding assistant's language handling when creating the corresponding prompt - Improved the coding assistant's language handling when creating the corresponding prompt