DSPy: The framework for programming—not prompting—language models
Python
change the way of enable/disable litellm logging (#1777)
Chen Qiand69ec390a406
diff --git a/dsp/utils/settings.py b/dsp/utils/settings.pyindex 1fed72368..009c7b6c9 100644--- a/dsp/utils/settings.py+++ b/dsp/utils/settings.py@@ -1,6 +1,6 @@import threading-from copy import deepcopyfrom contextlib import contextmanager+from copy import deepcopyfrom dsp.utils.utils import dotdict@@ -24,7 +24,6 @@ DEFAULT_CONFIG = dotdict(experimental=False,backoff_time=10,callbacks=[],- suppress_debug_info=True,)diff --git a/dspy/clients/__init__.py b/dspy/clients/__init__.pyindex 9692a9a97..dc10f865f 100644--- a/dspy/clients/__init__.py+++ b/dspy/clients/__init__.py@@ -10,7 +10,15 @@ from litellm.caching import CacheDISK_CACHE_DIR = os.environ.get("DSPY_CACHEDIR") or os.path.join(Path.home(), ".dspy_cache")litellm.cache = Cache(disk_cache_dir=DISK_CACHE_DIR, type="disk")litellm.telemetry = False+# Turn off by default to avoid LiteLLM logging during every LM call.+litellm.suppress_debug_info = Trueif "LITELLM_LOCAL_MODEL_COST_MAP" not in os.environ:- # accessed at run time by litellm; i.e., fine to keep after import+ # Accessed at run time by litellm; i.e., fine to keep after importos.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"++def enable_litellm_logging():+ litellm.suppress_debug_info = False++def disable_litellm_logging():+ litellm.suppress_debug_info = Truediff --git a/dspy/clients/lm.py b/dspy/clients/lm.pyindex ac891841c..4964d7317 100644--- a/dspy/clients/lm.py+++ b/dspy/clients/lm.py@@ -9,7 +9,6 @@ from typing import Any, Dict, List, Literal, Optionalimport litellmimport ujson-import dspyfrom dspy.adapters.base import Adapterfrom dspy.clients.openai import OpenAIProviderfrom dspy.clients.provider import Provider, TrainingJob@@ -70,9 +69,6 @@ class LM(BaseLM):self.num_retries = num_retriesself.finetuning_model = finetuning_model- #turned off by default to avoid LiteLLM logging during every LM call- litellm.suppress_debug_info = dspy.settings.suppress_debug_info-# TODO(bug): Arbitrary model strings could include the substring "o1-".# We should find a more robust way to check for the "o1-" family models.if "o1-" in model: