From c92ce49af2d647a9bcb42407dab2e0565e1cce61 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 16 Jul 2024 20:01:43 +0200 Subject: [PATCH] Finished coding assistant --- .../Pages/Coding/AssistantCoding.razor | 39 ++++++++- .../Pages/Coding/AssistantCoding.razor.cs | 84 ++++++++++++++++++- .../Components/Pages/Coding/CodingContext.cs | 15 +++- .../Pages/Coding/CodingContextItem.razor | 15 +++- .../Pages/Coding/CodingContextItem.razor.cs | 24 +++++- .../Coding/CommonCodingLanguageExtensions.cs | 1 + .../Pages/Coding/CommonCodingLanguages.cs | 1 + 7 files changed, 173 insertions(+), 6 deletions(-) diff --git a/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor b/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor index f260e65a..b2865820 100644 --- a/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor +++ b/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor @@ -1,4 +1,39 @@ @page "/assistant/coding" @using AIStudio.Settings -@using AIStudio.Tools -@inherits AssistantBaseCore \ No newline at end of file +@inherits AssistantBaseCore + + + @for (var contextIndex = 0; contextIndex < this.codingContexts.Count; contextIndex++) + { + var codingContext = this.codingContexts[contextIndex]; + + + + } + + + Add context + + + + + @(this.provideCompilerMessages ? "Provide compiler messages" : "Provide no compiler messages") + + @if (this.provideCompilerMessages) + { + + } + + + + + + @foreach (var provider in this.SettingsManager.ConfigurationData.Providers) + { + + } + + + + Get support + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor.cs b/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor.cs index b62e2c27..5c0a2be2 100644 --- a/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor.cs @@ -1,4 +1,6 @@ -namespace AIStudio.Components.Pages.Coding; +using System.Text; + +namespace AIStudio.Components.Pages.Coding; public partial class AssistantCoding : AssistantBaseCore { @@ -18,7 +20,87 @@ public partial class AssistantCoding : AssistantBaseCore You know object-oriented programming, as well as functional programming and procedural programming. You are also familiar with design patterns and can explain them. You are an expert of debugging and can help with compiler messages. You can also help with code refactoring and optimization. + + When the user asks in a different language than English, you answer in the same language! """; private readonly List codingContexts = new(); + private bool provideCompilerMessages; + private string compilerMessages = string.Empty; + private string questions = string.Empty; + + private string? ValidatingCompilerMessages(string checkCompilerMessages) + { + if(!this.provideCompilerMessages) + return null; + + if(string.IsNullOrWhiteSpace(checkCompilerMessages)) + return "Please provide the compiler messages."; + + return null; + } + + private string? ValidateQuestions(string checkQuestions) + { + if(string.IsNullOrWhiteSpace(checkQuestions)) + return "Please provide your questions."; + + return null; + } + + private void AddCodingContext() + { + this.codingContexts.Add(new() + { + Id = $"Context {this.codingContexts.Count + 1}", + }); + } + + private async Task GetSupport() + { + await this.form!.Validate(); + if (!this.inputIsValid) + return; + + var sbContext = new StringBuilder(); + if (this.codingContexts.Count > 0) + { + sbContext.AppendLine("I have the following coding context:"); + sbContext.AppendLine(); + foreach (var codingContext in this.codingContexts) + { + sbContext.AppendLine($"ID: {codingContext.Id}"); + sbContext.AppendLine($"Language: {codingContext.Language.Name()}"); + sbContext.AppendLine($"Other Language: {codingContext.OtherLanguage}"); + sbContext.AppendLine($"Content:"); + sbContext.AppendLine("```"); + sbContext.AppendLine(codingContext.Code); + sbContext.AppendLine("```"); + sbContext.AppendLine(); + } + } + + var sbCompilerMessages = new StringBuilder(); + if (this.provideCompilerMessages) + { + sbCompilerMessages.AppendLine("I have the following compiler messages:"); + sbCompilerMessages.AppendLine(); + sbCompilerMessages.AppendLine("```"); + sbCompilerMessages.AppendLine(this.compilerMessages); + sbCompilerMessages.AppendLine("```"); + sbCompilerMessages.AppendLine(); + } + + this.CreateChatThread(); + var time = this.AddUserRequest( + $""" + {sbContext} + {sbCompilerMessages} + + My questions are: + {this.questions} + """); + + await this.AddAIResponseAsync(time); + } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Pages/Coding/CodingContext.cs b/app/MindWork AI Studio/Components/Pages/Coding/CodingContext.cs index acce9828..726eccae 100644 --- a/app/MindWork AI Studio/Components/Pages/Coding/CodingContext.cs +++ b/app/MindWork AI Studio/Components/Pages/Coding/CodingContext.cs @@ -1,3 +1,16 @@ namespace AIStudio.Components.Pages.Coding; -public readonly record struct CodingContext(string Id, CommonCodingLanguages Language, string Code); \ No newline at end of file +public sealed class CodingContext(string id, CommonCodingLanguages language, string otherLanguage, string code) +{ + public CodingContext() : this(string.Empty, CommonCodingLanguages.NONE, string.Empty, string.Empty) + { + } + + public string Id { get; set; } = id; + + public CommonCodingLanguages Language { get; set; } = language; + + public string OtherLanguage { get; set; } = otherLanguage; + + public string Code { get; set; } = code; +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Pages/Coding/CodingContextItem.razor b/app/MindWork AI Studio/Components/Pages/Coding/CodingContextItem.razor index 1163771b..5c28bb3a 100644 --- a/app/MindWork AI Studio/Components/Pages/Coding/CodingContextItem.razor +++ b/app/MindWork AI Studio/Components/Pages/Coding/CodingContextItem.razor @@ -1 +1,14 @@ - \ No newline at end of file + + + + @foreach (var language in Enum.GetValues()) + { + @language.Name() + } + + @if (this.CodingContext.Language is CommonCodingLanguages.OTHER) + { + + } + + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Pages/Coding/CodingContextItem.razor.cs b/app/MindWork AI Studio/Components/Pages/Coding/CodingContextItem.razor.cs index db7f95c3..bb425de4 100644 --- a/app/MindWork AI Studio/Components/Pages/Coding/CodingContextItem.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/Coding/CodingContextItem.razor.cs @@ -7,7 +7,10 @@ namespace AIStudio.Components.Pages.Coding; public partial class CodingContextItem : ComponentBase { [Parameter] - public CodingContext CodingContext { get; set; } + public CodingContext CodingContext { get; set; } = new(); + + [Parameter] + public EventCallback CodingContextChanged { get; set; } [Inject] protected SettingsManager SettingsManager { get; set; } = null!; @@ -25,4 +28,23 @@ public partial class CodingContextItem : ComponentBase } #endregion + + private string? ValidatingCode(string code) + { + if(string.IsNullOrWhiteSpace(code)) + return $"{this.CodingContext.Id}: Please provide your input."; + + return null; + } + + private string? ValidatingOtherLanguage(string language) + { + if(this.CodingContext.Language != CommonCodingLanguages.OTHER) + return null; + + if(string.IsNullOrWhiteSpace(language)) + return "Please specify the language."; + + return null; + } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Pages/Coding/CommonCodingLanguageExtensions.cs b/app/MindWork AI Studio/Components/Pages/Coding/CommonCodingLanguageExtensions.cs index a1351546..9d47105c 100644 --- a/app/MindWork AI Studio/Components/Pages/Coding/CommonCodingLanguageExtensions.cs +++ b/app/MindWork AI Studio/Components/Pages/Coding/CommonCodingLanguageExtensions.cs @@ -7,6 +7,7 @@ public static class CommonCodingLanguageExtensions CommonCodingLanguages.NONE => "None", CommonCodingLanguages.BASH => "Bash", + CommonCodingLanguages.BLAZOR => ".NET Blazor", CommonCodingLanguages.C => "C", CommonCodingLanguages.CPP => "C++", CommonCodingLanguages.CSHARP => "C#", diff --git a/app/MindWork AI Studio/Components/Pages/Coding/CommonCodingLanguages.cs b/app/MindWork AI Studio/Components/Pages/Coding/CommonCodingLanguages.cs index 0e728e1d..58d9d80c 100644 --- a/app/MindWork AI Studio/Components/Pages/Coding/CommonCodingLanguages.cs +++ b/app/MindWork AI Studio/Components/Pages/Coding/CommonCodingLanguages.cs @@ -5,6 +5,7 @@ public enum CommonCodingLanguages NONE, BASH, + BLAZOR, C, CPP, CSHARP,