MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / _find_chapter_range

Function _find_chapter_range

functions/function_calling/deep_research.py:195–235  ·  view source on GitHub ↗

Find the start and end indices (inclusive, exclusive) of a chapter. title_path is like "Chapter 1/Section 2"

(lines: List[str], title_path: str)

Source from the content-addressed store, hash-verified

193
194
195def _find_chapter_range(lines: List[str], title_path: str) -> Tuple[int, int]:
196 """
197 Find the start and end indices (inclusive, exclusive) of a chapter.
198 title_path is like "Chapter 1/Section 2"
199 """
200 titles = [t.strip() for t in title_path.split("/")]
201 current_level_idx = 0
202 start_idx = -1
203
204 # We need to find the sequence of headers
205 search_start = 0
206
207 for i, target_title in enumerate(titles):
208 found = False
209
210 for idx in range(search_start, len(lines)):
211 level, text = _parse_header(lines[idx])
212 if level > 0 and text == target_title:
213 # Found the current segment
214 search_start = idx + 1
215 found = True
216 if i == len(titles) - 1:
217 start_idx = idx
218 current_level_idx = level
219 break
220
221 if not found:
222 return -1, -1
223
224 if start_idx == -1:
225 return -1, -1
226
227 # Find end: next header of same or lower level (higher importance, smaller integer)
228 end_idx = len(lines)
229 for idx in range(start_idx + 1, len(lines)):
230 level, _ = _parse_header(lines[idx])
231 if level > 0 and level <= current_level_idx:
232 end_idx = idx
233 break
234
235 return start_idx, end_idx
236
237
238def report_read(

Callers 6

report_read_chapterFunction · 0.85
report_create_chapterFunction · 0.85
report_rewrite_chapterFunction · 0.85
report_continue_chapterFunction · 0.85
report_reorder_chaptersFunction · 0.85
report_del_chapterFunction · 0.85

Calls 2

_parse_headerFunction · 0.85
splitMethod · 0.45

Tested by

no test coverage detected