The text a unit contributes to the prompt, whatever its container. Plain-text files are read directly; converted types (PDF) go through their converter. Both `expand_oversized_files` and `read_slice_text` use this, so the offsets a slice carries always index the same string the model se
(path: Path)
| 77 | |
| 78 | |
| 79 | def unit_source_text(path: Path) -> str: |
| 80 | """The text a unit contributes to the prompt, whatever its container. |
| 81 | |
| 82 | Plain-text files are read directly; converted types (PDF) go through their |
| 83 | converter. Both `expand_oversized_files` and `read_slice_text` use this, so |
| 84 | the offsets a slice carries always index the same string the model sees. |
| 85 | """ |
| 86 | if path.suffix.lower() not in _CONVERTED_TEXT_SUFFIXES: |
| 87 | return _read_source_text(path, warn=False) |
| 88 | try: |
| 89 | st = path.stat() |
| 90 | key = (str(path.resolve()), st.st_size, st.st_mtime_ns) |
| 91 | except OSError: |
| 92 | return _pdf_text(path) |
| 93 | hit = _CONVERTED_TEXT_CACHE.get(key) |
| 94 | if hit is not None: |
| 95 | return hit |
| 96 | text = _pdf_text(path) |
| 97 | if len(_CONVERTED_TEXT_CACHE) >= _CONVERTED_TEXT_CACHE_MAX: |
| 98 | _CONVERTED_TEXT_CACHE.clear() |
| 99 | _CONVERTED_TEXT_CACHE[key] = text |
| 100 | return text |
| 101 | |
| 102 | # Boundary preferences, strongest first. A Markdown heading (``\n#``) keeps a |
| 103 | # section with its title; a blank line keeps a paragraph intact; a bare newline |