XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension

【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEExtension.NetCore.Exceptions;

namespace XFEExtension.NetCore.XFEChatGPT.ChatGPTInnerClass.DefaultClass;

/// <summary>
/// GPT消息
/// </summary>
/// <param name="role">角色</param>
/// <param name="content">内容</param>
public class GPTMessage(string role, string content)
{
    private string _role = role;
    /// <summary>
    /// 角色(目前已知有:System,User和Assistant)
    /// </summary>
    public string Role
    {
        get
        {
            return _role;
        }
        set
        {
            _role = SetRoleAndCheckRoleLegal(value);
        }
    }
    /// <summary>
    /// 与角色对应的消息内容
    /// </summary>
    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三者中的一个");
    }
}