Skip to content

Commit

Permalink
Remove GetLocal, PutLocal (#12133)
Browse files Browse the repository at this point in the history
Do you agree?
  • Loading branch information
nfcampos authored Oct 24, 2023
1 parent 8c150ad commit 34ffb94
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 290 deletions.
3 changes: 0 additions & 3 deletions libs/langchain/langchain/schema/runnable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
This module contains schema and implementation of LangChain Runnables primitives.
"""
from langchain.schema.runnable._locals import GetLocalVar, PutLocalVar
from langchain.schema.runnable.base import (
Runnable,
RunnableBinding,
Expand All @@ -40,9 +39,7 @@
"ConfigurableField",
"ConfigurableFieldSingleOption",
"ConfigurableFieldMultiOption",
"GetLocalVar",
"patch_config",
"PutLocalVar",
"RouterInput",
"RouterRunnable",
"Runnable",
Expand Down
168 changes: 0 additions & 168 deletions libs/langchain/langchain/schema/runnable/_locals.py

This file was deleted.

11 changes: 2 additions & 9 deletions libs/langchain/langchain/schema/runnable/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,6 @@ def invoke(
# mark each step as a child run
patch_config(
config,
copy_locals=True,
callbacks=run_manager.get_child(f"map:key:{key}"),
),
)
Expand Down Expand Up @@ -2534,10 +2533,7 @@ def batch(
[merge_configs(self.config, conf) for conf in config],
)
else:
configs = [
patch_config(merge_configs(self.config, config), copy_locals=True)
for _ in range(len(inputs))
]
configs = [merge_configs(self.config, config) for _ in range(len(inputs))]
return self.bound.batch(
inputs,
configs,
Expand All @@ -2559,10 +2555,7 @@ async def abatch(
[merge_configs(self.config, conf) for conf in config],
)
else:
configs = [
patch_config(merge_configs(self.config, config), copy_locals=True)
for _ in range(len(inputs))
]
configs = [merge_configs(self.config, config) for _ in range(len(inputs))]
return await self.bound.abatch(
inputs,
configs,
Expand Down
13 changes: 1 addition & 12 deletions libs/langchain/langchain/schema/runnable/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ class RunnableConfig(TypedDict, total=False):
Name for the tracer run for this call. Defaults to the name of the class.
"""

locals: Dict[str, Any]
"""
Variables scoped to this call and any sub-calls. Usually used with
GetLocalVar() and PutLocalVar(). Care should be taken when placing mutable
objects in locals, as they will be shared between parallel sub-calls.
"""

max_concurrency: Optional[int]
"""
Maximum number of parallel calls to make. If not provided, defaults to
Expand All @@ -96,7 +89,6 @@ def ensure_config(config: Optional[RunnableConfig] = None) -> RunnableConfig:
tags=[],
metadata={},
callbacks=None,
locals={},
recursion_limit=25,
)
if config is not None:
Expand Down Expand Up @@ -124,23 +116,20 @@ def get_config_list(
return (
list(map(ensure_config, config))
if isinstance(config, list)
else [patch_config(config, copy_locals=True) for _ in range(length)]
else [ensure_config(config) for _ in range(length)]
)


def patch_config(
config: Optional[RunnableConfig],
*,
copy_locals: bool = False,
callbacks: Optional[BaseCallbackManager] = None,
recursion_limit: Optional[int] = None,
max_concurrency: Optional[int] = None,
run_name: Optional[str] = None,
configurable: Optional[Dict[str, Any]] = None,
) -> RunnableConfig:
config = ensure_config(config)
if copy_locals:
config["locals"] = config["locals"].copy()
if callbacks is not None:
# If we're replacing callbacks we need to unset run_name
# As that should apply only to the same run as the original callbacks
Expand Down
94 changes: 0 additions & 94 deletions libs/langchain/tests/unit_tests/schema/runnable/test_locals.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,6 @@ async def test_with_config(mocker: MockerFixture) -> None:
metadata={"key": "value"},
tags=["c"],
callbacks=None,
locals={},
recursion_limit=5,
),
),
Expand All @@ -1219,7 +1218,6 @@ async def test_with_config(mocker: MockerFixture) -> None:
metadata={"key": "value"},
tags=["c"],
callbacks=None,
locals={},
recursion_limit=5,
),
),
Expand Down Expand Up @@ -1290,7 +1288,6 @@ async def test_default_method_implementations(mocker: MockerFixture) -> None:
metadata={"key": "value"},
tags=[],
callbacks=None,
locals={},
recursion_limit=25,
),
),
Expand All @@ -1300,7 +1297,6 @@ async def test_default_method_implementations(mocker: MockerFixture) -> None:
metadata={"key": "value"},
tags=[],
callbacks=None,
locals={},
recursion_limit=25,
),
),
Expand Down

0 comments on commit 34ffb94

Please sign in to comment.