DSPy: The framework for programming—not prompting—language models
Python
fix: return value in the inspect_history beside printing.
Amir Mehrd726b84155dc
diff --git a/dsp/modules/lm.py b/dsp/modules/lm.pyindex e2965d49a..9fa57bff5 100644--- a/dsp/modules/lm.py+++ b/dsp/modules/lm.py@@ -26,10 +26,10 @@ class LM(ABC):return self.basic_request(prompt, **kwargs)def print_green(self, text: str, end: str = "\n"):- print("\x1b[32m" + str(text) + "\x1b[0m", end=end)+ return "\x1b[32m" + str(text) + "\x1b[0m" + enddef print_red(self, text: str, end: str = "\n"):- print("\x1b[31m" + str(text) + "\x1b[0m", end=end)+ return "\x1b[31m" + str(text) + "\x1b[0m" + enddef inspect_history(self, n: int = 1, skip: int = 0):"""Prints the last n prompts and their completions.@@ -69,12 +69,15 @@ class LM(ABC):breakfor idx, (prompt, choices) in enumerate(reversed(printed)):+ printing_value = ""+# skip the first `skip` promptsif (n - idx - 1) < skip:continue- print("\n\n\n")- print(prompt, end="")+ printing_value += "\n\n\n"+ printing_value += prompt+text = ""if provider == "cohere":text = choices[0].text@@ -82,15 +85,15 @@ class LM(ABC):text = ' ' + self._get_choice_text(choices[0]).strip()elif provider == "clarifai":text=choices- elif provider == "google":- text = choices[0].parts[0].textelse:text = choices[0]["text"]- self.print_green(text, end="")+ printing_value += self.print_green(text, end="")if len(choices) > 1:- self.print_red(f" \t (and {len(choices)-1} other completions)", end="")- print("\n\n\n")+ printing_value += self.print_red(f" \t (and {len(choices)-1} other completions)", end="")++ printing_value += "\n\n\n"+ return printing_value@abstractmethoddef __call__(self, prompt, only_completed=True, return_sorted=False, **kwargs):