MCPcopy
hub / github.com/VectifyAI/PageIndex / single_toc_item_index_fixer

Function single_toc_item_index_fixer

pageindex/page_index.py:740–756  ·  view source on GitHub ↗
(section_title, content, model=None)

Source from the content-addressed store, hash-verified

738
739################### fix incorrect toc #########################################################
740async def single_toc_item_index_fixer(section_title, content, model=None):
741 toc_extractor_prompt = """
742 You are given a section title and several pages of a document, your job is to find the physical index of the start page of the section in the partial document.
743
744 The provided pages contains tags like <physical_index_X> and <physical_index_X> to indicate the physical location of the page X.
745
746 Reply in a JSON format:
747 {
748 "thinking": <explain which page, started and closed by <physical_index_X>, contains the start of this section>,
749 "physical_index": "<physical_index_X>" (keep the format)
750 }
751 Directly return the final JSON structure. Do not output anything else."""
752
753 prompt = toc_extractor_prompt + '\nSection Title:\n' + str(section_title) + '\nDocument pages:\n' + content
754 response = await llm_acompletion(model=model, prompt=prompt)
755 json_content = extract_json(response)
756 return convert_physical_index_to_int(json_content['physical_index'])
757
758
759

Callers 1

process_and_check_itemFunction · 0.85

Calls 3

llm_acompletionFunction · 0.85
extract_jsonFunction · 0.85

Tested by

no test coverage detected