Skip to content

Commit df1f030

Browse files
committed
fix(cli): silence LiteLLM 'could not pre-load' warnings at import time
LiteLLM unconditionally tries to pre-load AWS Bedrock / SageMaker response stream shapes during 'import litellm'. When 'botocore' isn't installed it logs two WARNING lines per invocation — but botocore is optional and OpenAI / Anthropic / Gemini users have no reason to install it. Result was that every 'openkb' call printed two unhelpful warnings above the actual output, including for terminal/agent consumers parsing the first line of 'openkb status' to get the KB path. Attach a 'logging.Filter' to the 'LiteLLM' logger BEFORE litellm imports, dropping any record whose message contains 'could not pre-load'. Real LiteLLM warnings still come through.
1 parent cc52ee5 commit df1f030

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

openkb/cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
os.environ.setdefault("LITELLM_LOCAL_MODEL_COST_MAP", "True")
2424

2525
import click
26+
27+
# Silence LiteLLM's "could not pre-load <aws-service> response stream
28+
# shape" warnings — they fire at import time when ``botocore`` isn't
29+
# installed, but botocore is only needed for AWS Bedrock / SageMaker
30+
# users. Filter must be attached before ``import litellm`` runs.
31+
class _SuppressLiteLLMPreloadWarnings(logging.Filter):
32+
def filter(self, record: logging.LogRecord) -> bool:
33+
return "could not pre-load" not in record.getMessage()
34+
35+
36+
logging.getLogger("LiteLLM").addFilter(_SuppressLiteLLMPreloadWarnings())
37+
2638
import litellm
2739
litellm.suppress_debug_info = True
2840
from dotenv import load_dotenv

0 commit comments

Comments
 (0)