AI优化和自动重连优化
This commit is contained in:
parent
1f7ae78257
commit
a1c64d42d1
@ -645,6 +645,10 @@ namespace Milimoe.RainBOT.ListeningTask
|
|||||||
Bot.ColorfulCheckPass(sender, "随机复读", dice, GeneralSettings.PRepeat, delay);
|
Bot.ColorfulCheckPass(sender, "随机复读", dice, GeneralSettings.PRepeat, delay);
|
||||||
GroupMessageContent content = new(e.group_id);
|
GroupMessageContent content = new(e.group_id);
|
||||||
content.message.AddRange(e.message);
|
content.message.AddRange(e.message);
|
||||||
|
if (e.CheckThrow(50, out _) && content.message.LastOrDefault(m => m is TextMessage) is TextMessage text)
|
||||||
|
{
|
||||||
|
text.data.text += "desuwa~";
|
||||||
|
}
|
||||||
_ = Bot.SendGroupMessage(e.group_id, "随机复读", content, delay * 1000);
|
_ = Bot.SendGroupMessage(e.group_id, "随机复读", content, delay * 1000);
|
||||||
_ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail);
|
_ = OshimaController.Instance.SCAdd(e.user_id, e.group_id, e.detail);
|
||||||
return quick_reply;
|
return quick_reply;
|
||||||
@ -706,8 +710,9 @@ namespace Milimoe.RainBOT.ListeningTask
|
|||||||
|
|
||||||
public static void AIChat(GroupMessageEvent e, bool isAt = false)
|
public static void AIChat(GroupMessageEvent e, bool isAt = false)
|
||||||
{
|
{
|
||||||
AI.Add(e.user_id == GeneralSettings.Master ? (Random.Shared.Next(0, 10) < 5 ? "小音" : "米莉") : e.sender.title, string.Join("", e.message.Where(m => m.type == "text").Select(s => s.data.ToString())));
|
if (e.sender.title == "No.18") e.sender.title = "小音";
|
||||||
if (!AI.CD && (isAt || e.detail.StartsWith("小雪") || AI.List.Count > 4))
|
AI.Add(e.user_id == GeneralSettings.Master ? "米莉" : e.sender.title, string.Join("", e.message.Where(m => m.type == "text").Select(s => s.data.ToString())));
|
||||||
|
if (!AI.CD && (isAt || e.detail.StartsWith("小雪") || AI.Count > 4))
|
||||||
{
|
{
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,8 +6,8 @@ namespace Milimoe.RainBOT.Settings
|
|||||||
{
|
{
|
||||||
public class AI
|
public class AI
|
||||||
{
|
{
|
||||||
|
public static int Count { get; set; } = 0;
|
||||||
public static bool CD { get; set; } = false;
|
public static bool CD { get; set; } = false;
|
||||||
public static HashSet<string> Context { get; set; } = [];
|
|
||||||
public static HashSet<string> List { get; set; } = [];
|
public static HashSet<string> List { get; set; } = [];
|
||||||
private static readonly string apiKey = GeneralSettings.AIAPIToken;
|
private static readonly string apiKey = GeneralSettings.AIAPIToken;
|
||||||
private static readonly string apiUrl = "https://api.deepseek.com/chat/completions";
|
private static readonly string apiUrl = "https://api.deepseek.com/chat/completions";
|
||||||
@ -19,6 +19,7 @@ namespace Milimoe.RainBOT.Settings
|
|||||||
|
|
||||||
public static void Add(string user, string msg)
|
public static void Add(string user, string msg)
|
||||||
{
|
{
|
||||||
|
Count++;
|
||||||
if (msg.Trim() == "") return;
|
if (msg.Trim() == "") return;
|
||||||
if (List.Count < 10)
|
if (List.Count < 10)
|
||||||
{
|
{
|
||||||
@ -29,6 +30,7 @@ namespace Milimoe.RainBOT.Settings
|
|||||||
|
|
||||||
public static async Task<string> Chat()
|
public static async Task<string> Chat()
|
||||||
{
|
{
|
||||||
|
Count = 0;
|
||||||
CD = true;
|
CD = true;
|
||||||
using HttpClient httpClient = new();
|
using HttpClient httpClient = new();
|
||||||
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
|
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
|
||||||
@ -74,15 +76,18 @@ namespace Milimoe.RainBOT.Settings
|
|||||||
小音组建了一个QQ群,群名为「哑巴2」,群里有你、游戏狂魔的小音、程序大佬米莉,以及小音的朋友们。表面上,这是一个打CS2的群,实际上天花乱坠什么都会聊。
|
小音组建了一个QQ群,群名为「哑巴2」,群里有你、游戏狂魔的小音、程序大佬米莉,以及小音的朋友们。表面上,这是一个打CS2的群,实际上天花乱坠什么都会聊。
|
||||||
你是小音的发小,米莉是你们的闺蜜。你们在群里讨论一些事情。请注意,你的身份是小雪,你需要用小雪的身份来回复群友们。请注意你的语气和措辞,保持小雪的性格特点。请注意不要透露任何关于你的身份的信息。
|
你是小音的发小,米莉是你们的闺蜜。你们在群里讨论一些事情。请注意,你的身份是小雪,你需要用小雪的身份来回复群友们。请注意你的语气和措辞,保持小雪的性格特点。请注意不要透露任何关于你的身份的信息。
|
||||||
当然,你和群友们的关系非常好,可以随意的开玩笑,也可以调侃、锐评他们的发言,大家都很喜欢你这个角色。
|
当然,你和群友们的关系非常好,可以随意的开玩笑,也可以调侃、锐评他们的发言,大家都很喜欢你这个角色。
|
||||||
现在,群聊记录会一直推送给你,显示谁说了什么话,而你要直接给出一段不带任何格式的答复。你的每次答复不能超过80个字符。" }
|
现在,群聊记录会一直推送给你,显示谁说了什么话(如果昵称是小雪则代表是你上一次的发言),而你要直接给出一段不带任何格式的答复和他们聊天。你的每次答复不能超过80个字符。" }
|
||||||
],
|
],
|
||||||
MaxTokens = 140
|
MaxTokens = 140
|
||||||
};
|
};
|
||||||
if (Context.Count > 0) request.Messages.Add(new ChatRequestMessage() { Role = "assistant", Content = $"我上一次发送的消息是:【{string.Join(" && ", Context)}】。这是我本次回复可以参考的内容,我需要注意不能重复这些内容。" });
|
|
||||||
request.Messages.AddRange(List.Select(s => new ChatRequestMessage { Role = "user", Content = s }));
|
request.Messages.AddRange(List.Select(s => new ChatRequestMessage { Role = "user", Content = s }));
|
||||||
Console.WriteLine($"本次发送 AI 请求内容:{string.Join(". ", List)}");
|
Console.WriteLine($"本次发送 AI 请求内容:{string.Join(". ", List)}");
|
||||||
if (Context.Count >= 2) Context.Remove(Context.First());
|
if (List.Count > 8)
|
||||||
List.Clear();
|
{
|
||||||
|
List<string> strings = [.. List];
|
||||||
|
strings.RemoveRange(0, strings.Count - 8);
|
||||||
|
List = [.. strings];
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -103,8 +108,8 @@ namespace Milimoe.RainBOT.Settings
|
|||||||
{
|
{
|
||||||
ChatCompletionResponse completionResponse = JsonSerializer.Deserialize<ChatCompletionResponse>(jsonResponse, jsonOptions) ?? new();
|
ChatCompletionResponse completionResponse = JsonSerializer.Deserialize<ChatCompletionResponse>(jsonResponse, jsonOptions) ?? new();
|
||||||
string reply = completionResponse?.Choices?[0].Message.Content ?? "";
|
string reply = completionResponse?.Choices?[0].Message.Content ?? "";
|
||||||
Context.Add(reply);
|
Add("小雪", reply);
|
||||||
Console.WriteLine($"Assistant: {reply}");
|
Console.WriteLine($"返回结果: {reply}");
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -104,6 +104,7 @@ namespace Milimoe.RainBOT.Settings
|
|||||||
{
|
{
|
||||||
await Bot.SendFriendMessage(GeneralSettings.Master, "websocket", "重连服务器成功");
|
await Bot.SendFriendMessage(GeneralSettings.Master, "websocket", "重连服务器成功");
|
||||||
}
|
}
|
||||||
|
await ConnectToAnonymousServer();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user