refactor(ebook-search): simplify search and phrase matching
This commit is contained in:
@@ -64,17 +64,13 @@ async def check_embedding_endpoint(
|
||||
timeout_seconds: float = 5.0,
|
||||
) -> bool:
|
||||
"""Return whether the configured embedding endpoint answers a model listing."""
|
||||
try:
|
||||
response = await client.get(
|
||||
f"{config.embedding_base_url.rstrip('/')}/models",
|
||||
headers=auth_headers(config.embedding_api_key),
|
||||
timeout=timeout_seconds,
|
||||
)
|
||||
response.raise_for_status()
|
||||
except httpx.HTTPError as error:
|
||||
logger.warning(f"ebook_embedding_endpoint_unreachable {config.embedding_base_url=} {error=}")
|
||||
return False
|
||||
return True
|
||||
return await _check_endpoint(
|
||||
client,
|
||||
base_url=config.embedding_base_url,
|
||||
api_key=config.embedding_api_key,
|
||||
timeout_seconds=timeout_seconds,
|
||||
unavailable_log=f"ebook_embedding_endpoint_unreachable {config.embedding_base_url=}",
|
||||
)
|
||||
|
||||
|
||||
async def check_chat_endpoint(
|
||||
@@ -84,15 +80,33 @@ async def check_chat_endpoint(
|
||||
timeout_seconds: float = 5.0,
|
||||
) -> bool:
|
||||
"""Return whether the configured chat (answering) endpoint answers a model listing."""
|
||||
return await _check_endpoint(
|
||||
client,
|
||||
base_url=config.vllm_base_url,
|
||||
api_key=config.vllm_api_key,
|
||||
timeout_seconds=timeout_seconds,
|
||||
unavailable_log=f"ebook_chat_endpoint_unreachable {config.vllm_base_url=}",
|
||||
)
|
||||
|
||||
|
||||
async def _check_endpoint(
|
||||
client: httpx.AsyncClient,
|
||||
*,
|
||||
base_url: str,
|
||||
api_key: str,
|
||||
timeout_seconds: float,
|
||||
unavailable_log: str,
|
||||
) -> bool:
|
||||
"""Return whether an OpenAI-compatible endpoint answers a model listing."""
|
||||
try:
|
||||
response = await client.get(
|
||||
f"{config.vllm_base_url.rstrip('/')}/models",
|
||||
headers=auth_headers(config.vllm_api_key),
|
||||
f"{base_url.rstrip('/')}/models",
|
||||
headers=auth_headers(api_key),
|
||||
timeout=timeout_seconds,
|
||||
)
|
||||
response.raise_for_status()
|
||||
except httpx.HTTPError as error:
|
||||
logger.warning(f"ebook_chat_endpoint_unreachable {config.vllm_base_url=} {error=}")
|
||||
logger.warning(f"{unavailable_log} {error=}")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user