修改设备端对接

This commit is contained in:
HycJack
2026-04-16 21:13:06 +08:00
parent a22fcafea9
commit 602f0f7737
19 changed files with 1385 additions and 60 deletions

View File

@@ -24,9 +24,19 @@ class BaseLLM(LLM, BaseService):
async def connect(self):
try:
if self.session:
await self.session.close()
self.session = aiohttp.ClientSession()
if self.session and not self.session.closed:
return
connector = aiohttp.TCPConnector(
limit=20,
limit_per_host=5,
force_close=True,
enable_cleanup_closed=True
)
timeout = aiohttp.ClientTimeout(total=120, connect=30)
self.session = aiohttp.ClientSession(
connector=connector,
timeout=timeout
)
self.connected = True
except Exception as e:
session_logger.error(
@@ -97,8 +107,10 @@ class BaseLLM(LLM, BaseService):
}
try:
if not self.session or self.session.closed:
self.session = aiohttp.ClientSession()
self.connected = True
await self.connect()
if not self.connected:
yield None
return
response = await self.session.post(
f"{self.base_url}/chat/completions", headers=headers, json=data
)