Spaces:
Running
Running
Disable logs from a bunch of Python libs
Browse files- helpers/llm_helper.py +39 -2
helpers/llm_helper.py
CHANGED
|
@@ -7,8 +7,37 @@ import sys
|
|
| 7 |
import urllib3
|
| 8 |
from typing import Tuple, Union, Iterator, Optional
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
sys.path.append('..')
|
| 14 |
|
|
@@ -17,6 +46,14 @@ from global_config import GlobalConfig
|
|
| 17 |
try:
|
| 18 |
import litellm
|
| 19 |
from litellm import completion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
except ImportError:
|
| 21 |
litellm = None
|
| 22 |
completion = None
|
|
|
|
| 7 |
import urllib3
|
| 8 |
from typing import Tuple, Union, Iterator, Optional
|
| 9 |
|
| 10 |
+
# Centralized logging configuration (early):
|
| 11 |
+
# - Ensure noisy third-party loggers (httpx, httpcore, urllib3, LiteLLM, etc.) are set to WARNING
|
| 12 |
+
# - Disable propagation so they don't bubble up to the root logger
|
| 13 |
+
# - Capture warnings from the warnings module into logging
|
| 14 |
+
# The suppression must run before the noisy library is imported/initialised!
|
| 15 |
+
LOGGERS_TO_SUPPRESS = [
|
| 16 |
+
'asyncio',
|
| 17 |
+
'httpx',
|
| 18 |
+
'httpcore',
|
| 19 |
+
'langfuse',
|
| 20 |
+
'LiteLLM',
|
| 21 |
+
'litellm',
|
| 22 |
+
'openai',
|
| 23 |
+
'urllib3',
|
| 24 |
+
'urllib3.connectionpool',
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
# Basic config at module import time; use WARNING to avoid DEBUG noise
|
| 28 |
+
logging.basicConfig(
|
| 29 |
+
level=logging.WARNING,
|
| 30 |
+
format='%(asctime)s - %(levelname)s - %(name)s - %(message)s'
|
| 31 |
+
)
|
| 32 |
+
for _lg in LOGGERS_TO_SUPPRESS:
|
| 33 |
+
logger_obj = logging.getLogger(_lg)
|
| 34 |
+
logger_obj.setLevel(logging.WARNING)
|
| 35 |
+
# Prevent these logs from propagating to the root logger
|
| 36 |
+
logger_obj.propagate = False
|
| 37 |
+
|
| 38 |
+
# Capture warnings from the warnings module (optional, helps centralize output)
|
| 39 |
+
if hasattr(logging, 'captureWarnings'):
|
| 40 |
+
logging.captureWarnings(True)
|
| 41 |
|
| 42 |
sys.path.append('..')
|
| 43 |
|
|
|
|
| 46 |
try:
|
| 47 |
import litellm
|
| 48 |
from litellm import completion
|
| 49 |
+
|
| 50 |
+
# Ask LiteLLM to suppress debug information if possible
|
| 51 |
+
try:
|
| 52 |
+
litellm.suppress_debug_info = True
|
| 53 |
+
except Exception:
|
| 54 |
+
# Ignore if attribute is unavailable
|
| 55 |
+
pass
|
| 56 |
+
|
| 57 |
except ImportError:
|
| 58 |
litellm = None
|
| 59 |
completion = None
|