|
|
|
@ -7,7 +7,7 @@ from freezegun import freeze_time
|
|
|
|
|
from pytest_mock import MockerFixture
|
|
|
|
|
from syrupy import SnapshotAssertion
|
|
|
|
|
|
|
|
|
|
from langchain.callbacks.manager import Callbacks
|
|
|
|
|
from langchain.callbacks.manager import Callbacks, collect_runs
|
|
|
|
|
from langchain.callbacks.tracers.base import BaseTracer
|
|
|
|
|
from langchain.callbacks.tracers.schemas import Run
|
|
|
|
|
from langchain.callbacks.tracers.stdout import ConsoleCallbackHandler
|
|
|
|
@ -1271,6 +1271,31 @@ def test_with_config_with_config() -> None:
|
|
|
|
|
) == dumpd(llm.with_config({"metadata": {"a": "b"}, "tags": ["a-tag"]}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_metadata_is_merged() -> None:
|
|
|
|
|
"""Test metadata and tags defined in with_config and at are merged/concatend."""
|
|
|
|
|
|
|
|
|
|
foo = RunnableLambda(lambda x: x).with_config({"metadata": {"my_key": "my_value"}})
|
|
|
|
|
expected_metadata = {
|
|
|
|
|
"my_key": "my_value",
|
|
|
|
|
"my_other_key": "my_other_value",
|
|
|
|
|
}
|
|
|
|
|
with collect_runs() as cb:
|
|
|
|
|
foo.invoke("hi", {"metadata": {"my_other_key": "my_other_value"}})
|
|
|
|
|
run = cb.traced_runs[0]
|
|
|
|
|
assert run.extra["metadata"] == expected_metadata
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_tags_are_appended() -> None:
|
|
|
|
|
"""Test tags from with_config are concatenated with those in invocation."""
|
|
|
|
|
|
|
|
|
|
foo = RunnableLambda(lambda x: x).with_config({"tags": ["my_key"]})
|
|
|
|
|
with collect_runs() as cb:
|
|
|
|
|
foo.invoke("hi", {"tags": ["invoked_key"]})
|
|
|
|
|
run = cb.traced_runs[0]
|
|
|
|
|
assert isinstance(run.tags, list)
|
|
|
|
|
assert sorted(run.tags) == sorted(["my_key", "invoked_key"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_bind_bind() -> None:
|
|
|
|
|
llm = FakeListLLM(responses=["i'm a textbot"])
|
|
|
|
|
|
|
|
|
|