Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: Fix GenericRequestsWrapper _aget_resp_content must be async #18065

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions libs/community/langchain_community/utilities/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ def _get_resp_content(self, response: Response) -> Union[str, Dict[str, Any]]:
else:
raise ValueError(f"Invalid return type: {self.response_content_type}")

def _aget_resp_content(
async def _aget_resp_content(
self, response: aiohttp.ClientResponse
) -> Union[str, Dict[str, Any]]:
if self.response_content_type == "text":
return response.text() # type: ignore[return-value]
return await response.text()
elif self.response_content_type == "json":
return response.json() # type: ignore[return-value]
return await response.json()
else:
raise ValueError(f"Invalid return type: {self.response_content_type}")

Expand Down Expand Up @@ -176,33 +176,33 @@ def delete(self, url: str, **kwargs: Any) -> Union[str, Dict[str, Any]]:
async def aget(self, url: str, **kwargs: Any) -> Union[str, Dict[str, Any]]:
"""GET the URL and return the text asynchronously."""
async with self.requests.aget(url, **kwargs) as response:
return await self._aget_resp_content(response) # type: ignore[misc]
return await self._aget_resp_content(response)

async def apost(
self, url: str, data: Dict[str, Any], **kwargs: Any
) -> Union[str, Dict[str, Any]]:
"""POST to the URL and return the text asynchronously."""
async with self.requests.apost(url, data, **kwargs) as response:
return await self._aget_resp_content(response) # type: ignore[misc]
return await self._aget_resp_content(response)

async def apatch(
self, url: str, data: Dict[str, Any], **kwargs: Any
) -> Union[str, Dict[str, Any]]:
"""PATCH the URL and return the text asynchronously."""
async with self.requests.apatch(url, data, **kwargs) as response:
return await self._aget_resp_content(response) # type: ignore[misc]
return await self._aget_resp_content(response)

async def aput(
self, url: str, data: Dict[str, Any], **kwargs: Any
) -> Union[str, Dict[str, Any]]:
"""PUT the URL and return the text asynchronously."""
async with self.requests.aput(url, data, **kwargs) as response:
return await self._aget_resp_content(response) # type: ignore[misc]
return await self._aget_resp_content(response)

async def adelete(self, url: str, **kwargs: Any) -> Union[str, Dict[str, Any]]:
"""DELETE the URL and return the text asynchronously."""
async with self.requests.adelete(url, **kwargs) as response:
return await self._aget_resp_content(response) # type: ignore[misc]
return await self._aget_resp_content(response)


class JsonRequestsWrapper(GenericRequestsWrapper):
Expand Down