Adds history command
This commit is contained in:
@@ -92,17 +92,7 @@ async Task OnKroMessage(Message msg, UpdateType type) {
|
|||||||
//TODO: currently we only take in account private messages and messages directed to the bot/mentioning them.
|
//TODO: currently we only take in account private messages and messages directed to the bot/mentioning them.
|
||||||
// We should also take in account the last x messages in groups to add more context
|
// We should also take in account the last x messages in groups to add more context
|
||||||
async Task OnMessage(Message msg, Agent agent) {
|
async Task OnMessage(Message msg, Agent agent) {
|
||||||
//Check if the message contains the bot's username or a reply to a message sent by the bot or a private chat
|
|
||||||
|
|
||||||
var chatid = msg.Chat.Id;
|
var chatid = msg.Chat.Id;
|
||||||
var tokenlenght = oaiAgent.GetTokenLenght(msg.Text);
|
|
||||||
Console.WriteLine(
|
|
||||||
$"""
|
|
||||||
{agent.Name} has received message from {chatid} TokenLenght: {tokenlenght}
|
|
||||||
Message: {msg.Text}
|
|
||||||
""");
|
|
||||||
//Add the message to the chat history
|
|
||||||
oaiAgent.ChatHistoryAppend(Actor.User, chatid, "User: " + msg.Text);
|
|
||||||
|
|
||||||
//Check if the message is a reset command
|
//Check if the message is a reset command
|
||||||
if (msg.Text == "/reset" || msg.Text == "/reset@" + agent.Username) {
|
if (msg.Text == "/reset" || msg.Text == "/reset@" + agent.Username) {
|
||||||
@@ -111,6 +101,26 @@ async Task OnMessage(Message msg, Agent agent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (msg.Text == "/history @"+agent.Username) {
|
||||||
|
|
||||||
|
var history = oaiAgent.GetChatHistory(chatid, agent.Actor);
|
||||||
|
var historyText = string.Join("\n", history.Select(x => x.Item1.Content[0].Text));
|
||||||
|
await agent.Bot.SendMessage(chatid, historyText);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = $"{msg.From?.FirstName} {msg.From?.LastName}: {msg.Text}";
|
||||||
|
var tokenlenght = oaiAgent.GetTokenLenght(msg.Text!);
|
||||||
|
Console.WriteLine(
|
||||||
|
$"""
|
||||||
|
{agent.Name} has received message from {chatid} TokenLenght: {tokenlenght}
|
||||||
|
Message: {msg.Text}
|
||||||
|
""");
|
||||||
|
//Add the message to the chat history
|
||||||
|
oaiAgent.ChatHistoryAppend(Actor.User, chatid, text);
|
||||||
|
|
||||||
|
|
||||||
|
//Check if the message contains the bot's username or a reply to a message sent by the bot or a private chat
|
||||||
// Otherwise process it normally
|
// Otherwise process it normally
|
||||||
if (msg.Text!.Contains(agent.Name, StringComparison.OrdinalIgnoreCase) ||
|
if (msg.Text!.Contains(agent.Name, StringComparison.OrdinalIgnoreCase) ||
|
||||||
msg.ReplyToMessage?.From?.Id == agent.TelegramId ||
|
msg.ReplyToMessage?.From?.Id == agent.TelegramId ||
|
||||||
@@ -125,7 +135,6 @@ async Task OnMessage(Message msg, Agent agent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async Task AnswerChat(long chatId, Agent agent) {
|
async Task AnswerChat(long chatId, Agent agent) {
|
||||||
//Get the response from the OpenAI API
|
//Get the response from the OpenAI API
|
||||||
var result = oaiAgent.GetChatResponse(chatId, agent);
|
var result = oaiAgent.GetChatResponse(chatId, agent);
|
||||||
|
|||||||
Reference in New Issue
Block a user