Skip to content

Commit

Permalink
fix async client init for aiohttp 3.10+
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme committed Sep 12, 2024
1 parent 6b0c3d9 commit 2382e6b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions libs/partners/pinecone/langchain_pinecone/embeddings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import logging
from typing import Any, Dict, Iterable, List, Optional

Expand Down Expand Up @@ -85,6 +86,15 @@ def set_default_config(cls, values: dict) -> Any:
values[key] = value
return values

async def _init_async_client(self, api_key: str) -> None:
self._async_client = aiohttp.ClientSession(
headers={
"Api-Key": api_key,
"Content-Type": "application/json",
"X-Pinecone-API-Version": "2024-07",
}
)

@model_validator(mode="after")
def validate_environment(self) -> Self:
"""Validate that Pinecone version and credentials exist in environment."""
Expand All @@ -94,13 +104,8 @@ def validate_environment(self) -> Self:

# initialize async client
if not self._async_client:
self._async_client = aiohttp.ClientSession(
headers={
"Api-Key": api_key_str,
"Content-Type": "application/json",
"X-Pinecone-API-Version": "2024-07",
}
)
asyncio.run(self._init_async_client(api_key_str))

return self

def _get_batch_iterator(self, texts: List[str]) -> Iterable:
Expand Down

0 comments on commit 2382e6b

Please sign in to comment.