mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-14 07:07:34 +00:00
Merge 606e63fee3
into 30e3ed6a19
This commit is contained in:
commit
542c93cd5d
@ -120,11 +120,11 @@ def __getattr__(name: str) -> Any:
|
|||||||
"""Get attr name."""
|
"""Get attr name."""
|
||||||
if name in DEPRECATED_CODE:
|
if name in DEPRECATED_CODE:
|
||||||
# Get directory of langchain package
|
# Get directory of langchain package
|
||||||
HERE = Path(__file__).parents[1]
|
here = Path(__file__).parents[1]
|
||||||
relative_path = as_import_path(
|
relative_path = as_import_path(
|
||||||
Path(__file__).parent,
|
Path(__file__).parent,
|
||||||
suffix=name,
|
suffix=name,
|
||||||
relative_to=HERE,
|
relative_to=here,
|
||||||
)
|
)
|
||||||
old_path = "langchain." + relative_path
|
old_path = "langchain." + relative_path
|
||||||
new_path = "langchain_experimental." + relative_path
|
new_path = "langchain_experimental." + relative_path
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
from pathlib import Path
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api.path import as_import_path
|
|
||||||
|
|
||||||
|
|
||||||
def __getattr__(name: str) -> Any:
|
def __getattr__(name: str) -> Any:
|
||||||
"""Get attr name."""
|
"""Get attr name."""
|
||||||
|
|
||||||
if name == "create_csv_agent":
|
if name == "create_csv_agent":
|
||||||
# Get directory of langchain package
|
|
||||||
HERE = Path(__file__).parents[3]
|
|
||||||
here = as_import_path(Path(__file__).parent, relative_to=HERE)
|
|
||||||
|
|
||||||
old_path = "langchain." + here + "." + name
|
|
||||||
new_path = "langchain_experimental." + here + "." + name
|
|
||||||
msg = (
|
msg = (
|
||||||
"This agent has been moved to langchain experiment. "
|
"This agent has been moved to langchain experiment. "
|
||||||
"This agent relies on python REPL tool under the hood, so to use it "
|
"This agent relies on python REPL tool under the hood, so to use it "
|
||||||
@ -21,7 +12,9 @@ def __getattr__(name: str) -> Any:
|
|||||||
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
||||||
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
||||||
"To keep using this code as is, install langchain experimental and "
|
"To keep using this code as is, install langchain experimental and "
|
||||||
f"update your import statement from:\n `{old_path}` to `{new_path}`."
|
"update your import statement from:\n "
|
||||||
|
f"`langchain.agents.agent_toolkits.csv.{name}` to "
|
||||||
|
f"`langchain_experimental.agents.agent_toolkits.{name}`."
|
||||||
)
|
)
|
||||||
raise ImportError(msg)
|
raise ImportError(msg)
|
||||||
msg = f"{name} does not exist"
|
msg = f"{name} does not exist"
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
from pathlib import Path
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api.path import as_import_path
|
|
||||||
|
|
||||||
|
|
||||||
def __getattr__(name: str) -> Any:
|
def __getattr__(name: str) -> Any:
|
||||||
"""Get attr name."""
|
"""Get attr name."""
|
||||||
|
|
||||||
if name == "create_pandas_dataframe_agent":
|
if name == "create_pandas_dataframe_agent":
|
||||||
# Get directory of langchain package
|
|
||||||
HERE = Path(__file__).parents[3]
|
|
||||||
here = as_import_path(Path(__file__).parent, relative_to=HERE)
|
|
||||||
|
|
||||||
old_path = "langchain." + here + "." + name
|
|
||||||
new_path = "langchain_experimental." + here + "." + name
|
|
||||||
msg = (
|
msg = (
|
||||||
"This agent has been moved to langchain experiment. "
|
"This agent has been moved to langchain experiment. "
|
||||||
"This agent relies on python REPL tool under the hood, so to use it "
|
"This agent relies on python REPL tool under the hood, so to use it "
|
||||||
@ -21,7 +12,9 @@ def __getattr__(name: str) -> Any:
|
|||||||
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
||||||
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
||||||
"To keep using this code as is, install langchain experimental and "
|
"To keep using this code as is, install langchain experimental and "
|
||||||
f"update your import statement from:\n `{old_path}` to `{new_path}`."
|
"update your import statement from:\n"
|
||||||
|
f"`langchain.agents.agent_toolkits.pandas.{name}` to "
|
||||||
|
f"`langchain_experimental.agents.agent_toolkits.{name}`."
|
||||||
)
|
)
|
||||||
raise ImportError(msg)
|
raise ImportError(msg)
|
||||||
msg = f"{name} does not exist"
|
msg = f"{name} does not exist"
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
from pathlib import Path
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api.path import as_import_path
|
|
||||||
|
|
||||||
|
|
||||||
def __getattr__(name: str) -> Any:
|
def __getattr__(name: str) -> Any:
|
||||||
"""Get attr name."""
|
"""Get attr name."""
|
||||||
|
|
||||||
if name == "create_python_agent":
|
if name == "create_python_agent":
|
||||||
# Get directory of langchain package
|
|
||||||
HERE = Path(__file__).parents[3]
|
|
||||||
here = as_import_path(Path(__file__).parent, relative_to=HERE)
|
|
||||||
|
|
||||||
old_path = "langchain." + here + "." + name
|
|
||||||
new_path = "langchain_experimental." + here + "." + name
|
|
||||||
msg = (
|
msg = (
|
||||||
"This agent has been moved to langchain experiment. "
|
"This agent has been moved to langchain experiment. "
|
||||||
"This agent relies on python REPL tool under the hood, so to use it "
|
"This agent relies on python REPL tool under the hood, so to use it "
|
||||||
@ -21,7 +12,9 @@ def __getattr__(name: str) -> Any:
|
|||||||
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
||||||
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
||||||
"To keep using this code as is, install langchain experimental and "
|
"To keep using this code as is, install langchain experimental and "
|
||||||
f"update your import statement from:\n `{old_path}` to `{new_path}`."
|
"update your import statement from:\n"
|
||||||
|
f"`langchain.agents.agent_toolkits.python.{name}` to "
|
||||||
|
f"`langchain_experimental.agents.agent_toolkits.{name}`."
|
||||||
)
|
)
|
||||||
raise ImportError(msg)
|
raise ImportError(msg)
|
||||||
msg = f"{name} does not exist"
|
msg = f"{name} does not exist"
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
from pathlib import Path
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api.path import as_import_path
|
|
||||||
|
|
||||||
|
|
||||||
def __getattr__(name: str) -> Any:
|
def __getattr__(name: str) -> Any:
|
||||||
"""Get attr name."""
|
"""Get attr name."""
|
||||||
|
|
||||||
if name == "create_spark_dataframe_agent":
|
if name == "create_spark_dataframe_agent":
|
||||||
# Get directory of langchain package
|
|
||||||
HERE = Path(__file__).parents[3]
|
|
||||||
here = as_import_path(Path(__file__).parent, relative_to=HERE)
|
|
||||||
|
|
||||||
old_path = "langchain." + here + "." + name
|
|
||||||
new_path = "langchain_experimental." + here + "." + name
|
|
||||||
msg = (
|
msg = (
|
||||||
"This agent has been moved to langchain experiment. "
|
"This agent has been moved to langchain experiment. "
|
||||||
"This agent relies on python REPL tool under the hood, so to use it "
|
"This agent relies on python REPL tool under the hood, so to use it "
|
||||||
@ -21,7 +12,9 @@ def __getattr__(name: str) -> Any:
|
|||||||
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
||||||
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
||||||
"To keep using this code as is, install langchain experimental and "
|
"To keep using this code as is, install langchain experimental and "
|
||||||
f"update your import statement from:\n `{old_path}` to `{new_path}`."
|
"update your import statement from:\n"
|
||||||
|
f"`langchain.agents.agent_toolkits.spark.{name}` to "
|
||||||
|
f"`langchain_experimental.agents.agent_toolkits.{name}`."
|
||||||
)
|
)
|
||||||
raise ImportError(msg)
|
raise ImportError(msg)
|
||||||
msg = f"{name} does not exist"
|
msg = f"{name} does not exist"
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
from pathlib import Path
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api.path import as_import_path
|
|
||||||
|
|
||||||
|
|
||||||
def __getattr__(name: str) -> Any:
|
def __getattr__(name: str) -> Any:
|
||||||
"""Get attr name."""
|
"""Get attr name."""
|
||||||
|
|
||||||
if name == "create_xorbits_agent":
|
if name == "create_xorbits_agent":
|
||||||
# Get directory of langchain package
|
|
||||||
HERE = Path(__file__).parents[3]
|
|
||||||
here = as_import_path(Path(__file__).parent, relative_to=HERE)
|
|
||||||
|
|
||||||
old_path = "langchain." + here + "." + name
|
|
||||||
new_path = "langchain_experimental." + here + "." + name
|
|
||||||
msg = (
|
msg = (
|
||||||
"This agent has been moved to langchain experiment. "
|
"This agent has been moved to langchain experiment. "
|
||||||
"This agent relies on python REPL tool under the hood, so to use it "
|
"This agent relies on python REPL tool under the hood, so to use it "
|
||||||
@ -21,7 +12,9 @@ def __getattr__(name: str) -> Any:
|
|||||||
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
||||||
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
||||||
"To keep using this code as is, install langchain experimental and "
|
"To keep using this code as is, install langchain experimental and "
|
||||||
f"update your import statement from:\n `{old_path}` to `{new_path}`."
|
"update your import statement from:\n"
|
||||||
|
f"`langchain.agents.agent_toolkits.xorbits.{name}` to "
|
||||||
|
f"`langchain_experimental.agents.agent_toolkits.{name}`."
|
||||||
)
|
)
|
||||||
raise ImportError(msg)
|
raise ImportError(msg)
|
||||||
msg = f"{name} does not exist"
|
msg = f"{name} does not exist"
|
||||||
|
@ -9,7 +9,7 @@ if TYPE_CHECKING:
|
|||||||
from streamlit.delta_generator import DeltaGenerator
|
from streamlit.delta_generator import DeltaGenerator
|
||||||
|
|
||||||
|
|
||||||
def StreamlitCallbackHandler(
|
def StreamlitCallbackHandler( # noqa: N802
|
||||||
parent_container: DeltaGenerator,
|
parent_container: DeltaGenerator,
|
||||||
*,
|
*,
|
||||||
max_thought_containers: int = 4,
|
max_thought_containers: int = 4,
|
||||||
|
@ -79,7 +79,7 @@ class LLMChain(Chain):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@override
|
@override
|
||||||
def is_lc_serializable(self) -> bool:
|
def is_lc_serializable(cls) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
prompt: BasePromptTemplate
|
prompt: BasePromptTemplate
|
||||||
|
@ -651,6 +651,7 @@ class _ConfigurableModel(Runnable[LanguageModelInput, Any]):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@override
|
||||||
def InputType(self) -> TypeAlias:
|
def InputType(self) -> TypeAlias:
|
||||||
"""Get the input type for this runnable."""
|
"""Get the input type for this runnable."""
|
||||||
from langchain_core.prompt_values import (
|
from langchain_core.prompt_values import (
|
||||||
|
@ -97,7 +97,7 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor:
|
|||||||
Pinecone as CommunityPinecone,
|
Pinecone as CommunityPinecone,
|
||||||
)
|
)
|
||||||
|
|
||||||
BUILTIN_TRANSLATORS: dict[type[VectorStore], type[Visitor]] = {
|
builtin_translators: dict[type[VectorStore], type[Visitor]] = {
|
||||||
AstraDB: AstraDBTranslator,
|
AstraDB: AstraDBTranslator,
|
||||||
PGVector: PGVectorTranslator,
|
PGVector: PGVectorTranslator,
|
||||||
CommunityPinecone: PineconeTranslator,
|
CommunityPinecone: PineconeTranslator,
|
||||||
@ -128,8 +128,8 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor:
|
|||||||
field.name for field in (vectorstore.meta_fields or []) if field.index
|
field.name for field in (vectorstore.meta_fields or []) if field.index
|
||||||
]
|
]
|
||||||
return TencentVectorDBTranslator(fields)
|
return TencentVectorDBTranslator(fields)
|
||||||
if vectorstore.__class__ in BUILTIN_TRANSLATORS:
|
if vectorstore.__class__ in builtin_translators:
|
||||||
return BUILTIN_TRANSLATORS[vectorstore.__class__]()
|
return builtin_translators[vectorstore.__class__]()
|
||||||
try:
|
try:
|
||||||
from langchain_astradb.vectorstores import AstraDBVectorStore
|
from langchain_astradb.vectorstores import AstraDBVectorStore
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -154,7 +154,7 @@ class TestResult(dict):
|
|||||||
class EvalError(dict):
|
class EvalError(dict):
|
||||||
"""Your architecture raised an error."""
|
"""Your architecture raised an error."""
|
||||||
|
|
||||||
def __init__(self, Error: BaseException, **kwargs: Any) -> None:
|
def __init__(self, Error: BaseException, **kwargs: Any) -> None: # noqa: N803
|
||||||
"""Initialize the EvalError with an error and additional attributes.
|
"""Initialize the EvalError with an error and additional attributes.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -38,7 +38,7 @@ from langchain._api.interactive_env import is_interactive_env
|
|||||||
_DEPRECATED_TOOLS = {"PythonAstREPLTool", "PythonREPLTool"}
|
_DEPRECATED_TOOLS = {"PythonAstREPLTool", "PythonREPLTool"}
|
||||||
|
|
||||||
|
|
||||||
def _import_python_tool_PythonAstREPLTool() -> Any:
|
def _import_python_tool_python_ast_repl_tool() -> Any:
|
||||||
msg = (
|
msg = (
|
||||||
"This tool has been moved to langchain experiment. "
|
"This tool has been moved to langchain experiment. "
|
||||||
"This tool has access to a python REPL. "
|
"This tool has access to a python REPL. "
|
||||||
@ -50,7 +50,7 @@ def _import_python_tool_PythonAstREPLTool() -> Any:
|
|||||||
raise ImportError(msg)
|
raise ImportError(msg)
|
||||||
|
|
||||||
|
|
||||||
def _import_python_tool_PythonREPLTool() -> Any:
|
def _import_python_tool_python_repl_tool() -> Any:
|
||||||
msg = (
|
msg = (
|
||||||
"This tool has been moved to langchain experiment. "
|
"This tool has been moved to langchain experiment. "
|
||||||
"This tool has access to a python REPL. "
|
"This tool has access to a python REPL. "
|
||||||
@ -64,9 +64,9 @@ def _import_python_tool_PythonREPLTool() -> Any:
|
|||||||
|
|
||||||
def __getattr__(name: str) -> Any:
|
def __getattr__(name: str) -> Any:
|
||||||
if name == "PythonAstREPLTool":
|
if name == "PythonAstREPLTool":
|
||||||
return _import_python_tool_PythonAstREPLTool()
|
return _import_python_tool_python_ast_repl_tool()
|
||||||
if name == "PythonREPLTool":
|
if name == "PythonREPLTool":
|
||||||
return _import_python_tool_PythonREPLTool()
|
return _import_python_tool_python_repl_tool()
|
||||||
from langchain_community import tools
|
from langchain_community import tools
|
||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
|
@ -163,6 +163,7 @@ select = [
|
|||||||
"ICN", # flake8-import-conventions
|
"ICN", # flake8-import-conventions
|
||||||
"INT", # flake8-gettext
|
"INT", # flake8-gettext
|
||||||
"ISC", # isort-comprehensions
|
"ISC", # isort-comprehensions
|
||||||
|
"N", # pep8-naming
|
||||||
"PERF", # flake8-perf
|
"PERF", # flake8-perf
|
||||||
"PGH", # pygrep-hooks
|
"PGH", # pygrep-hooks
|
||||||
"PIE", # flake8-pie
|
"PIE", # flake8-pie
|
||||||
@ -207,6 +208,7 @@ ignore = [
|
|||||||
]
|
]
|
||||||
unfixable = ["B028"] # People should intentionally tune the stacklevel
|
unfixable = ["B028"] # People should intentionally tune the stacklevel
|
||||||
|
|
||||||
|
pep8-naming.classmethod-decorators = [ "classmethod", "langchain_core.utils.pre_init", "pydantic.field_validator", "pydantic.v1.root_validator",]
|
||||||
pydocstyle.convention = "google"
|
pydocstyle.convention = "google"
|
||||||
pyupgrade.keep-runtime-typing = true
|
pyupgrade.keep-runtime-typing = true
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ from pydantic import BaseModel
|
|||||||
from langchain.chat_models import init_chat_model
|
from langchain.chat_models import init_chat_model
|
||||||
|
|
||||||
|
|
||||||
class multiply(BaseModel):
|
class Multiply(BaseModel):
|
||||||
"""Product of two ints."""
|
"""Product of two ints."""
|
||||||
|
|
||||||
x: int
|
x: int
|
||||||
@ -21,7 +21,7 @@ class multiply(BaseModel):
|
|||||||
@pytest.mark.requires("langchain_openai", "langchain_anthropic")
|
@pytest.mark.requires("langchain_openai", "langchain_anthropic")
|
||||||
async def test_init_chat_model_chain() -> None:
|
async def test_init_chat_model_chain() -> None:
|
||||||
model = init_chat_model("gpt-4o", configurable_fields="any", config_prefix="bar")
|
model = init_chat_model("gpt-4o", configurable_fields="any", config_prefix="bar")
|
||||||
model_with_tools = model.bind_tools([multiply])
|
model_with_tools = model.bind_tools([Multiply])
|
||||||
|
|
||||||
model_with_config = model_with_tools.with_config(
|
model_with_config = model_with_tools.with_config(
|
||||||
RunnableConfig(tags=["foo"]),
|
RunnableConfig(tags=["foo"]),
|
||||||
|
@ -203,8 +203,10 @@ def test_simple_sequential_functionality() -> None:
|
|||||||
assert output == expected_output
|
assert output == expected_output
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("isAsync", [False, True])
|
@pytest.mark.parametrize("is_async", [False, True])
|
||||||
async def test_simple_sequential_functionality_with_callbacks(*, isAsync: bool) -> None:
|
async def test_simple_sequential_functionality_with_callbacks(
|
||||||
|
*, is_async: bool
|
||||||
|
) -> None:
|
||||||
"""Test simple sequential functionality."""
|
"""Test simple sequential functionality."""
|
||||||
handler_1 = FakeCallbackHandler()
|
handler_1 = FakeCallbackHandler()
|
||||||
handler_2 = FakeCallbackHandler()
|
handler_2 = FakeCallbackHandler()
|
||||||
@ -225,7 +227,7 @@ async def test_simple_sequential_functionality_with_callbacks(*, isAsync: bool)
|
|||||||
callbacks=[handler_3],
|
callbacks=[handler_3],
|
||||||
)
|
)
|
||||||
chain = SimpleSequentialChain(chains=[chain_1, chain_2, chain_3])
|
chain = SimpleSequentialChain(chains=[chain_1, chain_2, chain_3])
|
||||||
if isAsync:
|
if is_async:
|
||||||
output = await chain.ainvoke({"input": "123"})
|
output = await chain.ainvoke({"input": "123"})
|
||||||
else:
|
else:
|
||||||
output = chain({"input": "123"})
|
output = chain({"input": "123"})
|
||||||
|
@ -27,7 +27,7 @@ def test_resolve_criteria_list_enum() -> None:
|
|||||||
assert set(val.keys()) == {c.value for c in list(Criteria)}
|
assert set(val.keys()) == {c.value for c in list(Criteria)}
|
||||||
|
|
||||||
|
|
||||||
def test_PairwiseStringResultOutputParser_parse() -> None:
|
def test_pairwise_string_result_output_parser_parse() -> None:
|
||||||
output_parser = PairwiseStringResultOutputParser()
|
output_parser = PairwiseStringResultOutputParser()
|
||||||
text = """I like pie better than cake.
|
text = """I like pie better than cake.
|
||||||
[[A]]"""
|
[[A]]"""
|
||||||
|
@ -51,7 +51,7 @@ The criterion is: "Do you like cake?" I like cake.""", # noqa: E501
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_CriteriaResultOutputParser_parse(text: str, want: dict) -> None:
|
def test_criteria_result_output_parser_parse(text: str, want: dict) -> None:
|
||||||
output_parser = CriteriaResultOutputParser()
|
output_parser = CriteriaResultOutputParser()
|
||||||
got = output_parser.parse(text)
|
got = output_parser.parse(text)
|
||||||
assert got.get("reasoning") == want["reasoning"]
|
assert got.get("reasoning") == want["reasoning"]
|
||||||
|
@ -12,7 +12,7 @@ from langchain.evaluation.scoring.eval_chain import (
|
|||||||
from tests.unit_tests.llms.fake_llm import FakeLLM
|
from tests.unit_tests.llms.fake_llm import FakeLLM
|
||||||
|
|
||||||
|
|
||||||
def test_PairwiseStringResultOutputParser_parse() -> None:
|
def test_pairwise_string_result_output_parser_parse() -> None:
|
||||||
output_parser = ScoreStringResultOutputParser()
|
output_parser = ScoreStringResultOutputParser()
|
||||||
text = """This answer is really good.
|
text = """This answer is really good.
|
||||||
Rating: [[10]]"""
|
Rating: [[10]]"""
|
||||||
|
Loading…
Reference in New Issue
Block a user