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:
Jon Watte 2023-12-04 19:44:50 -08:00 committed by GitHub
parent fcc8e5e839
commit e042e5df35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -224,7 +224,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
llm_run.end_time = datetime.utcnow()
llm_run.events.append({"name": "error", "time": llm_run.end_time})
self._end_trace(llm_run)
self._on_chain_error(llm_run)
self._on_llm_error(llm_run)
return llm_run
def on_chain_start(

View File

@ -332,6 +332,42 @@ def test_tracer_llm_run_on_error() -> None:
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")
def test_tracer_chain_run_on_error() -> None:
"""Test tracer on a Chain run with an error."""