Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion backend/model_server/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def format_embedding_error(
service_name: str,
model: str | None,
provider: EmbeddingProvider,
sanitized_api_key: str | None = None,
status_code: int | None = None,
) -> str:
"""
Expand All @@ -103,6 +104,7 @@ def format_embedding_error(
f"{'HTTP error' if status_code else 'Exception'} embedding text with {service_name} - {detail}: "
f"Model: {model} "
f"Provider: {provider} "
f"API Key: {sanitized_api_key} "
f"Exception: {error}"
)

Expand Down Expand Up @@ -133,6 +135,7 @@ def __init__(
self.timeout = timeout
self.http_client = httpx.AsyncClient(timeout=timeout)
self._closed = False
self.sanitized_api_key = api_key[:4] + "********" + api_key[-4:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider moving API key sanitization to a separate utility function for reuse and consistent sanitization across the codebase


async def _embed_openai(
self, texts: list[str], model: str | None, reduced_dimension: int | None
Expand Down Expand Up @@ -306,6 +309,7 @@ async def embed(
str(self.provider),
model_name or deployment_name,
self.provider,
sanitized_api_key=self.sanitized_api_key,
status_code=e.response.status_code,
)
logger.error(error_string)
Expand All @@ -317,7 +321,11 @@ async def embed(
raise AuthenticationError(provider=str(self.provider))

error_string = format_embedding_error(
e, str(self.provider), model_name or deployment_name, self.provider
e,
str(self.provider),
model_name or deployment_name,
self.provider,
sanitized_api_key=self.sanitized_api_key,
)
logger.error(error_string)
logger.debug(f"Exception texts: {texts}")
Expand Down