Skip to content

Commit b59807f

Browse files
author
louyk18
committed
support evolve analysis
1 parent ce17ad0 commit b59807f

File tree

5 files changed

+253
-11
lines changed

5 files changed

+253
-11
lines changed

python/graphy/apps/graph_analyzer.py

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
TEMPLATE_TEXT_EXAMPLE_PROMPT,
2323
TEMPLATE_SUBSECTION_INSTRUCTION_PROMPT,
2424
TEMPLATE_PREVIOUS_SUBSECITON_PROMPT,
25+
CYPHER_QUERY_EXAMPLE,
26+
TEMPLATE_EVOLVE_SUBSECTION_INSTRUCTION_PROMPT,
27+
TEMPLATE_EVOLVE_TEXT_PROMPT,
28+
TEMPLATE_EVOLVE_PREVIOUS_SUBSECITON_PROMPT,
2529
)
2630

2731
logger = logging.getLogger()
@@ -62,8 +66,12 @@ def generate_prop_slot(self, prefix, info):
6266
return output_str
6367

6468
def get_fetch_query(self, query, schema, lang="cypher"):
69+
example = ""
70+
if lang == "cypher":
71+
example = CYPHER_QUERY_EXAMPLE
72+
6573
fetch_prompt = TEMPLATE_QUERY_GENERATOR.format(
66-
user_query=query, schema=schema, language=lang
74+
user_query=query, schema=schema, language=lang, example=example
6775
)
6876

6977
queries = self.generate("fetch_query", fetch_prompt)
@@ -192,3 +200,61 @@ def append_bib_text(self, text, id2bib):
192200
bib_text += "\n" + f"bib of {paper_id}" + "\n"
193201

194202
return bib_text
203+
204+
def generate_evolve_texts(self, query, mind_map, max_token_per_subsection):
205+
section_prompts = []
206+
207+
subsection_id = 0
208+
for category in mind_map.get("data", []):
209+
subsection_id += 1
210+
prop_slot = str(category)
211+
212+
generated_instruction = ""
213+
214+
generated_instruction += (
215+
TEMPLATE_EVOLVE_SUBSECTION_INSTRUCTION_PROMPT.format(
216+
subsection_id=str(subsection_id),
217+
max_token_per_subsection=str(max_token_per_subsection),
218+
)
219+
)
220+
221+
if subsection_id > 1:
222+
generated_instruction += TEMPLATE_EVOLVE_PREVIOUS_SUBSECITON_PROMPT
223+
224+
paper_memories = TEMPLATE_EVOLVE_TEXT_PROMPT.format(
225+
user_query=query,
226+
prop_slot=prop_slot,
227+
generate_instruction=generated_instruction,
228+
)
229+
230+
section_prompts.append(paper_memories)
231+
232+
return section_prompts
233+
234+
def write_evolve_sec_by_sec(
235+
self, query, mind_map, max_token_per_subsection, bib2id={}
236+
):
237+
section_prompts = self.generate_evolve_texts(
238+
query=query,
239+
mind_map=mind_map,
240+
max_token_per_subsection=max_token_per_subsection,
241+
)
242+
243+
# for sec in section_prompts:
244+
# print("########## SECTION PROMPT ###############")
245+
# print(sec)
246+
247+
section_text = ""
248+
for i in range(len(section_prompts)):
249+
text_prompt = section_prompts[i]
250+
if "<PREVIOUS></PREVIOUS>" in text_prompt:
251+
text_prompt = text_prompt.replace("<PREVIOUS></PREVIOUS>", section_text)
252+
new_section_text = self.generate("query_report_text", text_prompt)
253+
section_text += "\n" + new_section_text + "\n"
254+
255+
final_section = section_text
256+
bib_text = self.append_bib_text(final_section, bib2id)
257+
258+
final_section += bib_text
259+
260+
return final_section

0 commit comments

Comments
 (0)