Last work before refactor

This commit is contained in:
Samuele Lorefice
2024-12-26 17:26:29 +01:00
parent 0fe19ce04f
commit 000b32c41d
4 changed files with 46 additions and 7 deletions

View File

@@ -1,7 +1,6 @@
using OpenAI;
using OpenAI.Chat;
using System.ClientModel;
using System.Collections;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
@@ -21,19 +20,18 @@ Console.WriteLine(
""");
string nemesisPrompt = File.ReadAllText($"prompt/{GetEnv("NEMESIS_PROMPT_FILE")}");
string krolikPrompt = File.ReadAllText($"prompt/{GetEnv("KROLIK_PROMPT_FILE")}");
Dictionary<long, List<ChatMessage>> oaiChats = new();
//Ratelimit
TimeSpan rateLimit = new(0, 0, 0, 30);
Dictionary<long, DateTime> lastMessage = new();
HashSet<long> unlimitedChats = new();
bool IsRateLimited(long chatId) {
if (lastMessage.ContainsKey(chatId)) {
if (DateTime.Now - lastMessage[chatId] < rateLimit) {
return true;
}
}
if (lastMessage.ContainsKey(chatId) && DateTime.Now - lastMessage[chatId] < rateLimit) return true;
lastMessage[chatId] = DateTime.Now;
return false;
}
@@ -41,7 +39,7 @@ bool IsRateLimited(long chatId) {
var options = new OpenAIClientOptions() {
Endpoint = new(baseUrl),
NetworkTimeout = new TimeSpan(0, 0, 30)
NetworkTimeout = new TimeSpan(0, 0, 15)
};
var openAiApiKey = new ApiKeyCredential(apiKey);