Задействован механизм повторов неудавшегося запроса к ИИ.

This commit is contained in:
Kirill Kirilenko 2026-01-01 01:56:33 +03:00
parent 24ce709fb1
commit 324cbe16a6

View file

@ -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,