refactor(ebook-search): simplify search and phrase matching
This commit is contained in:
@@ -10,6 +10,7 @@ import pytest
|
||||
from python.ebook_search.answer import answer_query
|
||||
from python.ebook_search.config import EbookSearchConfig, RerankConfig
|
||||
from python.ebook_search.embeddings import embed_texts
|
||||
from python.ebook_search.llm_interface import check_chat_endpoint, check_embedding_endpoint
|
||||
from python.ebook_search.search import SearchResult
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -23,6 +24,44 @@ def make_async_client(mocker: MockerFixture, fake_post) -> httpx.AsyncClient:
|
||||
return client
|
||||
|
||||
|
||||
async def test_model_endpoint_checks_share_http_probe(mocker: MockerFixture) -> None:
|
||||
client = mocker.MagicMock(spec=httpx.AsyncClient)
|
||||
response = mocker.MagicMock(spec=httpx.Response)
|
||||
client.get = mocker.AsyncMock(return_value=response)
|
||||
config = EbookSearchConfig(
|
||||
rerank=RerankConfig(enabled=False),
|
||||
embedding_base_url="https://embedding.example/v1/",
|
||||
vllm_base_url="https://chat.example/v1/",
|
||||
vllm_api_key="secret",
|
||||
)
|
||||
|
||||
assert await check_embedding_endpoint(client, config, timeout_seconds=2.0)
|
||||
assert await check_chat_endpoint(client, config, timeout_seconds=3.0)
|
||||
assert client.get.await_args_list == [
|
||||
mocker.call("https://embedding.example/v1/models", headers={}, timeout=2.0),
|
||||
mocker.call(
|
||||
"https://chat.example/v1/models",
|
||||
headers={"Authorization": "Bearer secret"},
|
||||
timeout=3.0,
|
||||
),
|
||||
]
|
||||
assert response.raise_for_status.call_count == 2
|
||||
|
||||
|
||||
async def test_model_endpoint_checks_report_http_failures(mocker: MockerFixture) -> None:
|
||||
client = mocker.MagicMock(spec=httpx.AsyncClient)
|
||||
client.get = mocker.AsyncMock(
|
||||
side_effect=[
|
||||
httpx.ConnectError("embedding offline"),
|
||||
httpx.ConnectError("chat offline"),
|
||||
]
|
||||
)
|
||||
config = EbookSearchConfig(rerank=RerankConfig(enabled=False))
|
||||
|
||||
assert not await check_embedding_endpoint(client, config)
|
||||
assert not await check_chat_endpoint(client, config)
|
||||
|
||||
|
||||
async def test_answer_query_uses_httpx_chat_completions(mocker: MockerFixture) -> None:
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user