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

deprecated imports while running langflow #2070

Closed
mindful-time opened this issue Jun 5, 2024 · 2 comments
Closed

deprecated imports while running langflow #2070

mindful-time opened this issue Jun 5, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@mindful-time
Copy link

Getting the following deprecated imports issue in the langflow installation :

.pyenv\pyenv-win\versions\3.11.3\Lib\site-packages\langchain_api\module_import.py:120: LangChainDeprecationWarning: Importing RequestsWrapper from langchain is deprecated. Please replace deprecated imports:

from langchain import RequestsWrapper

with new imports of:

from langchain_community.utilities import RequestsWrapper

warn_deprecated(

@dosubot dosubot bot added the documentation Improvements or additions to documentation label Jun 5, 2024
Copy link

dosubot bot commented Jun 5, 2024

To resolve the deprecated import warning related to RequestsWrapper in Langflow, you need to update your import statements. Replace the deprecated import with the new one from langchain_community.utilities. Here is how you can update your code:

Replace:

from langchain import RequestsWrapper

With:

from langchain_community.utilities.requests import TextRequestsWrapper

Here is an example of how you can update your code to use TextRequestsWrapper:

from typing import Optional
from langchain_community.utilities.requests import TextRequestsWrapper
from langchain_core.documents import Document
from langflow import CustomComponent
from langflow.services.database.models.base import orjson_dumps

class GetRequest(CustomComponent):
    display_name: str = "GET Request"
    description: str = "Make a GET request to the given URL."
    output_types: list[str] = ["Document"]
    documentation: str = "https://docs.langflow.org/components/utilities#get-request"
    beta: bool = True
    field_config = {
        "url": {
            "display_name": "URL",
            "info": "The URL to make the request to",
            "is_list": True,
        },
        "headers": {
            "display_name": "Headers",
            "info": "The headers to send with the request.",
        },
        "code": {"show": False},
        "timeout": {
            "display_name": "Timeout",
            "field_type": "int",
            "info": "The timeout to use for the request.",
            "value": 5,
        },
    }

    def get_document(self, wrapper: TextRequestsWrapper, url: str, headers: Optional[dict], timeout: int) -> Document:
        try:
            response = wrapper.get(url, headers=headers, timeout=int(timeout))
            try:
                response_json = response.json()
                result = orjson_dumps(response_json, indent_2=False)
            except Exception:
                result = response.text
            self.repr_value = result
            return Document(
                page_content=result,
                metadata={
                    "source": url,
                    "headers": headers,
                    "status_code": response.status_code,
                },
            )
        except requests.Timeout:
            return Document(
                page_content="Request Timed Out",
                metadata={"source": url, "headers": headers, "status_code": 408},
            )
        except Exception as exc:
            return Document(
                page_content=str(exc),
                metadata={"source": url, "headers": headers, "status_code": 500},
            )

    def build(
        self,
        url: str,
        headers: Optional[dict] = None,
        timeout: int = 5,
    ) -> list[Document]:
        if headers is None:
            headers = {}
        urls = url if isinstance(url, list) else [url]
        wrapper = TextRequestsWrapper()
        documents = [self.get_document(wrapper, u, headers, timeout) for u in urls]
        self.repr_value = documents
        return documents

This update should resolve the deprecated import warning related to RequestsWrapper [1].

To continue talking to Dosu, mention @dosu.

@nicoloboschi
Copy link
Collaborator

Most of them have been resolved with the latest langchain upgrade. If any other deprecations appear, please open a new ticket with the specific lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants