langflow-ai / langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. It’s Python-based and agnostic to any model, API, or database.
http://www.langflow.org
MIT License
34.41k stars 4.14k forks source link

Nearly impossible to make it work behind a proxy #3252

Closed maxpaynebupt closed 1 month ago

maxpaynebupt commented 3 months ago

Bug Description

I am working behind a proxy server. If I disable the proxy setting, when starting up langflow, it will try to fetch some pypi langflow json data, if it fails, it crash. If setup the proxy setting, when I try to use our internal LLM service, it seems langflow can not recognize the NO_PROXY setting, it will try to access the local LLM service via proxy, that will fail for sure. Dilemma.

Reproduction

Windows 11.

  1. If I disable the proxy setting, when starting up langflow, it will try to fetch some pypi langflow json data, if it fails, it crash.
  2. If setup the proxy setting, when I try to use our internal LLM service, it seems langflow can not recognize the NO_PROXY setting, it will try to access the local LLM service via proxy, that will fail for sure. Dilemma.

Expected behavior

Langflow recognize the NO_PROXY settings.

Who can help?

No response

Operating System

Windows 11

Langflow Version

v1.0.14

Python Version

None

Screenshot

No response

Flow File

No response

dosubot[bot] commented 3 months ago

To address the issues you're facing with Langflow behind a proxy on Windows 11, you can take the following steps:

  1. Configure the NO_PROXY Setting: Ensure that the NO_PROXY environment variable is set correctly to bypass the proxy for your internal services. You can set this environment variable in your system or within your application settings.

    Here is how you can set the NO_PROXY environment variable in Python:

    import os
    
    # Set the NO_PROXY environment variable
    os.environ['NO_PROXY'] = 'localhost,127.0.0.1,.yourdomain.com'
    
    # Now you can initialize your settings
    settings = Settings()

    In the context of Langflow, you can add this configuration in the base.py file where the settings are initialized. Ensure that this environment variable is set before any network operations are performed [1].

  2. Bypass PyPI Data Fetching: To prevent Langflow from fetching PyPI data during startup, you can use the --no-store parameter in the CLI options or set the LANGFLOW_STORE environment variable to False.

    langflow run --no-store

    Or set the environment variable:

    export LANGFLOW_STORE=False

    This will disable the store features and prevent Langflow from attempting to fetch PyPI data during startup [2].

By following these steps, you should be able to configure Langflow to properly recognize the NO_PROXY setting and avoid issues with accessing internal services and fetching PyPI data behind a proxy.

To continue talking to Dosu, mention @dosu.

maxpaynebupt commented 3 months ago

To address the issues you're facing with Langflow behind a proxy on Windows 11, you can take the following steps:

  1. Configure the NO_PROXY Setting: Ensure that the NO_PROXY environment variable is set correctly to bypass the proxy for your internal services. You can set this environment variable in your system or within your application settings. Here is how you can set the NO_PROXY environment variable in Python:

    import os
    
    # Set the NO_PROXY environment variable
    os.environ['NO_PROXY'] = 'localhost,127.0.0.1,.yourdomain.com'
    
    # Now you can initialize your settings
    settings = Settings()

    In the context of Langflow, you can add this configuration in the base.py file where the settings are initialized. Ensure that this environment variable is set before any network operations are performed [1].

  2. Bypass PyPI Data Fetching: To prevent Langflow from fetching PyPI data during startup, you can use the --no-store parameter in the CLI options or set the LANGFLOW_STORE environment variable to False.

    langflow run --no-store

    Or set the environment variable:

    export LANGFLOW_STORE=False

    This will disable the store features and prevent Langflow from attempting to fetch PyPI data during startup [2].

By following these steps, you should be able to configure Langflow to properly recognize the NO_PROXY setting and avoid issues with accessing internal services and fetching PyPI data behind a proxy.

To continue talking to Dosu, mention @dosu.

tried with --no-store it still try to fetch https://pypi.org/pypi/langflow/json

dosubot[bot] commented 3 months ago

To ensure Langflow properly recognizes the NO_PROXY setting and avoids fetching PyPI data during startup, you can modify the relevant functions to respect the NO_PROXY environment variable. Here are the steps:

  1. Set the NO_PROXY Environment Variable: Ensure that the NO_PROXY environment variable is set correctly in your environment. This can be done in your system settings or within your application code.

    import os
    os.environ['NO_PROXY'] = 'localhost,127.0.0.1,.yourdomain.com'
  2. Modify Functions to Respect NO_PROXY: Update the functions that fetch PyPI data to respect the NO_PROXY setting. For example, you can modify the fetch_latest_version function to use the httpx library with proxy settings:

    import httpx
    import os
    
    def fetch_latest_version(package_name: str, include_prerelease: bool) -> Optional[str]:
       proxies = {
           "all://": None  # Disable proxy for all protocols
       }
       if "NO_PROXY" in os.environ:
           no_proxy = os.environ["NO_PROXY"]
           proxies = {
               "all://": None,
               "no_proxy": no_proxy
           }
    
       response = httpx.get(f"https://pypi.org/pypi/{package_name}/json", proxies=proxies)
       versions = response.json()["releases"].keys()
       valid_versions = [v for v in versions if include_prerelease or not is_prerelease(v)]
       if not valid_versions:
           return None  # Handle case where no valid versions are found
       return max(valid_versions, key=lambda v: pkg_version.parse(v))
  3. Ensure NO_PROXY is Set During Startup: Make sure the NO_PROXY environment variable is set before any network operations are performed. You can add this configuration in the set_var_for_macos_issue function or similar initialization code:

    def set_var_for_macos_issue():
       if platform.system() in ["Darwin"]:
           import os
           os.environ["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
           os.environ["no_proxy"] = "*"  # to avoid error with gunicorn
           logger.debug("Set OBJC_DISABLE_INITIALIZE_FORK_SAFETY to YES to avoid error")

By following these steps, you should be able to configure Langflow to properly recognize the NO_PROXY setting and avoid fetching PyPI data during startup [1][2][3].

To continue talking to Dosu, mention @dosu.

nicoloboschi commented 2 months ago

@maxpaynebupt Could you elaborate more on your deployment architecture (bare metal, k8s, pypi package, docker, single container...)?

it will try to fetch some pypi langflow json data what does it mean?

maxpaynebupt commented 2 months ago

@maxpaynebupt Could you elaborate more on your deployment architecture (bare metal, k8s, pypi package, docker, single container...)?

it will try to fetch some pypi langflow json data what does it mean?

just pypi package installed on windows 11