Skip to content

Commit 9a70c7c

Browse files
committed
Revert settings.py
1 parent e336971 commit 9a70c7c

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

dsp/utils/settings.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import copy
21
import threading
3-
42
from contextlib import contextmanager
3+
from copy import deepcopy
4+
55
from dsp.utils.utils import dotdict
6-
from functools import lru_cache
76

87
DEFAULT_CONFIG = dotdict(
98
lm=None,
@@ -28,12 +27,6 @@
2827
async_max_workers=8,
2928
)
3029

31-
@lru_cache(maxsize=None)
32-
def warn_once(msg: str):
33-
import logging
34-
logger = logging.getLogger(__name__)
35-
logger.warning(msg)
36-
3730

3831
class Settings:
3932
"""DSP configuration settings."""
@@ -56,21 +49,18 @@ def __new__(cls):
5649
# TODO: remove first-class support for re-ranker and potentially combine with RM to form a pipeline of sorts
5750
# eg: RetrieveThenRerankPipeline(RetrievalModel, Reranker)
5851
# downstream operations like dsp.retrieve would use configs from the defined pipeline.
59-
config = copy.deepcopy(DEFAULT_CONFIG)
60-
cls._instance.__append(config)
52+
53+
# make a deepcopy of the default config to avoid modifying the default config
54+
cls._instance.__append(deepcopy(DEFAULT_CONFIG))
6155

6256
return cls._instance
6357

6458
@property
6559
def config(self):
6660
thread_id = threading.get_ident()
67-
# if thread_id not in self.stack_by_thread:
68-
# self.stack_by_thread[thread_id] = [self.main_stack[-1].copy()]
69-
try:
70-
return self.stack_by_thread[thread_id][-1]
71-
except Exception:
72-
warn_once("Warning: You seem to be creating DSPy threads in an unsupported way.")
73-
return self.main_stack[-1]
61+
if thread_id not in self.stack_by_thread:
62+
self.stack_by_thread[thread_id] = [self.main_stack[-1].copy()]
63+
return self.stack_by_thread[thread_id][-1]
7464

7565
def __getattr__(self, name):
7666
if hasattr(self.config, name):
@@ -83,16 +73,14 @@ def __getattr__(self, name):
8373

8474
def __append(self, config):
8575
thread_id = threading.get_ident()
86-
# if thread_id not in self.stack_by_thread:
87-
# self.stack_by_thread[thread_id] = [self.main_stack[-1].copy()]
88-
89-
assert thread_id in self.stack_by_thread, "Error: You seem to be creating DSPy threads in an unsupported way."
76+
if thread_id not in self.stack_by_thread:
77+
self.stack_by_thread[thread_id] = [self.main_stack[-1].copy()]
9078
self.stack_by_thread[thread_id].append(config)
9179

9280
def __pop(self):
9381
thread_id = threading.get_ident()
94-
# if thread_id in self.stack_by_thread:
95-
self.stack_by_thread[thread_id].pop()
82+
if thread_id in self.stack_by_thread:
83+
self.stack_by_thread[thread_id].pop()
9684

9785
def configure(self, inherit_config: bool = True, **kwargs):
9886
"""Set configuration settings.
@@ -120,4 +108,4 @@ def __repr__(self) -> str:
120108
return repr(self.config)
121109

122110

123-
settings = Settings()
111+
settings = Settings()

0 commit comments

Comments
 (0)