From 324cbe16a6271d90e64f41e3eeef0de5e29b4df1 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Thu, 1 Jan 2026 01:56:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B5=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=BC=D0=B5=D1=85=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B7=D0=BC=20=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=BD=D0=B5=D1=83=D0=B4=D0=B0=D0=B2=D1=88=D0=B5=D0=B3?= =?UTF-8?q?=D0=BE=D1=81=D1=8F=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0?= =?UTF-8?q?=20=D0=BA=20=D0=98=D0=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai_agent.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ai_agent.py b/ai_agent.py index 242461f..e5e0f95 100644 --- a/ai_agent.py +++ b/ai_agent.py @@ -1,8 +1,8 @@ from dataclasses import dataclass from typing import List, Dict, Optional -from openrouter import OpenRouter - +from openrouter import OpenRouter, RetryConfig +from openrouter.utils import BackoffStrategy SYSTEM_PROMPT = """ Ты - помощник в групповом чате. @@ -39,7 +39,11 @@ class AiMessage: class AiAgent: def __init__(self, api_token: str): - self.client = OpenRouter(api_key=api_token, timeout_ms=15000) + retry_config = RetryConfig(strategy="backoff", + backoff=BackoffStrategy( + initial_interval=2000, max_interval=8000, exponent=2, max_elapsed_time=14000), + retry_connection_errors=True) + self.client = OpenRouter(api_key=api_token, retry_config=retry_config) self.chat_contexts: Dict[int, ChatContext] = {} async def get_reply(self, chat_id: int, chat_prompt: str,