MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / unit_source_text

Function unit_source_text

graphify/file_slice.py:79–100  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

77
78
79def 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

Calls 5

_read_source_textFunction · 0.90
_pdf_textFunction · 0.85
clearMethod · 0.80
resolveMethod · 0.45
getMethod · 0.45