mirror of
https://github.com/lllin000/PaperForge.git
synced 2026-07-22 06:50:53 +00:00
Rewrite embedding provider to use openai.OpenAI client instead of raw requests.post. Old code preserved in requests_fallback.py, selectable via VECTOR_DB_PROVIDER_TYPE env/setting. Changes: - paperforge/embedding/providers/openai_compatible.py: rewrite to SDK - paperforge/embedding/providers/requests_fallback.py: NEW old impl - paperforge/embedding/_config.py: add get_provider_type() - tests/test_openai_compatible.py: 6 new tests (encode, timeout, provider_type switch, no-key error, custom base url) feat(#33): E2E test fixtures — 3 synthetic PDFs + expected outputs 3 synthetic papers generated with PyMuPDF, each 3 pages: - paper_a: The Effect of Machine Learning on Clinical Outcomes - paper_b: A Randomized Trial of Remimazolam vs Propofol (with tables) - paper_c: Deep Learning for Medical Image Segmentation (with figures) Changes: - tests/fixtures/papers/: 3 PDFs - tests/fixtures/expected_outputs/: expected blocks + body units - tests/conftest.py: e2e_fixture_dir + synthetic_paper_paths fixtures feat(#26): sqlite-vec schema — vec0 virtual tables + build_state Schema version bumped 4→5. Adds: - 3 vec0 virtual tables: vec_fulltext, vec_body, vec_objects (1536-dim) - 3 companion metadata tables: vec_*_meta (paper_id, chunk_index, text) - build_state table (key/value/updated_at) - ensure_vec_extension() in db.py for extension loading Changes: - paperforge/memory/schema.py: schema v5, new tables in ensure_schema() - paperforge/memory/db.py: ensure_vec_extension() helper - tests/test_vector_schema.py: 5 new tests (tables, virtual, idempotent, v5)
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
def _read_plugin_settings(vault: Path) -> dict:
|
|
data_path = vault / ".obsidian" / "plugins" / "paperforge" / "data.json"
|
|
if data_path.exists():
|
|
return json.loads(data_path.read_text(encoding="utf-8"))
|
|
return {}
|
|
|
|
|
|
def get_api_key(vault: Path) -> str:
|
|
settings = _read_plugin_settings(vault)
|
|
api_key = os.environ.get("VECTOR_DB_API_KEY", "")
|
|
if not api_key:
|
|
api_key = os.environ.get("OPENAI_API_KEY", "")
|
|
if not api_key:
|
|
api_key = settings.get("vector_db_api_key", "")
|
|
if not api_key:
|
|
env_file = vault / ".env"
|
|
if env_file.exists():
|
|
for line in env_file.read_text(encoding="utf-8").splitlines():
|
|
if line.startswith("VECTOR_DB_API_KEY=") or line.startswith("OPENAI_API_KEY="):
|
|
api_key = line.split("=", 1)[1].strip().strip('"').strip("'")
|
|
break
|
|
return api_key
|
|
|
|
|
|
def get_api_base_url(vault: Path) -> str:
|
|
settings = _read_plugin_settings(vault)
|
|
return os.environ.get("VECTOR_DB_API_BASE", "") or settings.get("vector_db_api_base", "") or ""
|
|
|
|
|
|
def get_api_model(vault: Path) -> str:
|
|
settings = _read_plugin_settings(vault)
|
|
return os.environ.get("VECTOR_DB_API_MODEL", "") or settings.get("vector_db_api_model", "text-embedding-3-small")
|
|
|
|
|
|
def get_provider_type(vault: Path) -> str:
|
|
settings = _read_plugin_settings(vault)
|
|
return os.environ.get("VECTOR_DB_PROVIDER_TYPE", "") or settings.get("vector_db_provider_type", "") or "openai_sdk"
|