DSPy: The framework for programming—not prompting—language models
Python
Fix response format in Google class and update condition in LM class for deduplication
nbqu48f241c43126
diff --git a/dsp/modules/google.py b/dsp/modules/google.pyindex 3a5a57063..c6c6bd43e 100644--- a/dsp/modules/google.py+++ b/dsp/modules/google.py@@ -120,7 +120,7 @@ class Google(LM):history = {"prompt": prompt,- "response": response,+ "response": [response],"kwargs": kwargs,"raw_kwargs": raw_kwargs,}@@ -158,39 +158,3 @@ class Google(LM):completions.append(response.parts[0].text)return completions-- def inspect_history(self, n: int = 1, skip: int = 0):- """Prints the last n prompts and their completions.- TODO: print the valid choice that contains filled output field instead of the first- """-- last_prompt = None- printed = []- n = n + skip-- for x in reversed(self.history[-100:]):- prompt = x["prompt"]-- if prompt != last_prompt:- printed.append(- (- prompt,- x['response']- )- )-- last_prompt = prompt-- if len(printed) >= n:- break-- for idx, (prompt, response) in enumerate(reversed(printed)):- # skip the first `skip` prompts- if (n - idx - 1) < skip:- continue-- print("\n\n\n")- print(prompt, end="")- text = response.parts[0].text- self.print_green(text, end="")- print("\n\n\n")diff --git a/dsp/modules/lm.py b/dsp/modules/lm.pyindex 6305338d7..e2965d49a 100644--- a/dsp/modules/lm.py+++ b/dsp/modules/lm.py@@ -46,14 +46,14 @@ class LM(ABC):if prompt != last_prompt:- if provider=="clarifai":+ if provider == "clarifai" or provider == "google":printed.append((prompt,x['response']- )+ ))- else:+ else:printed.append((prompt,@@ -82,6 +82,8 @@ 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="")