Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

Add max size for global history (#8057)

TomuHirata16697f49e76e
diff --git a/dspy/clients/base_lm.py b/dspy/clients/base_lm.py
index c4005d44f..016f1e3bf 100644
--- a/dspy/clients/base_lm.py
+++ b/dspy/clients/base_lm.py
@@ -5,6 +5,7 @@ from abc import ABC
from dspy.dsp.utils import settings
from dspy.utils.callback import with_callbacks
+MAX_HISTORY_SIZE = 10_000
GLOBAL_HISTORY = []
@@ -117,6 +118,9 @@ class BaseLM(ABC):
if settings.disable_history:
return
+ if len(GLOBAL_HISTORY) >= MAX_HISTORY_SIZE:
+ GLOBAL_HISTORY.pop(0)
+
GLOBAL_HISTORY.append(entry)