using XFEExtension.NetCore.Exceptions; namespace XFEExtension.NetCore.XFEChatGPT.ChatGPTInnerClass.DefaultClass; /// /// GPT消息 /// /// 角色 /// 内容 public class GPTMessage(string role, string content) { private string _role = role; /// /// 角色(目前已知有:System,User和Assistant) /// public string Role { get { return _role; } set { _role = SetRoleAndCheckRoleLegal(value); } } /// /// 与角色对应的消息内容 /// public string Content { get; set; } = content; private static string SetRoleAndCheckRoleLegal(string inputRole) { var lowerRole = inputRole.ToLower(); if (lowerRole is "system" or "user" or "assistant") { return lowerRole; } throw new XFEChatGPTException($"角色名称不合法:{inputRole}\n应为system,user或assistant三者中的一个"); } }