add memory
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 16s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 16s
This commit is contained in:
@@ -103,7 +103,10 @@ public class BotService
|
||||
return;
|
||||
|
||||
var botId = _client.CurrentUser.Id;
|
||||
var botName = _client.CurrentUser.Username;
|
||||
var hasMention = message.MentionedUsers.Any(u => u.Id == botId);
|
||||
var hasTextMention = message.Content.TrimStart()
|
||||
.StartsWith($"@{botName}", StringComparison.OrdinalIgnoreCase);
|
||||
var isReplyToBot = false;
|
||||
|
||||
if (message.Reference?.MessageId.IsSpecified == true)
|
||||
@@ -121,10 +124,16 @@ public class BotService
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasMention && !isReplyToBot)
|
||||
if (!hasMention && !isReplyToBot && !hasTextMention)
|
||||
return;
|
||||
|
||||
var prompt = hasMention ? RemoveBotMentions(message.Content, botId) : message.Content.Trim();
|
||||
string prompt;
|
||||
if (hasMention)
|
||||
prompt = RemoveBotMentions(message.Content, botId);
|
||||
else if (hasTextMention)
|
||||
prompt = RemoveBotName(message.Content, botName);
|
||||
else
|
||||
prompt = message.Content.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(prompt))
|
||||
{
|
||||
@@ -136,7 +145,7 @@ public class BotService
|
||||
{
|
||||
var accumulated = string.Empty;
|
||||
|
||||
await foreach (var text in _llmService.SendMessageAsync(message.Channel.Id, message.Author.Username, prompt))
|
||||
await foreach (var text in _llmService.SendMessageAsync(message.Channel.Id, message.Author.Id, message.Author.Username, prompt))
|
||||
{
|
||||
accumulated = text;
|
||||
}
|
||||
@@ -190,6 +199,17 @@ public class BotService
|
||||
.Trim();
|
||||
}
|
||||
|
||||
private static string RemoveBotName(string content, string botName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(content))
|
||||
return string.Empty;
|
||||
|
||||
return System.Text.RegularExpressions.Regex.Replace(
|
||||
content,
|
||||
$@"^\s*@{System.Text.RegularExpressions.Regex.Escape(botName)}\s*",
|
||||
"", System.Text.RegularExpressions.RegexOptions.IgnoreCase).Trim();
|
||||
}
|
||||
|
||||
private static Task LogAsync(LogMessage message)
|
||||
{
|
||||
Console.WriteLine($"[{message.Severity}] {message.Source}: {message.Message}");
|
||||
|
||||
Reference in New Issue
Block a user