From bc9b8c8239ea6df05844d5fbec87eb53e852381b Mon Sep 17 00:00:00 2001 From: Zander Chase <130414180+vowelparrot@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:18:37 -0700 Subject: [PATCH] Improve Error Message for failed callback (#6247) Include the handler class name in the warning --- langchain/callbacks/manager.py | 16 ++++++++++++---- langchain/evaluation/run_evaluators/base.py | 3 +-- .../evaluation/run_evaluators/implementations.py | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/langchain/callbacks/manager.py b/langchain/callbacks/manager.py index c407cc5c..b438550b 100644 --- a/langchain/callbacks/manager.py +++ b/langchain/callbacks/manager.py @@ -200,11 +200,15 @@ def _handle_event( **kwargs, ) else: - logger.warning(f"Error in {event_name} callback: {e}") + logger.warning( + f"Error in {handler.__class__.__name__}.{event_name} callback: {e}" + ) except Exception as e: + logger.warning( + f"Error in {handler.__class__.__name__}.{event_name} callback: {e}" + ) if handler.raise_error: raise e - logger.warning(f"Error in {event_name} callback: {e}") async def _ahandle_event_for_handler( @@ -236,11 +240,15 @@ async def _ahandle_event_for_handler( **kwargs, ) else: - logger.warning(f"Error in {event_name} callback: {e}") + logger.warning( + f"Error in {handler.__class__.__name__}.{event_name} callback: {e}" + ) except Exception as e: + logger.warning( + f"Error in {handler.__class__.__name__}.{event_name} callback: {e}" + ) if handler.raise_error: raise e - logger.warning(f"Error in {event_name} callback: {e}") async def _ahandle_event( diff --git a/langchain/evaluation/run_evaluators/base.py b/langchain/evaluation/run_evaluators/base.py index aa465548..b640719c 100644 --- a/langchain/evaluation/run_evaluators/base.py +++ b/langchain/evaluation/run_evaluators/base.py @@ -11,7 +11,6 @@ from langchain.callbacks.manager import ( CallbackManagerForChainRun, ) from langchain.chains.base import Chain -from langchain.chains.llm import LLMChain from langchain.schema import RUN_KEY, BaseOutputParser @@ -39,7 +38,7 @@ class RunEvaluatorChain(Chain, RunEvaluator): input_mapper: RunEvaluatorInputMapper """Maps the Run and Optional example to a dictionary for the eval chain.""" - eval_chain: LLMChain + eval_chain: Chain """The evaluation chain.""" output_parser: RunEvaluatorOutputParser """Parse the output of the eval chain into feedback.""" diff --git a/langchain/evaluation/run_evaluators/implementations.py b/langchain/evaluation/run_evaluators/implementations.py index a086a23b..6b70d80d 100644 --- a/langchain/evaluation/run_evaluators/implementations.py +++ b/langchain/evaluation/run_evaluators/implementations.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Mapping, Optional, Sequence, Union -from langchainplus_sdk.evaluation.evaluator import EvaluationResult +from langchainplus_sdk.evaluation import EvaluationResult from langchainplus_sdk.schemas import Example, Run from pydantic import BaseModel