Reduces n by half until the function succeeds.
(self, fn, prompt, n)
| 277 | raise Exception("Aborted.") |
| 278 | |
| 279 | def auto_reduce_n(self, fn, prompt, n): |
| 280 | """Reduces n by half until the function succeeds.""" |
| 281 | try: |
| 282 | return fn(prompt, n) |
| 283 | except BatchSizeException as e: |
| 284 | if n == 1: |
| 285 | raise e |
| 286 | return self.auto_reduce_n(fn, prompt, n // 2) + self.auto_reduce_n(fn, prompt, n // 2) |
| 287 | |
| 288 | def generate_text(self, prompt, n): |
| 289 | if not isinstance(prompt, list): |