From 014916a66a7e01a3605900d51fcdb8ba2baa5516 Mon Sep 17 00:00:00 2001 From: Ray Tien Date: Mon, 26 Oct 2026 23:28:24 +0800 Subject: [PATCH 1/2] feat(pageindex): index with the Task model when one is configured PageIndex OSS resolved its indexing model from the active chat LLM, so an OAuth-only chat provider (Codex) blocked indexing entirely. Resolve it from the Task model instead when one is set, and fall back to the chat LLM otherwise, so existing setups behave the same. Co-Authored-By: Claude Sonnet 5.5 --- .../rag/pipelines/pageindex/client.py | 20 ++-- .../services/rag/test_pageindex_oss_config.py | 91 +++++++++++++++++++ 2 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 tests/services/rag/test_pageindex_oss_config.py diff --git a/deeptutor/services/rag/pipelines/pageindex/client.py b/deeptutor/services/rag/pipelines/pageindex/client.py index 37b105709..3f71c4a09 100644 --- a/deeptutor/services/rag/pipelines/pageindex/client.py +++ b/deeptutor/services/rag/pipelines/pageindex/client.py @@ -30,19 +30,25 @@ def _prefixed_model(prefix: str, model: str) -> str: def resolve_oss_sdk_config() -> tuple[str, dict[str, Any]]: - """Translate DeepTutor's active LLM into PageIndex's indexing lane.""" - from deeptutor.services.config import resolve_llm_runtime_config + """Translate DeepTutor's indexing model into PageIndex's indexing lane. - cfg = resolve_llm_runtime_config() + Indexing is background work, so it runs on the Task model when one is + configured and otherwise on the active chat LLM. + """ + from deeptutor.services.config import resolve_llm_runtime_config + from deeptutor.services.model_selection.tasks import TASK_SERVICE, task_service_configured + + if task_service_configured(): + cfg = resolve_llm_runtime_config(service_name=TASK_SERVICE) + else: + cfg = resolve_llm_runtime_config() model = str(getattr(cfg, "model", "") or "").strip() binding = str( getattr(cfg, "binding", None) or getattr(cfg, "provider_name", None) or "openai" ).strip() spec = find_by_name(binding) if not model: - raise RuntimeError( - "PageIndex OSS needs an active LLM. Configure one under Settings → Catalog." - ) + raise RuntimeError("PageIndex OSS needs an LLM. Configure one under Settings → Catalog.") if ( spec is None or spec.is_oauth @@ -55,7 +61,7 @@ def resolve_oss_sdk_config() -> tuple[str, dict[str, Any]]: ): raise RuntimeError( "PageIndex OSS indexing needs an API-key or local LLM profile; " - "the active OAuth-only provider cannot be used." + "an OAuth-only provider cannot be used." ) resolved_model = strip_provider_prefix(model, spec) diff --git a/tests/services/rag/test_pageindex_oss_config.py b/tests/services/rag/test_pageindex_oss_config.py new file mode 100644 index 000000000..a8d0e3610 --- /dev/null +++ b/tests/services/rag/test_pageindex_oss_config.py @@ -0,0 +1,91 @@ +"""PageIndex OSS indexing follows the background-task model, not the chat model.""" + +from __future__ import annotations + +from pathlib import Path + +import pytest + +from deeptutor.services.config import provider_runtime +from deeptutor.services.config.model_catalog import ModelCatalogService +from deeptutor.services.model_selection import tasks +from deeptutor.services.rag.pipelines.pageindex.client import resolve_oss_sdk_config + + +def _codex_llm() -> dict: + return { + "active_profile_id": "codex", + "active_model_id": "codex-model", + "profiles": [ + { + "id": "codex", + "name": "OpenAI Codex", + "binding": "openai_codex", + "models": [{"id": "codex-model", "model": "gpt-6-luna"}], + } + ], + } + + +def _anthropic_profile(model: str) -> dict: + return { + "id": "claude", + "name": "Anthropic", + "binding": "anthropic", + "api_key": "sk-test", + "models": [{"id": "claude-model", "model": model}], + } + + +@pytest.fixture +def catalog(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): + service = ModelCatalogService(path=tmp_path / "model_catalog.json") + monkeypatch.setattr(provider_runtime, "get_model_catalog_service", lambda: service) + monkeypatch.setattr(tasks, "get_model_catalog_service", lambda: service) + + def save(**services: dict) -> None: + data = service.load() + data["services"].update(services) + service.save(data) + + return save + + +def test_task_model_indexes_while_chat_stays_on_oauth(catalog) -> None: + llm = _codex_llm() + llm["profiles"].append(_anthropic_profile("claude-haiku")) + catalog( + llm=llm, + task={ + "mode": "reference", + "selection": {"profile_id": "claude", "model_id": "claude-model"}, + "active_profile_id": None, + "active_model_id": None, + "profiles": [], + }, + ) + + model, backend = resolve_oss_sdk_config() + + assert model == "anthropic/claude-haiku" + assert backend["api_key"] == "sk-test" + + +def test_inherited_task_model_still_rejects_an_oauth_chat_model(catalog) -> None: + catalog(llm=_codex_llm()) + + with pytest.raises(RuntimeError, match="OAuth-only"): + resolve_oss_sdk_config() + + +def test_inherited_task_model_uses_the_api_key_chat_model(catalog) -> None: + llm = { + "active_profile_id": "claude", + "active_model_id": "claude-model", + "profiles": [_anthropic_profile("claude-sonnet")], + } + catalog(llm=llm) + + model, _backend = resolve_oss_sdk_config() + + assert model == "anthropic/claude-sonnet" From 151458a6b340947a13c527fcdc45bfd2838c32e3 Mon Sep 17 00:00:00 2001 From: Ray Tien Date: Mon, 26 Oct 2026 23:34:53 +0800 Subject: [PATCH 2/2] fix(pageindex): drop the /v1 suffix from the Anthropic base URL litellm appends /v1/messages itself, so the default Anthropic base URL ending in /v1 made PageIndex OSS indexing 404 for any Anthropic API-key model. Co-Authored-By: Claude Sonnet 5.5 --- .../services/rag/pipelines/pageindex/client.py | 3 +++ tests/services/rag/test_pageindex_oss_config.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/deeptutor/services/rag/pipelines/pageindex/client.py b/deeptutor/services/rag/pipelines/pageindex/client.py index 3f71c4a09..ab8019137 100644 --- a/deeptutor/services/rag/pipelines/pageindex/client.py +++ b/deeptutor/services/rag/pipelines/pageindex/client.py @@ -87,6 +87,9 @@ def resolve_oss_sdk_config() -> tuple[str, dict[str, Any]]: elif api_key: backend["api_key"] = api_key + if spec.backend == "anthropic": + # litellm appends /v1/messages itself; a base ending in /v1 would 404. + base_url = base_url.rstrip("/").removesuffix("/v1") if base_url: backend["api_base"] = base_url if api_version and spec.backend != "openai_compat": diff --git a/tests/services/rag/test_pageindex_oss_config.py b/tests/services/rag/test_pageindex_oss_config.py index a8d0e3610..5aa6b1710 100644 --- a/tests/services/rag/test_pageindex_oss_config.py +++ b/tests/services/rag/test_pageindex_oss_config.py @@ -89,3 +89,19 @@ def test_inherited_task_model_uses_the_api_key_chat_model(catalog) -> None: model, _backend = resolve_oss_sdk_config() assert model == "anthropic/claude-sonnet" + + +def test_anthropic_base_url_drops_the_version_segment_litellm_appends(catalog) -> None: + profile = _anthropic_profile("claude-haiku") + profile["base_url"] = "https://api.anthropic.com/v1" + catalog( + llm={ + "active_profile_id": "claude", + "active_model_id": "claude-model", + "profiles": [profile], + } + ) + + _model, backend = resolve_oss_sdk_config() + + assert backend["api_base"] == "https://api.anthropic.com"