DSPy: The framework for programming—not prompting—language models
Python
Add option for inspect_history to return and print colorless text
Shangyintc605eb0fe961
diff --git a/dsp/modules/lm.py b/dsp/modules/lm.pyindex 8bed65aa3..c14fd0a79 100644--- a/dsp/modules/lm.py+++ b/dsp/modules/lm.py@@ -31,7 +31,7 @@ class LM(ABC):def print_red(self, text: str, end: str = "\n"):return "\x1b[31m" + str(text) + "\x1b[0m" + end- def inspect_history(self, n: int = 1, skip: int = 0):+ def inspect_history(self, n: int = 1, skip: int = 0, color_format: bool = True):"""Prints the last n prompts and their completions.TODO: print the valid choice that contains filled output field instead of the first.@@ -105,12 +105,13 @@ class LM(ABC):text = choiceselse:text = choices[0]["text"]- printing_value += self.print_green(text, end="")+ printing_value += self.print_green(text, end="") if color_format else textif len(choices) > 1 and isinstance(choices, list):+ choices_text = f" \t (and {len(choices)-1} other completions)"printing_value += self.print_red(- f" \t (and {len(choices)-1} other completions)", end="",- )+ choices_text, end="",+ ) if color_format else choices_textprinting_value += "\n\n\n"