Dmitry Beresnev
commited on
Commit
·
e98f030
1
Parent(s):
f9f20cc
add a new openrouter api key, limit the total count of articles
Browse files
src/services/news_pooling_service.py
CHANGED
|
@@ -264,6 +264,9 @@ class NewsPollingService:
|
|
| 264 |
|
| 265 |
if unique_articles:
|
| 266 |
unique_articles.sort(key=lambda x: x.get('datetime', 0))
|
|
|
|
|
|
|
|
|
|
| 267 |
await self.save_articles_to_hf(unique_articles)
|
| 268 |
# Notify in batches
|
| 269 |
for batch in self._chunked(unique_articles, self._article_batch_size):
|
|
|
|
| 264 |
|
| 265 |
if unique_articles:
|
| 266 |
unique_articles.sort(key=lambda x: x.get('datetime', 0))
|
| 267 |
+
if len(unique_articles) > 20:
|
| 268 |
+
logger.warning(f"Too many new articles ({len(unique_articles)}), limiting to 5")
|
| 269 |
+
unique_articles = unique_articles[:5]
|
| 270 |
await self.save_articles_to_hf(unique_articles)
|
| 271 |
# Notify in batches
|
| 272 |
for batch in self._chunked(unique_articles, self._article_batch_size):
|
src/telegram_bot/config.py
CHANGED
|
@@ -14,6 +14,7 @@ class Config:
|
|
| 14 |
OPENROUTER_API_KEY = os.getenv('OPENROUTER_API_TOKEN', '')
|
| 15 |
HF_TOKEN = os.getenv('HF_TOKEN', '')
|
| 16 |
HF_DATASET_REPO = os.getenv('HF_DATASET_REPO', '')
|
|
|
|
| 17 |
|
| 18 |
@classmethod
|
| 19 |
def validate(cls) -> bool:
|
|
|
|
| 14 |
OPENROUTER_API_KEY = os.getenv('OPENROUTER_API_TOKEN', '')
|
| 15 |
HF_TOKEN = os.getenv('HF_TOKEN', '')
|
| 16 |
HF_DATASET_REPO = os.getenv('HF_DATASET_REPO', '')
|
| 17 |
+
OPENROUTER_API_KEY_2 = os.getenv('OPENROUTER_API_TOKEN_2', '')
|
| 18 |
|
| 19 |
@classmethod
|
| 20 |
def validate(cls) -> bool:
|
src/telegram_bot/telegram_bot_service.py
CHANGED
|
@@ -256,7 +256,7 @@ class TelegramBotService:
|
|
| 256 |
Returns:
|
| 257 |
Analysis result as a string.
|
| 258 |
"""
|
| 259 |
-
client = OpenRouterClient(api_key=Config.
|
| 260 |
for news in news_list:
|
| 261 |
start_time = time.perf_counter()
|
| 262 |
prompt = PromptGenerator.format_prompt(news)
|
|
|
|
| 256 |
Returns:
|
| 257 |
Analysis result as a string.
|
| 258 |
"""
|
| 259 |
+
client = OpenRouterClient(api_key=Config.OPENROUTER_API_KEY_2)
|
| 260 |
for news in news_list:
|
| 261 |
start_time = time.perf_counter()
|
| 262 |
prompt = PromptGenerator.format_prompt(news)
|