修改设备端对接
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user