mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
fix: bot should now trim the invalid characters from openai message usernames
This commit is contained in:
@@ -3,10 +3,12 @@ using Newtonsoft.Json;
|
|||||||
using OneOf.Types;
|
using OneOf.Types;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using SharpToken;
|
using SharpToken;
|
||||||
|
using System.CodeDom;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Games.Common.ChatterBot;
|
namespace NadekoBot.Modules.Games.Common.ChatterBot;
|
||||||
|
|
||||||
public class OfficialGptSession : IChatterBotSession
|
public partial class OfficialGptSession : IChatterBotSession
|
||||||
{
|
{
|
||||||
private string Uri
|
private string Uri
|
||||||
=> $"https://api.openai.com/v1/chat/completions";
|
=> $"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<OneOf.OneOf<ThinkResult, Error<string>>> Think(string input, string username)
|
public async Task<OneOf.OneOf<ThinkResult, Error<string>>> Think(string input, string username)
|
||||||
{
|
{
|
||||||
|
username = UsernameCleaner().Replace(username, "");
|
||||||
|
|
||||||
messages.Add(new()
|
messages.Add(new()
|
||||||
{
|
{
|
||||||
Role = "user",
|
Role = "user",
|
||||||
Content = input,
|
Content = input,
|
||||||
Name = username
|
Name = username
|
||||||
});
|
});
|
||||||
|
|
||||||
while (messages.Count > _maxHistory + 2)
|
while (messages.Count > _maxHistory + 2)
|
||||||
{
|
{
|
||||||
messages.RemoveAt(1);
|
messages.RemoveAt(1);
|
||||||
|
Reference in New Issue
Block a user