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

Method gen_initial_report

papersolver.py:330–397  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

328 return text
329
330 def gen_initial_report(self):
331 num_attempts = 0
332 arx = ArxivSearch()
333 section_scaffold = str()
334 # 1. Abstract 2. Introduction, 3. Background, 4. Methods, 5. Experimental Setup 6. Results, and 7. Discussion
335 for _section in ["scaffold", "abstract", "introduction", "related work", "background", "methods", "experimental setup", "results", "discussion"]:
336 section_complete = False
337 if _section in ["introduction", "related work", "background", "methods", "discussion"]:
338 attempts = 0
339 papers = str()
340 first_attempt = True
341 while len(papers) == 0:
342 att_str = str()
343 if attempts > 5:
344 break
345 if not first_attempt:
346 att_str = "This is not your first attempt please try to come up with a simpler search query."
347 search_query = query_model(model_str=f"{self.llm_str}", prompt=f"Given the following research topic {self.topic} and research plan: \n\n{self.plan}\n\nPlease come up with a search query to find relevant papers on arXiv. Respond only with the search query and nothing else. This should be a a string that will be used to find papers with semantically similar content. {att_str}", system_prompt=f"You are a research paper finder. You must find papers for the section {_section}. Query must be text nothing else.", openai_api_key=self.openai_api_key)
348 search_query.replace('"', '')
349 papers = arx.find_papers_by_str(query=search_query, N=10)
350 first_attempt = False
351 attempts += 1
352 if len(papers) != 0:
353 self.section_related_work[_section] = papers
354 while not section_complete:
355 section_scaffold_temp = copy(section_scaffold)
356 if num_attempts == 0: err = str()
357 else: err = f"The following was the previous command generated: {model_resp}. This was the error return {cmd_str}. You should make sure not to repeat this error and to solve the presented problem."
358 if _section == "scaffold":
359 prompt = f"{err}\nNow please enter the ```REPLACE command to create the scaffold:\n "
360 else:
361 rp = str()
362 if _section in self.section_related_work:
363 rp = f"Here are related papers you can cite: {self.section_related_work[_section]}. You can cite them just by putting the arxiv ID in parentheses, e.g. (arXiv 2308.11483v1)\n"
364 prompt = f"{err}\n{rp}\nNow please enter the ```REPLACE command to create the designated section, make sure to only write the text for that section and nothing else. Do not include packages or section titles, just the section content:\n "
365 model_resp = query_model(
366 model_str=self.model,
367 system_prompt=self.system_prompt(section=_section),
368 prompt=f"{prompt}",
369 temp=0.8,
370 openai_api_key=self.openai_api_key)
371 model_resp = self.clean_text(model_resp)
372 if _section == "scaffold":
373 # minimal scaffold (some other sections can be combined)
374 for _sect in ["[ABSTRACT HERE]", "[INTRODUCTION HERE]", "[METHODS HERE]", "[RESULTS HERE]", "[DISCUSSION HERE]"]:
375 if _sect not in model_resp:
376 cmd_str = "Error: scaffold section placeholders were not present (e.g. [ABSTRACT HERE])."
377 if not self.supress_print: print("@@@ INIT ATTEMPT:", cmd_str)
378 continue
379 elif _section != "scaffold":
380 new_text = extract_prompt(model_resp, "REPLACE")
381 section_scaffold_temp = section_scaffold_temp.replace(f"[{_section.upper()} HERE]", new_text)
382 model_resp = '```REPLACE\n' + copy(section_scaffold_temp) + '\n```'
383 if "documentclass{article}" in new_text or "usepackage{" in new_text:
384 cmd_str = "Error: You must not include packages or documentclass in the text! Your latex must only include the section text, equations, and tables."
385 if not self.supress_print: print("@@@ INIT ATTEMPT:", cmd_str)
386 continue
387 cmd_str, latex_lines, prev_latex_ret, score = self.process_command(model_resp, scoring=False)

Callers 1

initial_solveMethod · 0.95

Calls 7

find_papers_by_strMethod · 0.95
system_promptMethod · 0.95
clean_textMethod · 0.95
process_commandMethod · 0.95
ArxivSearchClass · 0.85
query_modelFunction · 0.85
extract_promptFunction · 0.85

Tested by

no test coverage detected