mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-20 22:32:56 +00:00
Refactor ChatRole extensions into a dedicated class file
This commit is contained in:
parent
8ac19d6dda
commit
8cb951c63c
@ -14,68 +14,4 @@ public enum ChatRole
|
||||
USER,
|
||||
AI,
|
||||
AGENT,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extensions for the ChatRole enum.
|
||||
/// </summary>
|
||||
public static class ExtensionsChatRole
|
||||
{
|
||||
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ChatRole).Namespace, nameof(ChatRole));
|
||||
|
||||
/// <summary>
|
||||
/// Returns the name of the role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role.</param>
|
||||
/// <returns>The name of the role.</returns>
|
||||
public static string ToName(this ChatRole role) => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => TB("System"),
|
||||
ChatRole.USER => TB("You"),
|
||||
ChatRole.AI => TB("AI"),
|
||||
|
||||
_ => TB("Unknown"),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Returns the color of the role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role.</param>
|
||||
/// <returns>The color of the role.</returns>
|
||||
public static Color ToColor(this ChatRole role) => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => Color.Info,
|
||||
ChatRole.USER => Color.Primary,
|
||||
ChatRole.AI => Color.Tertiary,
|
||||
|
||||
_ => Color.Error,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Returns the icon of the role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role.</param>
|
||||
/// <returns>The icon of the role.</returns>
|
||||
public static string ToIcon(this ChatRole role) => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => Icons.Material.Filled.Settings,
|
||||
ChatRole.USER => Icons.Material.Filled.Person,
|
||||
ChatRole.AI => Icons.Material.Filled.AutoAwesome,
|
||||
|
||||
_ => Icons.Material.Filled.Help,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Returns the specific name of the role for the chat template.
|
||||
/// </summary>
|
||||
/// <param name="role">The role.</param>
|
||||
/// <returns>The name of the role.</returns>
|
||||
public static string ToChatTemplateName(this ChatRole role) => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => TB("System"),
|
||||
ChatRole.USER => TB("User"),
|
||||
ChatRole.AI => TB("Assistant"),
|
||||
|
||||
_ => TB("Unknown"),
|
||||
};
|
||||
}
|
75
app/MindWork AI Studio/Chat/ChatRoleExtensions.cs
Normal file
75
app/MindWork AI Studio/Chat/ChatRoleExtensions.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
|
||||
namespace AIStudio.Chat;
|
||||
|
||||
public static class ChatRoleExtensions
|
||||
{
|
||||
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ChatRoleExtensions).Namespace, nameof(ChatRoleExtensions));
|
||||
|
||||
/// <summary>
|
||||
/// Returns the name of the role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role.</param>
|
||||
/// <returns>The name of the role.</returns>
|
||||
public static string ToName(this ChatRole role) => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => TB("System"),
|
||||
ChatRole.USER => TB("You"),
|
||||
ChatRole.AI => TB("AI"),
|
||||
|
||||
_ => TB("Unknown"),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Returns the color of the role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role.</param>
|
||||
/// <returns>The color of the role.</returns>
|
||||
public static Color ToColor(this ChatRole role) => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => Color.Info,
|
||||
ChatRole.USER => Color.Primary,
|
||||
ChatRole.AI => Color.Tertiary,
|
||||
|
||||
_ => Color.Error,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Returns the icon of the role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role.</param>
|
||||
/// <returns>The icon of the role.</returns>
|
||||
public static string ToIcon(this ChatRole role) => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => Icons.Material.Filled.Settings,
|
||||
ChatRole.USER => Icons.Material.Filled.Person,
|
||||
ChatRole.AI => Icons.Material.Filled.AutoAwesome,
|
||||
|
||||
_ => Icons.Material.Filled.Help,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Returns the specific name of the role for the chat template.
|
||||
/// </summary>
|
||||
/// <param name="role">The role.</param>
|
||||
/// <returns>The name of the role.</returns>
|
||||
public static string ToChatTemplateName(this ChatRole role) => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => TB("System"),
|
||||
ChatRole.USER => TB("User"),
|
||||
ChatRole.AI => TB("Assistant"),
|
||||
|
||||
_ => TB("Unknown"),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Selects the next role for a chat template.
|
||||
/// </summary>
|
||||
/// <param name="currentRole">The current role.</param>
|
||||
/// <returns>The next role for the chat template.</returns>
|
||||
public static ChatRole SelectNextRoleForTemplate(this ChatRole currentRole) => currentRole switch
|
||||
{
|
||||
ChatRole.USER => ChatRole.AI,
|
||||
_ => ChatRole.USER,
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user