using XFEExtension.NetCore.FormatExtension;
namespace XFEExtension.NetCore.XFEChatGPT.ChatGPTInnerClass.HelperClass;
///
/// API密钥
///
/// 秘钥
/// 描述
public class ApiKey(string aPIKey, string description)
{
private static readonly char[] separator = ['{', '}'];
///
/// APIKEY
///
public string APIKey { get; set; } = aPIKey;
///
/// APIKey的描述
///
public string Description { get; set; } = description;
///
/// 转换为字符串
///
///
public override string ToString()
{
return $"{{[+-{Description}-+][+-{APIKey}-+]}}";
}
///
/// 将字符串转换为ApiKey的List
///
///
///
public static List ToApiKey(string keyString)
{
string[] keyGroup = keyString.Split(separator);
List apiKeys = [];
foreach (string key in keyGroup)
{
string[] oneKey = key.Split(XFEDictionary.EntrySeparator, StringSplitOptions.RemoveEmptyEntries);
if (oneKey.Length == 2)
{
apiKeys.Add(new ApiKey(oneKey[1], oneKey[0]));
}
}
return apiKeys;
}
}