mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-24 21:41:04 +02:00
refactor: move _coerce_bool to index/utils as the shared home
Both indexing paths and the CLI now use it; page_index_md re-exports it for existing importers.
This commit is contained in:
parent
c8aa83ac85
commit
3a780ab56b
4 changed files with 11 additions and 9 deletions
|
|
@ -1089,7 +1089,7 @@ async def tree_parser(page_list, opt, doc=None, logger=None):
|
|||
|
||||
def page_index_main(doc, opt=None):
|
||||
# accept legacy 'yes'/'no' string flags (a bare 'no' is truthy)
|
||||
from .page_index_md import _coerce_bool
|
||||
from .utils import _coerce_bool
|
||||
for flag in ('if_add_node_id', 'if_add_node_text',
|
||||
'if_add_node_summary', 'if_add_doc_description'):
|
||||
if hasattr(opt, flag):
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import json
|
|||
import re
|
||||
import os
|
||||
from .utils import *
|
||||
from .utils import _coerce_bool # underscore names aren't star-exported
|
||||
|
||||
async def get_node_summary(node, summary_token_threshold=200, model=None):
|
||||
node_text = node.get('text')
|
||||
|
|
@ -243,13 +244,6 @@ def clean_tree_for_output(tree_nodes):
|
|||
return cleaned_nodes
|
||||
|
||||
|
||||
def _coerce_bool(value):
|
||||
"""Coerce a legacy 'yes'/'no' string flag to bool (a bare 'no' is truthy)."""
|
||||
if isinstance(value, str):
|
||||
return value.strip().lower() in ("yes", "true", "1", "y", "on")
|
||||
return bool(value)
|
||||
|
||||
|
||||
async def md_to_tree(md_path, if_thinning=False, min_token_threshold=None, if_add_node_summary=False, summary_token_threshold=None, model=None, if_add_doc_description=False, if_add_node_text=False, if_add_node_id=True):
|
||||
# Accept legacy 'yes'/'no' string flags — a bare 'no' would otherwise be
|
||||
# truthy and wrongly enable the option.
|
||||
|
|
|
|||
|
|
@ -941,6 +941,13 @@ def add_node_text_with_labels(node, pdf_pages):
|
|||
return
|
||||
|
||||
|
||||
def _coerce_bool(value):
|
||||
"""Coerce a legacy 'yes'/'no' string flag to bool (a bare 'no' is truthy)."""
|
||||
if isinstance(value, str):
|
||||
return value.strip().lower() in ("yes", "true", "1", "y", "on")
|
||||
return bool(value)
|
||||
|
||||
|
||||
class ConfigLoader:
|
||||
"""Legacy 0.2.x config helper. Defaults now come from IndexConfig; this
|
||||
class no longer reads the packaged ``config.yaml`` (the CLI still uses it
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ from pageindex.index.page_index import *
|
|||
# a bare ``--flag`` (no value) resolves to True via argparse's ``const``; an
|
||||
# explicit value keeps the legacy yes/no style working, so ``--flag no`` turns
|
||||
# it off. argparse only ever passes a str here (const/default bypass type=).
|
||||
from pageindex.index.page_index_md import md_to_tree, _coerce_bool as _cli_bool
|
||||
from pageindex.index.page_index_md import md_to_tree
|
||||
from pageindex.index.utils import _coerce_bool as _cli_bool
|
||||
from pageindex.config import IndexConfig
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue