Skip to content

Fix analysis runtime and document review workflow#11

Merged
magic-alt merged 4 commits into
mainfrom
fix/document-metadata-pdfium-tables
May 22, 2026
Merged

Fix analysis runtime and document review workflow#11
magic-alt merged 4 commits into
mainfrom
fix/document-metadata-pdfium-tables

Conversation

@magic-alt
Copy link
Copy Markdown
Owner

Summary

This PR rebases the document review fixes onto the latest main after PR #10 and bundles the follow-up runtime fixes that were validated locally.

What changed

  • fix OpenAI-compatible structured output handling for DeepSeek and related runtime/state persistence issues
  • enrich document list metadata from extracted pages so company, report type, and period end render correctly
  • switch original PDF preview to PDFium-rendered page images and improve raw table browsing in the web UI
  • make uploads start analysis server-side to prevent orphan queued tasks when the frontend follow-up request is missed
  • lock Docker host ports to the project-standard bindings and align docs/helper scripts with those fixed ports

Validation

  • python -m pytest tests/test_routes_web.py tests/test_storage.py tests/test_schemas.py tests/test_openai_compatible_client.py -q
  • npm run typecheck
  • npm run test:unit

Notes

Copilot AI review requested due to automatic review settings May 22, 2026 02:33
@magic-alt magic-alt merged commit 5d67b5f into main May 22, 2026
5 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the document review + analysis workflow across the FastAPI backend and Vue web UI: analysis is started server-side on upload, document metadata is enriched from extracted pages, PDF preview switches to PDFium-rendered page images, and OpenAI-compatible structured output handling is hardened for DeepSeek/Ollama. It also standardizes Docker host port bindings and aligns helper scripts/docs accordingly.

Changes:

  • Start analysis automatically on POST /v1/documents (prevents orphan queued tasks) and improve task state persistence/visibility.
  • Enrich document list metadata from extracted pages.json, and add a /pages/{n}/image endpoint + UI PDFium image preview.
  • Improve table browsing UX (search + merged-cell rendering) and extend OpenAI-compatible client fallback behavior + tests.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
web/src/views/UploadView.vue Stops calling analyze() client-side; relies on server-side auto-start.
web/src/components/TablesPanel.vue Adds table search + merged-cell grid rendering and stats display.
web/src/components/PdfViewer.vue Replaces iframe PDF preview with PDFium-rendered page images + paging toolbar.
web/src/api/types.ts Extends ExtractedTable and introduces ExtractedPage for new endpoints/UI needs.
web/src/api/docs.ts Adds pages() and pageImageBlob() API helpers.
src/api/routes.py Starts analysis on upload, enriches metas on read/list, adds page image endpoint.
src/utils/document_metadata.py Adds metadata inference/enrichment helpers (company/report type/period end).
src/agent/nodes.py Persists enriched metadata during pipeline finalize.
src/storage/task_store.py Ensures get() sees updates from other SQLite connections via rollback.
src/schemas/models.py Drops invalid evidence entries before validation to avoid runtime failures.
src/llm/openai_client.py Provider-aware structured output fallback behavior + JSON payload parsing hardening.
src/llm/base.py Passes provider into OpenAILLMClient construction.
tests/test_routes_web.py Adds coverage for metadata enrichment, upload auto-analysis, and PDFium image endpoint.
tests/test_storage.py Adds regression test ensuring cross-store updates are visible.
tests/test_schemas.py Adds regression test for dropping evidence missing required page references.
tests/test_openai_compatible_client.py New test ensuring DeepSeek structured output uses chat.completions fallback.
scripts/open_ui_after_docker.py Aligns UI open helper with fixed Docker host port.
docker-compose.yml Locks host ports to project-standard bindings.
README.md Updates Docker URLs/ports and documents fixed host ports.
.env.example Updates DeepSeek base URL and removes Docker host-port override variables.
.gitignore Ignores .env.example (note: file is still tracked).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

>
<div class="item-title">{{ t.title || t.table_id }}</div>
<div class="item-meta muted">第 {{ t.page }} 页 · {{ t.cells.length }} 单元格</div>
<div class="item-meta muted">第 {{ t.page }} 页 · {{ t.n_rows || '—' }}×{{ t.n_cols || '—' }} · {{ t.cells.length }} 单元格</div>
Comment thread src/llm/openai_client.py
Comment on lines 64 to +68
chain = prompt | self._chat_model
message = await chain.ainvoke({"system_message": system, "user_message": user})
return _message_to_text(message)
if json_schema and not self._supports_native_structured_output():
user = _with_json_instructions(user, json_schema)
Comment thread src/api/routes.py
Comment on lines 122 to +126

def _load_enriched_meta(doc_id: str) -> DocumentMeta | None:
meta = store.load_meta(doc_id)
if meta is None:
return None
Comment thread .env.example
OPENAI_MODEL=gpt-4.1-mini
DEEPSEEK_API_KEY=
DEEPSEEK_BASE_URL=https://api.deepseek.com/v1
DEEPSEEK_BASE_URL=https://api.deepseek.com
Comment thread README.md
Use this path when you want the full local system with background worker and infrastructure services.

```bash
copy .env.example .env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants