Skip to content

Commit 2f83b8f

Browse files
committed
Add Experimental tab with AI chat for commands
Introduces an Experimental tab that allows users to interact with an AI assistant for Minecraft command building. Refactors tab titles to use constants for consistency, updates dependencies to support AI features, and registers an IChatClient using OllamaSharp and Microsoft.Extensions.AI.
1 parent 909e0d6 commit 2f83b8f

21 files changed

+108
-16
lines changed

MinecraftCommandBuilder/Components/CommandTabs/EffectsTab.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h3>Effects</h3>
1+
<h3>@TabTitle</h3>
22

33
<MudStack>
44
<PlayerNameComponent/>

MinecraftCommandBuilder/Components/CommandTabs/EffectsTab.razor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ namespace MinecraftCommandBuilder.Components.CommandTabs;
22

33
public partial class EffectsTab
44
{
5+
public const string TabTitle = "Effects";
6+
57
private List<Effect> Effects { get; set; } = [];
68

79
private Effect? SelectedEffect { get; set; }

MinecraftCommandBuilder/Components/CommandTabs/EnchantsTab.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h3>Enchantments</h3>
1+
<h3>@TabTitle</h3>
22

33
<MudStack>
44
<PlayerNameComponent/>

MinecraftCommandBuilder/Components/CommandTabs/EnchantsTab.razor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ namespace MinecraftCommandBuilder.Components.CommandTabs;
22

33
public partial class EnchantsTab
44
{
5+
public const string TabTitle = "Enchantments";
6+
57
private readonly List<string> BestAxeEnchantmentNames =
68
[
79
"unbreaking",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<h3>@TabTitle</h3>
2+
3+
<MudTextField @bind-Value="@UserInputText"
4+
Placeholder="Type your command here..."
5+
Lines="1"
6+
Adornment="Adornment.Start"
7+
AdornmentIcon="@Icons.Material.Filled.Input"
8+
AdornmentColor="Color.Primary"
9+
Class="mb-2"
10+
Immediate="true" />
11+
12+
<MudButton Variant="Variant.Filled"
13+
Color="Color.Primary"
14+
OnClick="@GetResponseFromChat"
15+
StartIcon="@Icons.Material.Filled.Send"
16+
Class="mb-2">
17+
Send
18+
</MudButton>
19+
20+
@if (!string.IsNullOrEmpty(ChatOutputText))
21+
{
22+
<MudText>
23+
@((MarkupString)ChatOutputText)
24+
</MudText>
25+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace MinecraftCommandBuilder.Components.CommandTabs;
2+
3+
public partial class ExperimentalTab
4+
{
5+
public const string TabTitle = "Experimental";
6+
7+
private string UserInputText = string.Empty;
8+
9+
private string ChatOutputText = string.Empty;
10+
11+
List<ChatMessage> messages = [new(ChatRole.System, """
12+
You are a helpful assistant for Minecraft command building. Your task is to assist users in creating Minecraft commands based on their input.
13+
You should provide clear and concise responses, and if the user asks for help with a specific command, you should guide them through the process of building that command step by step.
14+
If the user asks for help with a specific command, you should ask them for more details about what they want to achieve.
15+
""")];
16+
17+
private async Task GetResponseFromChat()
18+
{
19+
if (string.IsNullOrWhiteSpace(UserInputText))
20+
{
21+
return;
22+
}
23+
24+
messages.Add(new ChatMessage(ChatRole.User, UserInputText));
25+
26+
var response = await ChatClient.GetResponseAsync(messages);
27+
28+
if (response is not null)
29+
{
30+
messages.Add(new ChatMessage(ChatRole.Assistant, response.Text));
31+
ChatOutputText = response.Text;
32+
}
33+
else
34+
{
35+
ChatOutputText = "No response received.";
36+
}
37+
}
38+
}

MinecraftCommandBuilder/Components/CommandTabs/FillTab.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h3>FillTab</h3>
1+
<h3>@TabTitle</h3>
22

33
<MudStack>
44
<PlayerNameComponent/>

MinecraftCommandBuilder/Components/CommandTabs/FillTab.razor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ namespace MinecraftCommandBuilder.Components.CommandTabs;
22

33
public partial class FillTab
44
{
5+
public const string TabTitle = "Fill";
6+
57
private int Width { get; set; }
68

79
private int Height { get; set; }

MinecraftCommandBuilder/Components/CommandTabs/GameModeTab.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h3>Game Mode</h3>
1+
<h3>@TabTitle</h3>
22

33
<MudStack>
44
<PlayerNameComponent/>

MinecraftCommandBuilder/Components/CommandTabs/GameModeTab.razor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ namespace MinecraftCommandBuilder.Components.CommandTabs;
22

33
public partial class GameModeTab
44
{
5+
public const string TabTitle = "Game Mode";
6+
57
public enum GameMode
68
{
79
Survival,

0 commit comments

Comments
 (0)