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) { string lowerRole = inputRole.ToLower(); if (lowerRole == "system" || lowerRole == "user" || lowerRole == "assistant") { return lowerRole; } else { throw new XFEChatGPTException($"角色名称不合法:{inputRole}\n应为system,user或assistant三者中的一个"); } } }