fix: issue (bug_risk): Reusing ClientSession across retries may lead to closed session issues.

pull/72/head
KawaiiYusora 2025-03-07 01:37:17 +08:00
parent 1becc5d2d9
commit a463f3a1a4
1 changed files with 1 additions and 3 deletions

View File

@ -74,14 +74,12 @@ class LLM_request:
elif payload is None:
payload = await self._build_payload(prompt)
session_method = aiohttp.ClientSession()
for retry in range(policy["max_retries"]):
try:
# 使用上下文管理器处理会话
headers = await self._build_headers()
async with session_method as session:
async with aiohttp.ClientSession() as session:
async with session.post(api_url, headers=headers, json=payload) as response:
# 处理需要重试的状态码
if response.status in policy["retry_codes"]: