mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-03 08:12:39 +00:00
Fix Python 3.11 validation test failures: Remove global logger state and improve error handling
- Remove global _litellm_logger variable that could interfere with exception propagation - Add proper error handling around logger.setLevel() operations - Update tests to reflect removal of global caching - Ensure context manager is fully isolated and doesn't affect validation methods Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -201,16 +201,11 @@ def suppress_warnings():
|
||||
yield
|
||||
|
||||
|
||||
_litellm_logger = None
|
||||
|
||||
@contextmanager
|
||||
def suppress_litellm_output():
|
||||
"""Contextually suppress litellm-related logging output during LLM calls."""
|
||||
global _litellm_logger
|
||||
if _litellm_logger is None:
|
||||
_litellm_logger = logging.getLogger("litellm")
|
||||
|
||||
original_level = _litellm_logger.level
|
||||
litellm_logger = logging.getLogger("litellm")
|
||||
original_level = litellm_logger.level
|
||||
|
||||
warning_patterns = [
|
||||
".*give feedback.*",
|
||||
@@ -224,14 +219,18 @@ def suppress_litellm_output():
|
||||
for pattern in warning_patterns:
|
||||
warnings.filterwarnings("ignore", message=pattern)
|
||||
|
||||
_litellm_logger.setLevel(logging.WARNING)
|
||||
try:
|
||||
litellm_logger.setLevel(logging.WARNING)
|
||||
except Exception as e:
|
||||
logging.debug(f"Error setting logger level: {e}")
|
||||
|
||||
yield
|
||||
except Exception as e:
|
||||
logging.debug(f"Error in litellm output suppression: {e}")
|
||||
raise
|
||||
finally:
|
||||
try:
|
||||
_litellm_logger.setLevel(original_level)
|
||||
litellm_logger.setLevel(original_level)
|
||||
except Exception as e:
|
||||
logging.debug(f"Error restoring logger level: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user