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

Function report_rewrite_chapter

functions/function_calling/deep_research.py:391–418  ·  view source on GitHub ↗

Rewrite the content of an existing chapter.

(
    title: Annotated[str, ParamMeta(description="Chapter title to rewrite (supports multi-level index e.g. 'Intro/Background')")],
    content: Annotated[str, ParamMeta(description="New content")],
    _context: Dict[str, Any] | None = None,
)

Source from the content-addressed store, hash-verified

389
390
391def report_rewrite_chapter(
392 title: Annotated[str, ParamMeta(description="Chapter title to rewrite (supports multi-level index e.g. 'Intro/Background')")],
393 content: Annotated[str, ParamMeta(description="New content")],
394 _context: Dict[str, Any] | None = None,
395) -> str:
396 """
397 Rewrite the content of an existing chapter.
398 """
399 ctx = FileToolContext(_context)
400 _, report_file = _get_files(ctx)
401 _, report_lock = _get_locks(ctx)
402
403 with FileLock(report_lock):
404 lines = _read_report_lines(report_file)
405
406 start, end = _find_chapter_range(lines, title)
407 if start == -1:
408 return f"Chapter '{title}' not found."
409
410 # Keep the header, replace the body
411 # new body should not contain the header itself, just the content
412 new_body = [lines[start]] + content.splitlines() + [""]
413
414 # Replace slice
415 lines[start:end] = new_body
416
417 _save_report(report_file, lines)
418 return f"Rewrote chapter '{title}'"
419
420
421def report_continue_chapter(

Callers

nothing calls this directly

Calls 7

ParamMetaClass · 0.90
FileToolContextClass · 0.90
_get_filesFunction · 0.85
_get_locksFunction · 0.85
_read_report_linesFunction · 0.85
_find_chapter_rangeFunction · 0.85
_save_reportFunction · 0.85

Tested by

no test coverage detected