MCPcopy Create free account
hub / github.com/SamuelSchmidgall/AgentLaboratory / process_command

Method process_command

papersolver.py:399–468  ·  view source on GitHub ↗

Take command from language model and execute if valid @param model_resp: (str) language model output @return: (tuple) tuple containing the following items - cmd_str: (str) paper execution return and success flag - paper_lines: (list) list of paper lin

(self, model_resp, scoring=True)

Source from the content-addressed store, hash-verified

397 return latex_lines, prev_latex_ret, score
398
399 def process_command(self, model_resp, scoring=True):
400 """
401 Take command from language model and execute if valid
402 @param model_resp: (str) language model output
403 @return: (tuple) tuple containing the following items
404 - cmd_str: (str) paper execution return and success flag
405 - paper_lines: (list) list of paper lines as strings
406 - prev_paper_ret: (str) output from running paper
407 - score: (float) score of model
408 """
409 cmd_str = None
410 score = None
411 prev_paper_ret = self.prev_paper_ret
412 paper_lines = copy(self.paper_lines)
413 if "\\includegraphics[width=\\textwidth]{Figure_1.png}" in model_resp or "\\includegraphics[width=\\textwidth]{Figure_2.png}" in model_resp:
414 cwd = os.getcwd()
415 model_resp = model_resp.replace("\\includegraphics[width=\\textwidth]{Figure_1.png}", "\\includegraphics[width=\\textwidth]{" + cwd + "/Figure_1.png}")
416 model_resp = model_resp.replace("\\includegraphics[width=\\textwidth]{Figure_2.png}", "\\includegraphics[width=\\textwidth]{" + cwd + "/Figure_2.png}")
417 for cmd in self.commands:
418 if cmd.matches_command(model_resp):
419 # attempt to execute the paper edit command
420 if cmd.cmd_type == "PAPER-edit": # DONE
421 score = None
422 failed = True
423 success, args = cmd.parse_command(model_resp, paper_lines)
424 paper_err = f"Return from executing latex: {args[1]}"
425 if success:
426 # True, current_latex, latex_ret
427 args = cmd.execute_command((args[0], args[1], paper_lines, args[3], self.compile_pdf))
428 success = success and args[0]
429 if not success: pass
430 else:
431 paper_lines = copy(args[1]) #
432 if scoring:
433 score, cmd_str, is_valid = get_score(self.plan, "\n".join(paper_lines), reward_model_llm=self.llm_str)
434 else:
435 score, cmd_str, is_valid = 0.0, "Paper scored successfully", True
436 if is_valid: failed = False
437 paper_err += f"\nReturn from executing latex: {cmd_str}"
438 if not self.supress_print: print("$$$$ PAPER EDIT (success)")
439 if failed:
440 cmd_str = f"Paper edit FAILED due to the following error: {paper_err}. Paper was reverted back to original state before edits."
441 if not self.supress_print: print("$$$$ PAPER EDIT (failed)")
442 else:
443 cmd_str = "Paper was successfully edited."
444 paper_lines = copy(args[1])
445 prev_paper_ret = copy(args[2])
446 if not self.supress_print: print("$$$$ PAPER EDIT (success)")
447 elif cmd.cmd_type == "PAPER-replace": # DONE
448 score = None
449 failed = True
450 success, args = cmd.parse_command(model_resp, self.compile_pdf)
451 paper_err = f"Return from executing latex: {args[1]}"
452 if success:
453 paper_lines = copy(args[0]) #
454 if scoring:
455 score, cmd_str, is_valid = get_score(self.plan, "\n".join(paper_lines), reward_model_llm=self.llm_str)
456 else:

Callers 2

solveMethod · 0.95
gen_initial_reportMethod · 0.95

Calls 4

get_scoreFunction · 0.90
matches_commandMethod · 0.45
parse_commandMethod · 0.45
execute_commandMethod · 0.45

Tested by

no test coverage detected