mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-02-05 11:49:06 +00:00
Adding a coding assistant (#38)
This commit is contained in:
parent
a9ca51377e
commit
a956b55d6b
@ -57,6 +57,14 @@ public abstract partial class AssistantBase : ComponentBase
|
||||
|
||||
#endregion
|
||||
|
||||
protected string? ValidatingProvider(AIStudio.Settings.Provider provider)
|
||||
{
|
||||
if(provider.UsedProvider == Providers.NONE)
|
||||
return "Please select a provider.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void CreateChatThread()
|
||||
{
|
||||
this.chatThread = new()
|
||||
|
@ -13,6 +13,7 @@ public partial class Changelog
|
||||
|
||||
public static readonly Log[] LOGS =
|
||||
[
|
||||
new (164, "v0.8.2, build 164 (2024-07-16 18:03 UTC)", "v0.8.2.md"),
|
||||
new (163, "v0.8.1, build 163 (2024-07-16 08:32 UTC)", "v0.8.1.md"),
|
||||
new (162, "v0.8.0, build 162 (2024-07-14 19:39 UTC)", "v0.8.0.md"),
|
||||
new (161, "v0.7.1, build 161 (2024-07-13 11:42 UTC)", "v0.7.1.md"),
|
||||
|
@ -8,4 +8,5 @@
|
||||
<AssistantBlock Name="Icon Finder" Description="Using a LLM to find an icon for a given context." Icon="@Icons.Material.Filled.FindInPage" Link="/assistant/icons"/>
|
||||
<AssistantBlock Name="Text Summarizer" Description="Using a LLM to summarize a given text." Icon="@Icons.Material.Filled.TextSnippet" Link="/assistant/summarizer"/>
|
||||
<AssistantBlock Name="Translator" Description="Translate text into another language." Icon="@Icons.Material.Filled.Translate" Link="/assistant/translator"/>
|
||||
<AssistantBlock Name="Coding" Description="Get coding and debugging support from a LLM." Icon="@Icons.Material.Filled.Code" Link="/assistant/coding"/>
|
||||
</MudGrid>
|
@ -0,0 +1,39 @@
|
||||
@page "/assistant/coding"
|
||||
@using AIStudio.Settings
|
||||
@inherits AssistantBaseCore
|
||||
|
||||
<MudExpansionPanels Class="mb-3">
|
||||
@for (var contextIndex = 0; contextIndex < this.codingContexts.Count; contextIndex++)
|
||||
{
|
||||
var codingContext = this.codingContexts[contextIndex];
|
||||
<ExpansionPanel HeaderText="@codingContext.Id" HeaderIcon="@Icons.Material.Filled.Code">
|
||||
<CodingContextItem @bind-CodingContext="@codingContext"/>
|
||||
</ExpansionPanel>
|
||||
}
|
||||
</MudExpansionPanels>
|
||||
<MudButton Variant="Variant.Filled" OnClick="() => this.AddCodingContext()" Class="mb-3">
|
||||
Add context
|
||||
</MudButton>
|
||||
|
||||
<MudStack Row="@false" Class="mb-3">
|
||||
<MudSwitch T="bool" @bind-Value="@this.provideCompilerMessages">
|
||||
@(this.provideCompilerMessages ? "Provide compiler messages" : "Provide no compiler messages")
|
||||
</MudSwitch>
|
||||
@if (this.provideCompilerMessages)
|
||||
{
|
||||
<MudTextField T="string" @bind-Text="@this.compilerMessages" Validation="@this.ValidatingCompilerMessages" AdornmentIcon="@Icons.Material.Filled.Error" Adornment="Adornment.Start" Label="Compiler messages" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
}
|
||||
</MudStack>
|
||||
|
||||
<MudTextField T="string" @bind-Text="@this.questions" Validation="@this.ValidateQuestions" AdornmentIcon="@Icons.Material.Filled.QuestionMark" Adornment="Adornment.Start" Label="Your question(s)" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
|
||||
<MudSelect T="Provider" @bind-Value="@this.providerSettings" Validation="@this.ValidatingProvider" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Apps" Margin="Margin.Dense" Label="Provider" Class="mb-3 rounded-lg" Variant="Variant.Outlined">
|
||||
@foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
|
||||
{
|
||||
<MudSelectItem Value="@provider"/>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Info" OnClick="() => this.GetSupport()" Class="mb-3">
|
||||
Get support
|
||||
</MudButton>
|
@ -0,0 +1,106 @@
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Components.Pages.Coding;
|
||||
|
||||
public partial class AssistantCoding : AssistantBaseCore
|
||||
{
|
||||
protected override string Title => "Coding Assistant";
|
||||
|
||||
protected override string Description =>
|
||||
"""
|
||||
This coding assistant supports you in writing code. Provide some coding context by copying and pasting
|
||||
your code into the input fields. You might assign an ID to your code snippet to easily reference it later.
|
||||
When you have compiler messages, you can paste them into the input fields to get help with debugging as well.
|
||||
""";
|
||||
|
||||
protected override string SystemPrompt =>
|
||||
"""
|
||||
You are a friendly, helpful senior software developer with extensive experience in various programming languages
|
||||
and concepts. You are familiar with principles like DRY, KISS, YAGNI, and SOLID and can apply and explain them.
|
||||
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<CodingContext> 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);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
namespace AIStudio.Components.Pages.Coding;
|
||||
|
||||
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;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<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"/>
|
||||
<MudStack Row="@true" AlignItems="AlignItems.Center" Class="mb-3">
|
||||
<MudSelect T="CommonCodingLanguages" @bind-Value="@this.CodingContext.Language" AdornmentIcon="@Icons.Material.Filled.Code" Adornment="Adornment.Start" Label="Language" Variant="Variant.Outlined" Margin="Margin.Dense">
|
||||
@foreach (var language in Enum.GetValues<CommonCodingLanguages>())
|
||||
{
|
||||
<MudSelectItem Value="@language">@language.Name()</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
@if (this.CodingContext.Language is CommonCodingLanguages.OTHER)
|
||||
{
|
||||
<MudTextField T="string" @bind-Text="@this.CodingContext.OtherLanguage" Validation="@this.ValidatingOtherLanguage" Label="Other language" Variant="Variant.Outlined" Margin="Margin.Dense" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
|
||||
}
|
||||
</MudStack>
|
||||
<MudTextField T="string" @bind-Text="@this.CodingContext.Code" Validation="@this.ValidatingCode" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="Your code" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES" />
|
@ -0,0 +1,50 @@
|
||||
using AIStudio.Settings;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Components.Pages.Coding;
|
||||
|
||||
public partial class CodingContextItem : ComponentBase
|
||||
{
|
||||
[Parameter]
|
||||
public CodingContext CodingContext { get; set; } = new();
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<CodingContext> CodingContextChanged { get; set; }
|
||||
|
||||
[Inject]
|
||||
protected SettingsManager SettingsManager { get; set; } = null!;
|
||||
|
||||
private static readonly Dictionary<string, object?> USER_INPUT_ATTRIBUTES = new();
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
// Configure the spellchecking for the user input:
|
||||
this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES);
|
||||
|
||||
await base.OnParametersSetAsync();
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
namespace AIStudio.Components.Pages.Coding;
|
||||
|
||||
public static class CommonCodingLanguageExtensions
|
||||
{
|
||||
public static string Name(this CommonCodingLanguages language) => language switch
|
||||
{
|
||||
CommonCodingLanguages.NONE => "None",
|
||||
|
||||
CommonCodingLanguages.BASH => "Bash",
|
||||
CommonCodingLanguages.BLAZOR => ".NET Blazor",
|
||||
CommonCodingLanguages.C => "C",
|
||||
CommonCodingLanguages.CPP => "C++",
|
||||
CommonCodingLanguages.CSHARP => "C#",
|
||||
CommonCodingLanguages.CSS => "CSS",
|
||||
CommonCodingLanguages.FORTRAN => "Fortran",
|
||||
CommonCodingLanguages.GDSCRIPT => "GDScript",
|
||||
CommonCodingLanguages.GO => "Go",
|
||||
CommonCodingLanguages.HTML => "HTML",
|
||||
CommonCodingLanguages.JAVA => "Java",
|
||||
CommonCodingLanguages.JAVASCRIPT => "JavaScript",
|
||||
CommonCodingLanguages.JSON => "JSON",
|
||||
CommonCodingLanguages.JULIA => "Julia",
|
||||
CommonCodingLanguages.KOTLIN => "Kotlin",
|
||||
CommonCodingLanguages.LUA => "Lua",
|
||||
CommonCodingLanguages.MARKDOWN => "Markdown",
|
||||
CommonCodingLanguages.MATHEMATICA => "Mathematica",
|
||||
CommonCodingLanguages.MATLAB => "MATLAB",
|
||||
CommonCodingLanguages.PHP => "PHP",
|
||||
CommonCodingLanguages.POWERSHELL => "PowerShell",
|
||||
CommonCodingLanguages.PROLOG => "Prolog",
|
||||
CommonCodingLanguages.PYTHON => "Python",
|
||||
CommonCodingLanguages.R => "R",
|
||||
CommonCodingLanguages.RUBY => "Ruby",
|
||||
CommonCodingLanguages.RUST => "Rust",
|
||||
CommonCodingLanguages.SQL => "SQL",
|
||||
CommonCodingLanguages.SWIFT => "Swift",
|
||||
CommonCodingLanguages.TYPESCRIPT => "TypeScript",
|
||||
CommonCodingLanguages.XML => "XML",
|
||||
|
||||
CommonCodingLanguages.OTHER => "Other",
|
||||
_ => "Unknown"
|
||||
};
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
namespace AIStudio.Components.Pages.Coding;
|
||||
|
||||
public enum CommonCodingLanguages
|
||||
{
|
||||
NONE,
|
||||
|
||||
BASH,
|
||||
BLAZOR,
|
||||
C,
|
||||
CPP,
|
||||
CSHARP,
|
||||
CSS,
|
||||
FORTRAN,
|
||||
GDSCRIPT,
|
||||
GO,
|
||||
HTML,
|
||||
JAVA,
|
||||
JAVASCRIPT,
|
||||
JSON,
|
||||
JULIA,
|
||||
KOTLIN,
|
||||
LUA,
|
||||
MARKDOWN,
|
||||
MATHEMATICA,
|
||||
MATLAB,
|
||||
PHP,
|
||||
POWERSHELL,
|
||||
PROLOG,
|
||||
PYTHON,
|
||||
R,
|
||||
RUBY,
|
||||
RUST,
|
||||
SQL,
|
||||
SWIFT,
|
||||
TYPESCRIPT,
|
||||
XML,
|
||||
|
||||
OTHER,
|
||||
}
|
@ -35,14 +35,6 @@ public partial class AssistantIconFinder : AssistantBaseCore
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidatingProvider(AIStudio.Settings.Provider provider)
|
||||
{
|
||||
if(provider.UsedProvider == Providers.NONE)
|
||||
return "Please select a provider.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task FindIcon()
|
||||
{
|
||||
|
@ -38,14 +38,6 @@ public partial class AssistantTextSummarizer : AssistantBaseCore
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidatingProvider(AIStudio.Settings.Provider provider)
|
||||
{
|
||||
if(provider.UsedProvider == Providers.NONE)
|
||||
return "Please select a provider.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateCustomLanguage(string language)
|
||||
{
|
||||
if(this.selectedTargetLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
|
||||
|
@ -34,14 +34,6 @@ public partial class AssistantTranslator : AssistantBaseCore
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidatingProvider(AIStudio.Settings.Provider provider)
|
||||
{
|
||||
if(provider.UsedProvider == Providers.NONE)
|
||||
return "Please select a provider.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidatingTargetLanguage(CommonLanguages language)
|
||||
{
|
||||
if(language == CommonLanguages.AS_IS)
|
||||
|
@ -1,2 +1,3 @@
|
||||
# v0.8.2, build 164 (2024-07-xxx
|
||||
- Fixed the in-app description of possible self-hosted models.
|
||||
# v0.8.2, build 164 (2024-07-16 18:03 UTC)
|
||||
- Added the coding assistant.
|
||||
- Fixed the in-app description of possible self-hosted models.
|
@ -1,9 +1,9 @@
|
||||
0.8.1
|
||||
2024-07-16 08:32:21 UTC
|
||||
163
|
||||
0.8.2
|
||||
2024-07-16 18:03:04 UTC
|
||||
164
|
||||
8.0.107 (commit 1bdaef7265)
|
||||
8.0.7 (commit 2aade6beb0)
|
||||
1.79.0 (commit 129f3b996)
|
||||
6.20.0
|
||||
1.6.1
|
||||
063fd0fcfa2, release
|
||||
c92ce49af2d, release
|
||||
|
2
runtime/Cargo.lock
generated
2
runtime/Cargo.lock
generated
@ -2313,7 +2313,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||
|
||||
[[package]]
|
||||
name = "mindwork-ai-studio"
|
||||
version = "0.8.1"
|
||||
version = "0.8.2"
|
||||
dependencies = [
|
||||
"arboard",
|
||||
"flexi_logger",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mindwork-ai-studio"
|
||||
version = "0.8.1"
|
||||
version = "0.8.2"
|
||||
edition = "2021"
|
||||
description = "MindWork AI Studio"
|
||||
authors = ["Thorsten Sommer"]
|
||||
|
@ -6,7 +6,7 @@
|
||||
},
|
||||
"package": {
|
||||
"productName": "MindWork AI Studio",
|
||||
"version": "0.8.1"
|
||||
"version": "0.8.2"
|
||||
},
|
||||
"tauri": {
|
||||
"allowlist": {
|
||||
|
Loading…
Reference in New Issue
Block a user