Skip to content

Commit

Permalink
Revert settings.py
Browse files Browse the repository at this point in the history
  • Loading branch information
okhat committed Nov 19, 2024
1 parent e336971 commit 9a70c7c
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions dsp/utils/settings.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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."""
Expand All @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -120,4 +108,4 @@ def __repr__(self) -> str:
return repr(self.config)


settings = Settings()
settings = Settings()

0 comments on commit 9a70c7c

Please sign in to comment.