PageIndex/pageindex/__init__.py

78 lines
2.4 KiB
Python

# pageindex/__init__.py
# Load .env first so env-based credentials (OPENAI_API_KEY, PAGEINDEX_API_KEY) are set.
from dotenv import load_dotenv as _load_dotenv
_load_dotenv()
# Backward compatibility: honor CHATGPT_API_KEY as an alias for OPENAI_API_KEY.
import os as _os
if not _os.getenv("OPENAI_API_KEY") and _os.getenv("CHATGPT_API_KEY"):
_os.environ["OPENAI_API_KEY"] = _os.getenv("CHATGPT_API_KEY")
# Upstream exports (backward compatibility); import from the canonical index.*
# modules so plain `import pageindex` doesn't trip the deprecation shims.
from .index.page_index import * # noqa: E402
from .index.page_index_md import md_to_tree
from .retrieve import get_document, get_document_structure, get_page_content
# SDK exports
from .client import PageIndexClient, LocalClient, CloudClient
from .config import IndexConfig, set_llm_params
from .collection import Collection
from .types import DocumentInfo, DocumentDetail, PageContent
from .parser.protocol import ContentNode, ParsedDocument, DocumentParser
from .storage.protocol import StorageEngine
from .events import QueryEvent
from .errors import (
PageIndexError,
PageIndexAPIError,
CollectionNotFoundError,
DocumentNotFoundError,
IndexingError,
CloudAPIError,
FileTypeError,
)
__all__ = [
"PageIndexClient",
"LocalClient",
"CloudClient",
"IndexConfig",
"set_llm_params",
"Collection",
"DocumentInfo",
"DocumentDetail",
"PageContent",
"ContentNode",
"ParsedDocument",
"DocumentParser",
"StorageEngine",
"QueryEvent",
"PageIndexError",
"PageIndexAPIError",
"CollectionNotFoundError",
"DocumentNotFoundError",
"IndexingError",
"CloudAPIError",
"FileTypeError",
# Legacy top-level exports (pre-SDK API), kept so `from pageindex import *`
# still binds them.
"page_index",
"page_index_main",
"tree_parser",
"ConfigLoader",
"llm_completion",
"llm_acompletion",
"md_to_tree",
"get_document",
"get_document_structure",
"get_page_content",
]
def __getattr__(name):
# Lazy so plain `import pageindex` never trips the shims' deprecation
# warnings; they fire only when the legacy attribute is actually used.
if name in ("utils", "page_index_md"):
import importlib
return importlib.import_module(f".{name}", __name__)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")