-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
126 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/AzureOpenAIProxy.PlaygroundApp/Components/UI/ChatHistoryComponent.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@using AzureOpenAIProxy.PlaygroundApp.Models | ||
|
||
<FluentStack Id="@Id" Style="width: 100%;" Orientation="Orientation.Vertical" VerticalAlignment="VerticalAlignment.Top"> | ||
@if (this.Messages != null && this.Messages.Any()) | ||
{ | ||
foreach (var message in this.Messages) | ||
{ | ||
<FluentStack id="message-@(this.Messages.IndexOf(message).ToString("00"))" Style="width: 100%;" Orientation="Orientation.Horizontal" HorizontalAlignment="@(message.Role == MessageRole.Assistant ? HorizontalAlignment.Start : HorizontalAlignment.End)"> | ||
<FluentCard Style="width: 70%;" MinimalStyle="true"> | ||
<p>@message.Message</p> | ||
</FluentCard> | ||
</FluentStack> | ||
} | ||
} | ||
</FluentStack> | ||
|
||
@code { | ||
[Parameter] | ||
public string? Id { get; set; } | ||
|
||
[Parameter] | ||
public List<ChatMessage>? Messages { get; set; } | ||
} |
47 changes: 47 additions & 0 deletions
47
src/AzureOpenAIProxy.PlaygroundApp/Components/UI/ChatPromptComponent.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<FluentStack Id="@Id" Style="width: 100%;" Orientation="Orientation.Vertical" VerticalAlignment="VerticalAlignment.Bottom"> | ||
<FluentTextArea Id="prompt" Style="width: 100%;" Rows="6" Placeholder="Type user query here. (Shift + Enter for new line)" @bind-Value="prompt" @onchange="UpdatePrompt"></FluentTextArea> | ||
<FluentStack Style="width: 100%;" Orientation="Orientation.Horizontal" HorizontalAlignment="HorizontalAlignment.Start"> | ||
<FluentStack Style="width: 50%;" Orientation="Orientation.Horizontal" HorizontalAlignment="HorizontalAlignment.Start"> | ||
<FluentButton Id="button-clear" IconStart="@(new Icons.Regular.Size20.Broom())" OnClick="ClearChat">Clear</FluentButton> | ||
</FluentStack> | ||
<FluentStack Style="width: 50%;" Orientation="Orientation.Horizontal" HorizontalAlignment="HorizontalAlignment.End"> | ||
<FluentButton Id="button-send" IconStart="@(new Icons.Regular.Size20.Send())" OnClick="CompleteChat">Send</FluentButton> | ||
</FluentStack> | ||
</FluentStack> | ||
</FluentStack> | ||
|
||
@code { | ||
private string? prompt; | ||
|
||
[Parameter] | ||
public string? Id { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<string?> OnPromptSent { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback OnChatCleared { get; set; } | ||
|
||
private async Task UpdatePrompt(ChangeEventArgs e) | ||
{ | ||
this.prompt = e.Value!.ToString(); | ||
|
||
await Task.CompletedTask; | ||
} | ||
|
||
private async Task CompleteChat() | ||
{ | ||
if (string.IsNullOrWhiteSpace(this.prompt) == true) | ||
{ | ||
return; | ||
} | ||
|
||
await this.OnPromptSent.InvokeAsync(this.prompt); | ||
this.prompt = string.Empty; | ||
} | ||
|
||
private async Task ClearChat() | ||
{ | ||
await this.OnChatCleared.InvokeAsync(); | ||
} | ||
} |
35 changes: 15 additions & 20 deletions
35
src/AzureOpenAIProxy.PlaygroundApp/Components/UI/ChatWindowComponent.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,34 @@ | ||
<FluentLayout Id="@Id"> | ||
<FluentTextArea Style="width: 100%;" Rows="6" Placeholder="Type user query here. (Shift + Enter for new line)" @bind-Value="prompt" @onchange="UpdatePrompt"></FluentTextArea> | ||
<FluentStack Style="width: 100%;" Orientation="Orientation.Horizontal" HorizontalAlignment="HorizontalAlignment.Start"> | ||
<FluentStack Style="width: 50%;" Orientation="Orientation.Horizontal" HorizontalAlignment="HorizontalAlignment.Start"> | ||
<FluentButton IconStart="@(new Icons.Regular.Size20.Broom())" OnClick="ClearChat">Clear</FluentButton> | ||
</FluentStack> | ||
<FluentStack Style="width: 50%;" Orientation="Orientation.Horizontal" HorizontalAlignment="HorizontalAlignment.End"> | ||
<FluentButton IconStart="@(new Icons.Regular.Size20.Send())" OnClick="CompleteChat">Send</FluentButton> | ||
</FluentStack> | ||
</FluentStack> | ||
</FluentLayout> | ||
@using AzureOpenAIProxy.PlaygroundApp.Models | ||
|
||
<FluentStack Id="@Id" Style="width: 100%; height: 100%;" Orientation="Orientation.Vertical" VerticalAlignment="VerticalAlignment.Bottom"> | ||
<ChatHistoryComponent Id="chat-history" Messages="messages" /> | ||
<ChatPromptComponent Id="chat-prompt" OnPromptSent="SendPrompt" OnChatCleared="ClearMessage" /> | ||
</FluentStack> | ||
|
||
@code { | ||
private string? prompt; | ||
private List<ChatMessage>? messages; | ||
|
||
[Parameter] | ||
public string? Id { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<string?> OnPromptSent { get; set; } | ||
|
||
private async Task UpdatePrompt(ChangeEventArgs e) | ||
protected override async Task OnInitializedAsync() | ||
{ | ||
this.prompt = e.Value!.ToString(); | ||
this.messages = []; | ||
|
||
await Task.CompletedTask; | ||
} | ||
|
||
private async Task CompleteChat() | ||
private async Task SendPrompt(string prompt) | ||
{ | ||
await this.OnPromptSent.InvokeAsync(this.prompt); | ||
this.messages!.Add(new ChatMessage() { Role = MessageRole.User, Message = prompt }); | ||
|
||
await Task.CompletedTask; | ||
} | ||
private async Task ClearChat() | ||
|
||
private async Task ClearMessage() | ||
{ | ||
this.messages!.Clear(); | ||
|
||
await Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace AzureOpenAIProxy.PlaygroundApp.Models; | ||
|
||
/// <summary> | ||
/// This represents the entity for chat message. | ||
/// </summary> | ||
public class ChatMessage | ||
{ | ||
/// <summary> | ||
/// Gets or sets the message role. | ||
/// </summary> | ||
public MessageRole? Role { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the message. | ||
/// </summary> | ||
public string? Message { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// This defines the role of the message. | ||
/// </summary> | ||
public enum MessageRole | ||
{ | ||
/// <summary> | ||
/// Indicates the role is not defined. | ||
/// </summary> | ||
Undefined, | ||
|
||
/// <summary> | ||
/// Indicates the user role. | ||
/// </summary> | ||
User, | ||
|
||
/// <summary> | ||
/// Indicates the assistant role. | ||
/// </summary> | ||
Assistant | ||
} |