community: Fix closed session in Infinity (#26933)

**Description:** 

The `aiohttp.ClientSession` is closed at the end of the with statement,
which causes an error during a second call.

The implemented fix is to define the session directly within the with
block, exactly like in the textembed code:


c6350d636e/libs/community/langchain_community/embeddings/textembed.py (L335-L346)
 
**Issue:** Fix #26932

Co-authored-by: ccurme <chester.curme@gmail.com>
This commit is contained in:
Baptiste Pasquier 2024-10-27 16:37:21 +01:00 committed by GitHub
parent 8895d468cb
commit 440c162b8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -306,11 +306,9 @@ class TinyAsyncOpenAIInfinityEmbeddingClient: #: :meta private:
perm_texts_batched = self._batch(perm_texts)
# Request
if self.aiosession is None:
self.aiosession = aiohttp.ClientSession(
trust_env=True, connector=aiohttp.TCPConnector(limit=32)
)
async with self.aiosession as session:
async with aiohttp.ClientSession(
trust_env=True, connector=aiohttp.TCPConnector(limit=32)
) as session:
embeddings_batch_perm = await asyncio.gather(
*[
self._async_request(