BUG: more core fixes (#13665)

Fix some circular deps:
- move PromptValue into top level module bc both PromptTemplates and
OutputParsers import
- move tracer context vars to `tracers.context` and import them in
functions in `callbacks.manager`
- add core import tests
This commit is contained in:
Bagatur
2023-11-21 15:15:48 -08:00
committed by GitHub
parent 59df16ab92
commit c61e30632e
99 changed files with 1000 additions and 576 deletions

View File

@@ -0,0 +1,15 @@
from langchain_core.tracers import __all__
EXPECTED_ALL = [
"BaseTracer",
"EvaluatorCallbackHandler",
"LangChainTracer",
"ConsoleCallbackHandler",
"Run",
"RunLog",
"RunLogPatch",
]
def test_all_imports() -> None:
assert set(__all__) == set(EXPECTED_ALL)

View File

@@ -0,0 +1,16 @@
"""Test the run collector."""
import uuid
from langchain_core.tracers.context import collect_runs
from tests.unit_tests.fake.llm import FakeListLLM
def test_collect_runs() -> None:
llm = FakeListLLM(responses=["hello"])
with collect_runs() as cb:
llm.predict("hi")
assert cb.traced_runs
assert len(cb.traced_runs) == 1
assert isinstance(cb.traced_runs[0].id, uuid.UUID)
assert cb.traced_runs[0].inputs == {"prompts": ["hi"]}