Open zix3r opened 3 weeks ago
You could create an in-memory cache that lasts for a while. Using an API, if you want it to remember, you have to resend previous messages so it has context. You could do something like this:
private readonly GroqClient groqClient;
private readonly IMemoryCache _memoryCache;
private async Task ProcesingIA(Message message)
{
var cacheKey = $"messages_{message.Chat.Username}";
if (!_memoryCache.TryGetValue(cacheKey, out ICollection<MessageGroq>? messages))
{
var timeMemory = 20;
messages = [new MessageGroq {
Role = MessageRoleType.System,
Content = "your-prompt"
}];
_memoryCache.Set(cacheKey, messages, TimeSpan.FromMinutes(timeMemory));
}
messages?.Add(new MessageGroq { Role = MessageRoleType.User, Content = message.Text! });
var response = await groqClient.CreateChatCompletionAsync([.. messages!]);
}
is it possible to implement some sort of memory/history for the chat so that the bot remembers what was said? cuz currently i have something like this:
but when another prompt is sent, it doesn't remember anything from the last one