Skip to content

Commit

Permalink
Add inspect_history method to Google class
Browse files Browse the repository at this point in the history
  • Loading branch information
nbqu committed Feb 26, 2024
1 parent b519d9e commit 0339b13
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions dsp/modules/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,41 @@ def __call__(
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")


0 comments on commit 0339b13

Please sign in to comment.