AI-Studio/app/MindWork AI Studio/Chat/ChatRole.cs

81 lines
2.1 KiB
C#
Raw Normal View History

2025-05-24 10:27:00 +00:00
using AIStudio.Tools.PluginSystem;
2024-05-04 09:11:09 +00:00
namespace AIStudio.Chat;
/// <summary>
/// Possible roles in the chat.
/// </summary>
public enum ChatRole
{
NONE,
UNKNOWN,
SYSTEM,
USER,
AI,
AGENT,
2024-05-04 09:11:09 +00:00
}
/// <summary>
/// Extensions for the ChatRole enum.
/// </summary>
public static class ExtensionsChatRole
{
2025-05-24 10:27:00 +00:00
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ChatRole).Namespace, nameof(ChatRole));
2024-05-04 09:11:09 +00:00
/// <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
{
2025-05-24 10:27:00 +00:00
ChatRole.SYSTEM => TB("System"),
ChatRole.USER => TB("You"),
ChatRole.AI => TB("AI"),
2024-05-04 09:11:09 +00:00
2025-05-24 10:27:00 +00:00
_ => TB("Unknown"),
2024-05-04 09:11:09 +00:00
};
/// <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,
};
2025-05-24 10:27:00 +00:00
/// <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"),
};
2024-05-04 09:11:09 +00:00
}