mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-05 12:48:12 +00:00
fix: call _on_llm_error() (#13581)
Description: There's a copy-paste typo where on_llm_error() calls _on_chain_error() instead of _on_llm_error(). Issue: #13580 Dependencies: None Tag maintainer: @hwchase17 Twitter handle: @jwatte "Run `make format`, `make lint` and `make test` to check this locally." The test scripts don't work in a plain Ubuntu LTS 20.04 system. It looks like the dev container pulling is stuck. Or maybe the internet is just ornery today. --------- Co-authored-by: jwatte <jwatte@observeinc.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
parent
fcc8e5e839
commit
e042e5df35
@ -224,7 +224,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
|
|||||||
llm_run.end_time = datetime.utcnow()
|
llm_run.end_time = datetime.utcnow()
|
||||||
llm_run.events.append({"name": "error", "time": llm_run.end_time})
|
llm_run.events.append({"name": "error", "time": llm_run.end_time})
|
||||||
self._end_trace(llm_run)
|
self._end_trace(llm_run)
|
||||||
self._on_chain_error(llm_run)
|
self._on_llm_error(llm_run)
|
||||||
return llm_run
|
return llm_run
|
||||||
|
|
||||||
def on_chain_start(
|
def on_chain_start(
|
||||||
|
@ -332,6 +332,42 @@ def test_tracer_llm_run_on_error() -> None:
|
|||||||
assert tracer.runs == [compare_run]
|
assert tracer.runs == [compare_run]
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time("2023-01-01")
|
||||||
|
def test_tracer_llm_run_on_error_callback() -> None:
|
||||||
|
"""Test tracer on an LLM run with an error and a callback."""
|
||||||
|
exception = Exception("test")
|
||||||
|
uuid = uuid4()
|
||||||
|
|
||||||
|
compare_run = Run(
|
||||||
|
id=str(uuid),
|
||||||
|
start_time=datetime.utcnow(),
|
||||||
|
end_time=datetime.utcnow(),
|
||||||
|
events=[
|
||||||
|
{"name": "start", "time": datetime.utcnow()},
|
||||||
|
{"name": "error", "time": datetime.utcnow()},
|
||||||
|
],
|
||||||
|
extra={},
|
||||||
|
execution_order=1,
|
||||||
|
child_execution_order=1,
|
||||||
|
serialized=SERIALIZED,
|
||||||
|
inputs=dict(prompts=[]),
|
||||||
|
outputs=None,
|
||||||
|
error=repr(exception),
|
||||||
|
run_type="llm",
|
||||||
|
)
|
||||||
|
|
||||||
|
class FakeTracerWithLlmErrorCallback(FakeTracer):
|
||||||
|
error_run = None
|
||||||
|
|
||||||
|
def _on_llm_error(self, run: Run) -> None:
|
||||||
|
self.error_run = run
|
||||||
|
|
||||||
|
tracer = FakeTracerWithLlmErrorCallback()
|
||||||
|
tracer.on_llm_start(serialized=SERIALIZED, prompts=[], run_id=uuid)
|
||||||
|
tracer.on_llm_error(exception, run_id=uuid)
|
||||||
|
assert tracer.error_run == compare_run
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2023-01-01")
|
@freeze_time("2023-01-01")
|
||||||
def test_tracer_chain_run_on_error() -> None:
|
def test_tracer_chain_run_on_error() -> None:
|
||||||
"""Test tracer on a Chain run with an error."""
|
"""Test tracer on a Chain run with an error."""
|
||||||
|
Loading…
Reference in New Issue
Block a user