Documentation
¶
Overview ¶
Package docconv centralizes the external Python-script document-conversion helpers (markitdown via doc_converter.py, and PDF OCR via ocr_pdf.py) that were previously duplicated across three packages (rag, tool/builtin, control).
The conversion logic, script discovery, and Python-process invocation are byte-for-byte identical in all three call sites; this package collapses them into one implementation. Each caller keeps its own fallback policy (e.g. rag falls back to a Go docx parser when markitdown is absent) — this package only owns the shared "find script → run python → parse JSON" plumbing.
Index ¶
Constants ¶
const DefaultTimeout = 3 * time.Minute
DefaultTimeout is the max time allowed for a single conversion subprocess. markitdown uses 3 min; PDF OCR (PaddleOCR over many pages) needs longer and overrides this via ConvertFile.
Variables ¶
This section is empty.
Functions ¶
func ConvertText ¶
ConvertText is a convenience wrapper that runs doc_converter.py (located via FindScript) and returns just the converted text, preserving the exact signature the three call sites used (string text + error). Returns ("", err) when the script is missing or fails — callers apply their own fallback.
func FindScript ¶
FindScript searches the conventional locations for a bundled Python script (e.g. "doc_converter.py", "ocr_pdf.py"): the current working directory first, then next to the running executable and up to two parent directories. Returns "" when not found. This is the single source of truth that the three former duplicated finders resolved to.
func ScriptCandidates ¶
ScriptCandidates returns the ordered list of paths to probe for a bundled script of the given name. Exposed so tests can inspect/override the list.
Types ¶
type Result ¶
type Result struct {
Text string `json:"text"`
Title string `json:"title"`
Error string `json:"error"`
}
Result is the JSON shape emitted by doc_converter.py (and ocr_pdf.py). Text holds the converted markdown/text; Title is the detected document title (may be empty); Error carries a Python-side error message.
func ConvertFile ¶
ConvertFile runs the given Python script against `path`, capturing its JSON stdout into a Result. A zero timeout uses DefaultTimeout. The error wraps both the process exit error (with stderr) and any JSON-parse failure, and surfaces a Python-emitted error field, so callers can distinguish causes.
This is the unified replacement for rag.convertWithMarkitdown, builtin.convertDocWithMarkitdown, and control.convertFileWithMarkitdown.