mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-18 21:21:05 +02:00
fix: address PR #272 review findings (directly-fixable items)
Verified against current dev; the compat/behavior decisions (#7 api_key semantics, #10 CLI flags, #11 doc-description default) are deferred. Crashes: - page_index(): snapshot args before importing IndexConfig — locals() was capturing the imported class and IndexConfig(extra='forbid') made every call raise ValidationError. - process_none_page_numbers: pop('page', None) instead of del (a TOC item without 'page' raised KeyError mid-pipeline). - pipeline._run_async: guard only the loop detection, not the run, so a real RuntimeError from the coroutine isn't masked as "asyncio.run() cannot be called from a running event loop". Silent-wrong / robustness: - LocalBackend.get_document_structure and the agent get_document / get_document_structure tools now surface a missing doc (raise / error-JSON) instead of returning empty, matching get_page_content and the cloud backend. - cloud delete_collection drops the cached folder_id. - cloud query raises on an empty collection instead of POSTing doc_id:[]. - LocalClient skips the API-key check for keyless providers (ollama, lm_studio, …) so keyless LiteLLM models aren't rejected at construction. Compat / cleanup: - md_to_tree coerces legacy 'yes'/'no' string flags (a bare 'no' was truthy). - FileTypeError also subclasses ValueError (0.2.x raised ValueError). - _validate_llm_provider no longer mutates global litellm.model_cost_map_url. - __all__ re-includes legacy exports (page_index, md_to_tree, get_*). - Rewrite examples/agentic_vectorless_rag_demo.py to the Collection API and use the in-repo attention.pdf (the old workspace=/client.index/client.documents API no longer exists). Adds tests/test_review_fixes.py (10 regressions). Full suite: 189 passed. Claude-Session: https://claude.ai/code/session_01Kx5DgKbhK1N8autqXH8SmS
This commit is contained in:
parent
703017e581
commit
cf7f5ce9bf
10 changed files with 250 additions and 56 deletions
|
|
@ -44,17 +44,22 @@ def _run_async(coro):
|
|||
import asyncio
|
||||
import concurrent.futures
|
||||
import contextvars
|
||||
# Only the detection is guarded — NOT the run. If the coroutine's own work
|
||||
# raises RuntimeError, letting it fall into `except RuntimeError` here would
|
||||
# misfire the "no running loop" branch and mask the real error behind a
|
||||
# bogus "asyncio.run() cannot be called from a running event loop".
|
||||
try:
|
||||
asyncio.get_running_loop()
|
||||
# Already inside an event loop -- run in a separate thread. Copy the
|
||||
# current context so ContextVar-based settings (e.g. the
|
||||
# max_concurrency_scope override set by build_index) propagate into the
|
||||
# worker thread instead of silently falling back to the process default.
|
||||
ctx = contextvars.copy_context()
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
|
||||
return pool.submit(ctx.run, asyncio.run, coro).result()
|
||||
except RuntimeError:
|
||||
# No running loop -- drive the coroutine directly.
|
||||
return asyncio.run(coro)
|
||||
# Already inside an event loop -- run in a separate thread so we don't nest
|
||||
# asyncio.run. Copy the current context so ContextVar-based settings (e.g.
|
||||
# the max_concurrency_scope override set by build_index) propagate into the
|
||||
# worker thread; .result() re-raises the worker's real exception unchanged.
|
||||
ctx = contextvars.copy_context()
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
|
||||
return pool.submit(ctx.run, asyncio.run, coro).result()
|
||||
|
||||
|
||||
def build_index(parsed: ParsedDocument, model: str = None, opt=None) -> dict:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue