Files
Yi.Framework/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Extensions/ChatMessageExtensions.cs
2025-06-25 00:05:00 +08:00

21 lines
584 B
C#

using System.Reflection;
using OpenAI.Chat;
namespace Yi.Framework.AiHub.Domain.Extensions;
public static class ChatMessageExtensions
{
public static string GetRoleAsString(this ChatMessage message)
{
var type = message.GetType();
var propertyInfo = type.GetProperty("Role", BindingFlags.NonPublic | BindingFlags.Instance);
if (propertyInfo != null)
{
var value = propertyInfo.GetValue(message) as ChatMessageRole?;
return value.ToString().ToLower();
}
return string.Empty;
}
}