diff --git a/dsp/utils/settings.py b/dsp/utils/settings.py index e973f4705..00f01eeaf 100644 --- a/dsp/utils/settings.py +++ b/dsp/utils/settings.py @@ -1,9 +1,8 @@ -import copy import threading - from contextlib import contextmanager +from copy import deepcopy + from dsp.utils.utils import dotdict -from functools import lru_cache DEFAULT_CONFIG = dotdict( lm=None, @@ -28,12 +27,6 @@ async_max_workers=8, ) -@lru_cache(maxsize=None) -def warn_once(msg: str): - import logging - logger = logging.getLogger(__name__) - logger.warning(msg) - class Settings: """DSP configuration settings.""" @@ -56,21 +49,18 @@ def __new__(cls): # TODO: remove first-class support for re-ranker and potentially combine with RM to form a pipeline of sorts # eg: RetrieveThenRerankPipeline(RetrievalModel, Reranker) # downstream operations like dsp.retrieve would use configs from the defined pipeline. - config = copy.deepcopy(DEFAULT_CONFIG) - cls._instance.__append(config) + + # make a deepcopy of the default config to avoid modifying the default config + cls._instance.__append(deepcopy(DEFAULT_CONFIG)) return cls._instance @property def config(self): thread_id = threading.get_ident() - # if thread_id not in self.stack_by_thread: - # self.stack_by_thread[thread_id] = [self.main_stack[-1].copy()] - try: - return self.stack_by_thread[thread_id][-1] - except Exception: - warn_once("Warning: You seem to be creating DSPy threads in an unsupported way.") - return self.main_stack[-1] + if thread_id not in self.stack_by_thread: + self.stack_by_thread[thread_id] = [self.main_stack[-1].copy()] + return self.stack_by_thread[thread_id][-1] def __getattr__(self, name): if hasattr(self.config, name): @@ -83,16 +73,14 @@ def __getattr__(self, name): def __append(self, config): thread_id = threading.get_ident() - # if thread_id not in self.stack_by_thread: - # self.stack_by_thread[thread_id] = [self.main_stack[-1].copy()] - - assert thread_id in self.stack_by_thread, "Error: You seem to be creating DSPy threads in an unsupported way." + if thread_id not in self.stack_by_thread: + self.stack_by_thread[thread_id] = [self.main_stack[-1].copy()] self.stack_by_thread[thread_id].append(config) def __pop(self): thread_id = threading.get_ident() - # if thread_id in self.stack_by_thread: - self.stack_by_thread[thread_id].pop() + if thread_id in self.stack_by_thread: + self.stack_by_thread[thread_id].pop() def configure(self, inherit_config: bool = True, **kwargs): """Set configuration settings. @@ -120,4 +108,4 @@ def __repr__(self) -> str: return repr(self.config) -settings = Settings() +settings = Settings() \ No newline at end of file