(self)
| 267 | self.openai_api_key = openai_api_key |
| 268 | |
| 269 | def solve(self): |
| 270 | num_attempts = 0 |
| 271 | best_pkg = None |
| 272 | top_score = None |
| 273 | self.prev_paper_ret = None |
| 274 | while True: |
| 275 | self.paper_lines = copy(random.choice(self.best_report)[0]) |
| 276 | model_resp = query_model( |
| 277 | model_str=self.model, |
| 278 | system_prompt=self.system_prompt(), |
| 279 | prompt=f"\nNow please enter a command: ", |
| 280 | temp=1.0, |
| 281 | openai_api_key=self.openai_api_key) |
| 282 | model_resp = self.clean_text(model_resp) |
| 283 | cmd_str, paper_lines, prev_paper_ret, score = self.process_command(model_resp) |
| 284 | if score is not None: |
| 285 | if top_score is None: |
| 286 | best_pkg = copy(paper_lines), copy(prev_paper_ret), copy(model_resp), copy(cmd_str) |
| 287 | top_score = score |
| 288 | elif score > top_score: |
| 289 | best_pkg = copy(paper_lines), copy(prev_paper_ret), copy(model_resp), copy(cmd_str) |
| 290 | top_score = score |
| 291 | if num_attempts >= self.min_gen_trials and top_score is not None: break |
| 292 | if not self.supress_print: print(f"@@@ Command Exec // Attempt {num_attempts}: ", str(cmd_str).replace("\n", " | ")) |
| 293 | if not self.supress_print: print(f"$$$ Score: {score}") |
| 294 | num_attempts += 1 |
| 295 | self.paper_lines, self.prev_paper_ret, model_resp, cmd_str = best_pkg |
| 296 | # add top scoring paper that was successful to the best papers |
| 297 | if top_score > self.best_report[-1][1]: |
| 298 | # replace the lowest scoring one |
| 299 | if len(self.best_report) >= self.max_papers: |
| 300 | self.best_report.pop(-1) |
| 301 | self.best_report.append((copy(self.paper_lines), copy(top_score), self.prev_paper_ret)) |
| 302 | # sort by score, to make sure lowest are removed in future |
| 303 | self.best_report.sort(key=lambda x: x[1], reverse=True) |
| 304 | return model_resp, cmd_str |
| 305 | |
| 306 | def initial_solve(self): |
| 307 | """ |
no test coverage detected