Skip to content

Commit 8cbef49

Browse files
Add ERI server assistant (#231)
1 parent cdf717a commit 8cbef49

File tree

76 files changed

+3581
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3581
-153
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Things we are currently working on:
1010
- [x] ~~App: Metadata for providers (which provider offers embeddings?) (PR [#205](https://github.com/MindWorkAI/AI-Studio/pull/205))~~
1111
- [x] ~~App: Add an option to show preview features (PR [#222](https://github.com/MindWorkAI/AI-Studio/pull/222))~~
1212
- [x] ~~App: Configure embedding providers (PR [#224](https://github.com/MindWorkAI/AI-Studio/pull/224))~~
13+
- [x] ~~App: Implement an [ERI](https://github.com/MindWorkAI/ERI) server coding assistant (PR [#231](https://github.com/MindWorkAI/AI-Studio/pull/231))~~
1314
- [ ] App: Management of data sources (local & external data via [ERI](https://github.com/MindWorkAI/ERI))
1415
- [ ] Runtime: Extract data from txt / md / pdf / docx / xlsx files
1516
- [ ] (*Optional*) Runtime: Implement internal embedding provider through [fastembed-rs](https://github.com/Anush008/fastembed-rs)

app/MindWork AI Studio.sln.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AI/@EntryIndexedValue">AI</s:String>
3+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EDI/@EntryIndexedValue">EDI</s:String>
4+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ERI/@EntryIndexedValue">ERI</s:String>
35
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LLM/@EntryIndexedValue">LLM</s:String>
46
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LM/@EntryIndexedValue">LM</s:String>
57
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSG/@EntryIndexedValue">MSG</s:String>

app/MindWork AI Studio/Assistants/Agenda/AssistantAgenda.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ the logistical challenges that come with an increasing number of participants.
106106
SystemPrompt = SystemPrompts.DEFAULT,
107107
};
108108

109-
protected override void ResetFrom()
109+
protected override void ResetForm()
110110
{
111111
this.inputContent = string.Empty;
112112
this.contentLines.Clear();

app/MindWork AI Studio/Assistants/AssistantBase.razor

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<InnerScrolling HeaderHeight="6em">
88
<ChildContent>
9-
<MudForm @ref="@(this.form)" @bind-IsValid="@(this.inputIsValid)" @bind-Errors="@(this.inputIssues)" Class="pr-2">
9+
<MudForm @ref="@(this.form)" @bind-IsValid="@(this.inputIsValid)" @bind-Errors="@(this.inputIssues)" FieldChanged="@this.TriggerFormChange" Class="pr-2">
1010
<MudText Typo="Typo.body1" Align="Align.Justify" Class="mb-6">
1111
@this.Description
1212
</MudText>
@@ -35,11 +35,22 @@
3535
<div id="@BEFORE_RESULT_DIV_ID" class="mt-3">
3636
</div>
3737

38-
@if (this.ShowResult && this.resultingContentBlock is not null)
38+
@if (this.ShowResult && !this.ShowEntireChatThread && this.resultingContentBlock is not null)
3939
{
4040
<ContentBlockComponent Role="@(this.resultingContentBlock.Role)" Type="@(this.resultingContentBlock.ContentType)" Time="@(this.resultingContentBlock.Time)" Content="@(this.resultingContentBlock.Content)"/>
4141
}
4242

43+
@if(this.ShowResult && this.ShowEntireChatThread && this.chatThread is not null)
44+
{
45+
foreach (var block in this.chatThread.Blocks.OrderBy(n => n.Time))
46+
{
47+
@if (!block.HideFromUser)
48+
{
49+
<ContentBlockComponent Role="@block.Role" Type="@block.ContentType" Time="@block.Time" Content="@block.Content"/>
50+
}
51+
}
52+
}
53+
4354
<div id="@AFTER_RESULT_DIV_ID" class="mt-3">
4455
</div>
4556
</ChildContent>

app/MindWork AI Studio/Assistants/AssistantBase.razor.cs

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
using Microsoft.AspNetCore.Components;
66

7+
using MudBlazor.Utilities;
8+
79
using RustService = AIStudio.Tools.RustService;
10+
using Timer = System.Timers.Timer;
811

912
namespace AIStudio.Assistants;
1013

@@ -55,7 +58,7 @@ public abstract partial class AssistantBase : ComponentBase, IMessageBusReceiver
5558
_ => string.Empty,
5659
};
5760

58-
protected abstract void ResetFrom();
61+
protected abstract void ResetForm();
5962

6063
protected abstract bool MightPreselectValues();
6164

@@ -68,6 +71,8 @@ public abstract partial class AssistantBase : ComponentBase, IMessageBusReceiver
6871
private protected virtual RenderFragment? Body => null;
6972

7073
protected virtual bool ShowResult => true;
74+
75+
protected virtual bool ShowEntireChatThread => false;
7176

7277
protected virtual bool AllowProfiles => true;
7378

@@ -91,8 +96,10 @@ public abstract partial class AssistantBase : ComponentBase, IMessageBusReceiver
9196
protected MudForm? form;
9297
protected bool inputIsValid;
9398
protected Profile currentProfile = Profile.NO_PROFILE;
94-
9599
protected ChatThread? chatThread;
100+
101+
private readonly Timer formChangeTimer = new(TimeSpan.FromSeconds(1.6));
102+
96103
private ContentBlock? resultingContentBlock;
97104
private string[] inputIssues = [];
98105
private bool isProcessing;
@@ -101,6 +108,13 @@ public abstract partial class AssistantBase : ComponentBase, IMessageBusReceiver
101108

102109
protected override async Task OnInitializedAsync()
103110
{
111+
this.formChangeTimer.AutoReset = false;
112+
this.formChangeTimer.Elapsed += async (_, _) =>
113+
{
114+
this.formChangeTimer.Stop();
115+
await this.OnFormChange();
116+
};
117+
104118
this.MightPreselectValues();
105119
this.providerSettings = this.SettingsManager.GetPreselectedProvider(this.Component);
106120
this.currentProfile = this.SettingsManager.GetPreselectedProfile(this.Component);
@@ -161,7 +175,35 @@ public Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEv
161175

162176
return null;
163177
}
178+
179+
private void TriggerFormChange(FormFieldChangedEventArgs _)
180+
{
181+
this.formChangeTimer.Stop();
182+
this.formChangeTimer.Start();
183+
}
164184

185+
/// <summary>
186+
/// This method is called after any form field has changed.
187+
/// </summary>
188+
/// <remarks>
189+
/// This method is called after a delay of 1.6 seconds. This is to prevent
190+
/// the method from being called too often. This method is called after
191+
/// the user has stopped typing or selecting options.
192+
/// </remarks>
193+
protected virtual Task OnFormChange() => Task.CompletedTask;
194+
195+
/// <summary>
196+
/// Add an issue to the UI.
197+
/// </summary>
198+
/// <param name="issue">The issue to add.</param>
199+
protected void AddInputIssue(string issue)
200+
{
201+
Array.Resize(ref this.inputIssues, this.inputIssues.Length + 1);
202+
this.inputIssues[^1] = issue;
203+
this.inputIsValid = false;
204+
this.StateHasChanged();
205+
}
206+
165207
protected void CreateChatThread()
166208
{
167209
this.chatThread = new()
@@ -221,7 +263,7 @@ protected DateTimeOffset AddUserRequest(string request, bool hideContentFromUser
221263
return time;
222264
}
223265

224-
protected async Task<string> AddAIResponseAsync(DateTimeOffset time)
266+
protected async Task<string> AddAIResponseAsync(DateTimeOffset time, bool hideContentFromUser = false)
225267
{
226268
var aiText = new ContentText
227269
{
@@ -236,6 +278,7 @@ protected async Task<string> AddAIResponseAsync(DateTimeOffset time)
236278
ContentType = ContentType.TEXT,
237279
Role = ChatRole.AI,
238280
Content = aiText,
281+
HideFromUser = hideContentFromUser,
239282
};
240283

241284
if (this.chatThread is not null)
@@ -313,7 +356,7 @@ private async Task InnerResetForm()
313356
await this.JsRuntime.ClearDiv(RESULT_DIV_ID);
314357
await this.JsRuntime.ClearDiv(AFTER_RESULT_DIV_ID);
315358

316-
this.ResetFrom();
359+
this.ResetForm();
317360
this.providerSettings = this.SettingsManager.GetPreselectedProvider(this.Component);
318361

319362
this.inputIsValid = false;
@@ -341,6 +384,7 @@ private async Task InnerResetForm()
341384
public void Dispose()
342385
{
343386
this.MessageBus.Unregister(this);
387+
this.formChangeTimer.Dispose();
344388
}
345389

346390
#endregion

app/MindWork AI Studio/Assistants/BiasDay/BiasOfTheDayAssistant.razor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Text;
22

3-
using AIStudio.Components;
3+
using AIStudio.Chat;
44
using AIStudio.Settings.DataModel;
55

66
namespace AIStudio.Assistants.BiasDay;
@@ -50,7 +50,7 @@ this bias.
5050

5151
protected override bool ShowReset => false;
5252

53-
protected override void ResetFrom()
53+
protected override void ResetForm()
5454
{
5555
if (!this.MightPreselectValues())
5656
{
@@ -124,7 +124,7 @@ private async Task TellBias()
124124
{
125125
var biasChat = new LoadChat
126126
{
127-
WorkspaceId = Workspaces.WORKSPACE_ID_BIAS,
127+
WorkspaceId = KnownWorkspaces.BIAS_WORKSPACE_ID,
128128
ChatId = this.SettingsManager.ConfigurationData.BiasOfTheDay.BiasOfTheDayChatId,
129129
};
130130

@@ -147,7 +147,7 @@ private async Task TellBias()
147147
BiasCatalog.ALL_BIAS[this.SettingsManager.ConfigurationData.BiasOfTheDay.BiasOfTheDayId] :
148148
BiasCatalog.GetRandomBias(this.SettingsManager.ConfigurationData.BiasOfTheDay.UsedBias);
149149

150-
var chatId = this.CreateChatThread(Workspaces.WORKSPACE_ID_BIAS, this.biasOfTheDay.Name);
150+
var chatId = this.CreateChatThread(KnownWorkspaces.BIAS_WORKSPACE_ID, this.biasOfTheDay.Name);
151151
this.SettingsManager.ConfigurationData.BiasOfTheDay.BiasOfTheDayId = this.biasOfTheDay.Id;
152152
this.SettingsManager.ConfigurationData.BiasOfTheDay.BiasOfTheDayChatId = chatId;
153153
this.SettingsManager.ConfigurationData.BiasOfTheDay.DateLastBiasDrawn = DateOnly.FromDateTime(DateTime.Now);

app/MindWork AI Studio/Assistants/Coding/AssistantCoding.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ messages. You can also help with code refactoring and optimization.
3232

3333
protected override Func<Task> SubmitAction => this.GetSupport;
3434

35-
protected override void ResetFrom()
35+
protected override void ResetForm()
3636
{
3737
this.codingContexts.Clear();
3838
this.compilerMessages = string.Empty;

app/MindWork AI Studio/Assistants/Coding/CodingContextItem.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<MudTextField T="string" @bind-Text="@this.CodingContext.Id" AdornmentIcon="@Icons.Material.Filled.Numbers" Adornment="Adornment.Start" Label="(Optional) Identifier" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES" Class="mb-3"/>
2-
<MudStack Row="@true" AlignItems="AlignItems.Center" Class="mb-3">
2+
<MudStack Row="@true" Class="mb-3">
33
<MudSelect T="CommonCodingLanguages" @bind-Value="@this.CodingContext.Language" AdornmentIcon="@Icons.Material.Filled.Code" Adornment="Adornment.Start" Label="Language" Variant="Variant.Outlined" Margin="Margin.Dense">
44
@foreach (var language in Enum.GetValues<CommonCodingLanguages>())
55
{

app/MindWork AI Studio/Assistants/EMail/AssistantEMail.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public partial class AssistantEMail : AssistantBaseCore
3333
SystemPrompt = SystemPrompts.DEFAULT,
3434
};
3535

36-
protected override void ResetFrom()
36+
protected override void ResetForm()
3737
{
3838
this.inputBulletPoints = string.Empty;
3939
this.bulletPointsLines.Clear();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace AIStudio.Assistants.ERI;
2+
3+
public enum AllowedLLMProviders
4+
{
5+
NONE,
6+
7+
ANY,
8+
SELF_HOSTED,
9+
}

0 commit comments

Comments
 (0)