diff --git a/src/NadekoBot/Modules/Games/ChatterBot/_common/OfficialGptSession.cs b/src/NadekoBot/Modules/Games/ChatterBot/_common/OfficialGptSession.cs index 7a65e52b8..d0d15b439 100644 --- a/src/NadekoBot/Modules/Games/ChatterBot/_common/OfficialGptSession.cs +++ b/src/NadekoBot/Modules/Games/ChatterBot/_common/OfficialGptSession.cs @@ -3,10 +3,12 @@ using Newtonsoft.Json; using OneOf.Types; using System.Net.Http.Json; using SharpToken; +using System.CodeDom; +using System.Text.RegularExpressions; namespace NadekoBot.Modules.Games.Common.ChatterBot; -public class OfficialGptSession : IChatterBotSession +public partial class OfficialGptSession : IChatterBotSession { private string Uri => $"https://api.openai.com/v1/chat/completions"; @@ -55,14 +57,21 @@ public class OfficialGptSession : IChatterBotSession }); } + + [GeneratedRegex("[^a-zA-Z0-9_-]")] + private static partial Regex UsernameCleaner(); + public async Task>> Think(string input, string username) { + username = UsernameCleaner().Replace(username, ""); + messages.Add(new() { Role = "user", Content = input, Name = username }); + while (messages.Count > _maxHistory + 2) { messages.RemoveAt(1);