core[patch]: remove requests (#19891)

Removes required usage of `requests` from `langchain-core`, all of which
has been deprecated.

- removes Tracer V1 implementations
- removes old `try_load_from_hub` github-based hub implementations

Removal done in a way where imports will still succeed, and usage will
fail with a `RuntimeError`.
This commit is contained in:
Erick Friis
2024-04-02 13:28:10 -07:00
committed by GitHub
parent d5a2ff58e9
commit f0d5b59962
13 changed files with 137 additions and 1144 deletions

View File

@@ -1,4 +1,5 @@
"""Functionality for loading agents."""
import json
import logging
from pathlib import Path
@@ -8,7 +9,6 @@ import yaml
from langchain_core._api import deprecated
from langchain_core.language_models import BaseLanguageModel
from langchain_core.tools import Tool
from langchain_core.utils.loading import try_load_from_hub
from langchain.agents.agent import BaseMultiActionAgent, BaseSingleActionAgent
from langchain.agents.types import AGENT_TO_CLASS
@@ -100,13 +100,13 @@ def load_agent(
Returns:
An agent executor.
"""
valid_suffixes = {"json", "yaml"}
if hub_result := try_load_from_hub(
path, _load_agent_from_file, "agents", valid_suffixes
):
return hub_result
else:
return _load_agent_from_file(path, **kwargs)
if isinstance(path, str) and path.startswith("lc://"):
raise RuntimeError(
"Loading from the deprecated github-based Hub is no longer supported. "
"Please use the new LangChain Hub at https://smith.langchain.com/hub "
"instead."
)
return _load_agent_from_file(path, **kwargs)
def _load_agent_from_file(

View File

@@ -1,4 +1,5 @@
"""Functionality for loading chains."""
import json
from pathlib import Path
from typing import Any, Union
@@ -10,7 +11,6 @@ from langchain_core.prompts.loading import (
load_prompt,
load_prompt_from_config,
)
from langchain_core.utils.loading import try_load_from_hub
from langchain.chains import ReduceDocumentsChain
from langchain.chains.api.base import APIChain
@@ -622,12 +622,13 @@ def load_chain_from_config(config: dict, **kwargs: Any) -> Chain:
def load_chain(path: Union[str, Path], **kwargs: Any) -> Chain:
"""Unified method for loading a chain from LangChainHub or local fs."""
if hub_result := try_load_from_hub(
path, _load_chain_from_file, "chains", {"json", "yaml"}, **kwargs
):
return hub_result
else:
return _load_chain_from_file(path, **kwargs)
if isinstance(path, str) and path.startswith("lc://"):
raise RuntimeError(
"Loading from the deprecated github-based Hub is no longer supported. "
"Please use the new LangChain Hub at https://smith.langchain.com/hub "
"instead."
)
return _load_chain_from_file(path, **kwargs)
def _load_chain_from_file(file: Union[str, Path], **kwargs: Any) -> Chain: