Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

feat(dspy): clear settings between tests

Michael Jones03d8f2b2acaf
diff --git a/dsp/utils/settings.py b/dsp/utils/settings.py
index df073c707..ea02059e4 100644
--- a/dsp/utils/settings.py
+++ b/dsp/utils/settings.py
@@ -3,6 +3,27 @@ from contextlib import contextmanager
from dsp.utils.utils import dotdict
+DEFAULT_CONFIG = dotdict(
+ lm=None,
+ adapter=None,
+ rm=None,
+ branch_idx=0,
+ reranker=None,
+ compiled_lm=None,
+ force_reuse_cached_compilation=False,
+ compiling=False,
+ skip_logprobs=False,
+ trace=[],
+ release=0,
+ bypass_assert=False,
+ bypass_suggest=False,
+ assert_failures=0,
+ suggest_failures=0,
+ langchain_history=[],
+ experimental=False,
+ backoff_time=10,
+)
+
class Settings:
"""DSP configuration settings."""
@@ -25,26 +46,7 @@ class Settings:
# 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 = dotdict(
- lm=None,
- adapter=None,
- rm=None,
- branch_idx=0,
- reranker=None,
- compiled_lm=None,
- force_reuse_cached_compilation=False,
- compiling=False, # TODO: can probably be removed
- skip_logprobs=False,
- trace=[],
- release=0,
- bypass_assert=False,
- bypass_suggest=False,
- assert_failures=0,
- suggest_failures=0,
- langchain_history=[],
- experimental=False,
- backoff_time = 10
- )
+ config = DEFAULT_CONFIG
cls._instance.__append(config)
return cls._instance
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 000000000..0bb74ac90
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,13 @@
+import pytest
+
+import dspy
+from dsp.utils.settings import DEFAULT_CONFIG
+
+
[email protected](autouse=True)
+def clear_settings():
+ """Ensures that the settings are cleared after each test."""
+
+ yield
+
+ dspy.settings.configure(**DEFAULT_CONFIG, inherit_config=False)