fix(config): handle /v1 suffix in PAGEPIPER_OLLAMA_URL; add DATA_DIR mkdir guard

This commit is contained in:
pyr0ball 2026-05-04 17:13:50 -07:00
parent 9797e76931
commit abeb6089e5
2 changed files with 13 additions and 4 deletions

View file

@ -6,6 +6,7 @@ import os
from pathlib import Path from pathlib import Path
DATA_DIR = Path(os.environ.get("PAGEPIPER_DATA_DIR", "data")) DATA_DIR = Path(os.environ.get("PAGEPIPER_DATA_DIR", "data"))
DATA_DIR.mkdir(parents=True, exist_ok=True)
DB_PATH = str(DATA_DIR / "pagepiper.db") DB_PATH = str(DATA_DIR / "pagepiper.db")
VEC_DB_PATH = str(DATA_DIR / "pagepiper_vecs.db") VEC_DB_PATH = str(DATA_DIR / "pagepiper_vecs.db")
WATCH_DIR = Path(os.environ.get("PAGEPIPER_WATCH_DIR", "books")) WATCH_DIR = Path(os.environ.get("PAGEPIPER_WATCH_DIR", "books"))
@ -16,12 +17,14 @@ def get_llm_config() -> dict | None:
url = os.environ.get("PAGEPIPER_OLLAMA_URL", "").strip() url = os.environ.get("PAGEPIPER_OLLAMA_URL", "").strip()
if not url: if not url:
return None return None
_clean = url.rstrip("/")
_base_url = _clean if _clean.endswith("/v1") else _clean + "/v1"
return { return {
"fallback_order": ["ollama"], "fallback_order": ["ollama"],
"backends": { "backends": {
"ollama": { "ollama": {
"type": "openai_compat", "type": "openai_compat",
"base_url": url.rstrip("/") + "/v1", "base_url": _base_url,
"model": os.environ.get("PAGEPIPER_CHAT_MODEL", "mistral:7b"), "model": os.environ.get("PAGEPIPER_CHAT_MODEL", "mistral:7b"),
"embedding_model": os.environ.get( "embedding_model": os.environ.get(
"PAGEPIPER_EMBED_MODEL", "nomic-embed-text" "PAGEPIPER_EMBED_MODEL", "nomic-embed-text"

View file

@ -10,7 +10,9 @@ import pytest
def test_migration_creates_documents_table(tmp_path): def test_migration_creates_documents_table(tmp_path):
db_path = str(tmp_path / "test.db") db_path = str(tmp_path / "test.db")
schema = Path("migrations/001_initial_schema.sql").read_text() schema = (
Path(__file__).parent.parent / "migrations/001_initial_schema.sql"
).read_text()
conn = sqlite3.connect(db_path) conn = sqlite3.connect(db_path)
conn.executescript(schema) conn.executescript(schema)
@ -28,7 +30,9 @@ def test_migration_creates_documents_table(tmp_path):
def test_documents_table_has_required_columns(tmp_path): def test_documents_table_has_required_columns(tmp_path):
db_path = str(tmp_path / "test.db") db_path = str(tmp_path / "test.db")
schema = Path("migrations/001_initial_schema.sql").read_text() schema = (
Path(__file__).parent.parent / "migrations/001_initial_schema.sql"
).read_text()
conn = sqlite3.connect(db_path) conn = sqlite3.connect(db_path)
conn.executescript(schema) conn.executescript(schema)
@ -47,7 +51,9 @@ def test_documents_table_has_required_columns(tmp_path):
def test_page_chunks_foreign_key_cascades(tmp_path): def test_page_chunks_foreign_key_cascades(tmp_path):
db_path = str(tmp_path / "test.db") db_path = str(tmp_path / "test.db")
schema = Path("migrations/001_initial_schema.sql").read_text() schema = (
Path(__file__).parent.parent / "migrations/001_initial_schema.sql"
).read_text()
conn = sqlite3.connect(db_path) conn = sqlite3.connect(db_path)
conn.executescript(schema) conn.executescript(schema)