mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(vertex_ai): keep the old batch create error text and Google object names
A failed Vertex batch create keeps httpx's error line first and adds Vertex's body after it, and logs the status and body again. Only Claude object names keep the @ version, so Google models are stored under the same names as before
This commit is contained in:
parent
757021ab19
commit
79cc204c54
4 changed files with 37 additions and 8 deletions
|
|
@ -86,7 +86,7 @@ def _vertex_batch_list_payload(response: _VertexBatchListJsonSource) -> dict[str
|
|||
def _vertex_batch_create_error(error: httpx.HTTPStatusError) -> MaskedHTTPStatusError:
|
||||
body: Final = mask_sensitive_info(error.response.text)
|
||||
return MaskedHTTPStatusError(
|
||||
httpx.HTTPStatusError(f"Vertex AI batch create failed: {body}", request=error.request, response=error.response),
|
||||
httpx.HTTPStatusError(f"{error}\n{body}", request=error.request, response=error.response),
|
||||
message=body,
|
||||
text=body,
|
||||
)
|
||||
|
|
@ -184,6 +184,11 @@ class VertexAIBatchPrediction(VertexLLM):
|
|||
data=json.dumps(vertex_batch_request),
|
||||
)
|
||||
except httpx.HTTPStatusError as e:
|
||||
litellm.verbose_logger.error(
|
||||
"Vertex AI batch create failed: status=%s, body=%s",
|
||||
e.response.status_code,
|
||||
e.response.text[:1000],
|
||||
)
|
||||
raise _vertex_batch_create_error(e) from e
|
||||
|
||||
payload_view: Final[_VertexBatchPayloadView] = {"payload": response.json()}
|
||||
|
|
@ -280,6 +285,11 @@ class VertexAIBatchPrediction(VertexLLM):
|
|||
data=json.dumps(vertex_batch_request),
|
||||
)
|
||||
except httpx.HTTPStatusError as e:
|
||||
litellm.verbose_logger.error(
|
||||
"Vertex AI batch create failed: status=%s, body=%s",
|
||||
e.response.status_code,
|
||||
e.response.text[:1000],
|
||||
)
|
||||
raise _vertex_batch_create_error(e) from e
|
||||
|
||||
payload_view: Final[_VertexBatchPayloadView] = {"payload": response.json()}
|
||||
|
|
|
|||
|
|
@ -1115,11 +1115,16 @@ def _publisher_model_path(raw_model: str) -> str:
|
|||
def _managed_batch_object_name(raw_model: str, *, passthrough: bool) -> str:
|
||||
endpoint_id: Final = get_vertex_ai_fine_tuned_endpoint_id(raw_model)
|
||||
model_path: Final = f"endpoints/{endpoint_id}" if endpoint_id is not None else _publisher_model_path(raw_model)
|
||||
safe_model_path: Final = "@".join(
|
||||
prefix: Final = _PASSTHROUGH_MANAGED_GCS_PREFIX if passthrough else VERTEX_AI_MANAGED_GCS_PREFIX
|
||||
return f"{prefix}{_safe_managed_model_path(model_path)}/{uuid.uuid4()}"
|
||||
|
||||
|
||||
def _safe_managed_model_path(model_path: str) -> str:
|
||||
if not is_vertex_anthropic_batch_model(model_path):
|
||||
return sanitize_cloud_object_path(model_path, fallback="model")
|
||||
return "@".join(
|
||||
sanitize_cloud_object_path(version_part, fallback="model") for version_part in model_path.split("@")
|
||||
)
|
||||
prefix: Final = _PASSTHROUGH_MANAGED_GCS_PREFIX if passthrough else VERTEX_AI_MANAGED_GCS_PREFIX
|
||||
return f"{prefix}{safe_model_path}/{uuid.uuid4()}"
|
||||
|
||||
|
||||
class VertexAIFilesConfig(VertexBase, BaseFilesConfig):
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ from litellm.proxy.utils import handle_exception_on_proxy # noqa: E402
|
|||
from litellm.types.utils import LiteLLMBatch # noqa: E402
|
||||
|
||||
HMOD = "litellm.llms.vertex_ai.batches.handler"
|
||||
_CLIENT_ERROR_429: Final = "Client error '429 Too Many Requests' for url 'https://x/batchPredictionJobs'"
|
||||
TOKEN = "ya29.fake-access-token"
|
||||
PROJECT = "my-project"
|
||||
LOCATION = "us-central1"
|
||||
|
|
@ -380,11 +381,11 @@ def test_create_batch_sync_httpstatuserror_carries_vertex_status_body_and_header
|
|||
status_code=429, request=request, text="boom", headers={"retry-after": "30"}
|
||||
)
|
||||
client.post.side_effect = httpx.HTTPStatusError(
|
||||
"boom", request=request, response=err_response
|
||||
_CLIENT_ERROR_429, request=request, response=err_response
|
||||
)
|
||||
|
||||
with patch(f"{HMOD}.get_httpx_client", return_value=client):
|
||||
with pytest.raises(httpx.HTTPStatusError, match="Vertex AI batch create failed: boom") as exc_info:
|
||||
with pytest.raises(httpx.HTTPStatusError) as exc_info:
|
||||
h.create_batch(
|
||||
_is_async=False,
|
||||
create_batch_data=CREATE_DATA,
|
||||
|
|
@ -399,6 +400,7 @@ def test_create_batch_sync_httpstatuserror_carries_vertex_status_body_and_header
|
|||
assert exc_info.value.response.headers["retry-after"] == "30"
|
||||
assert handle_exception_on_proxy(exc_info.value).code == "429"
|
||||
assert (getattr(exc_info.value, "message", None), getattr(exc_info.value, "text", None)) == ("boom", "boom")
|
||||
assert str(exc_info.value).splitlines() == [_CLIENT_ERROR_429, "boom"]
|
||||
|
||||
|
||||
def test_create_batch_input_file_id_without_model_raises_400_before_post():
|
||||
|
|
@ -815,7 +817,7 @@ def test_create_batch_async_httpstatuserror_carries_vertex_status_body_and_heade
|
|||
)
|
||||
async_client.post = AsyncMock(
|
||||
side_effect=httpx.HTTPStatusError(
|
||||
"boom", request=request, response=err_response
|
||||
_CLIENT_ERROR_429, request=request, response=err_response
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -833,12 +835,13 @@ def test_create_batch_async_httpstatuserror_carries_vertex_status_body_and_heade
|
|||
timeout=600.0,
|
||||
max_retries=None,
|
||||
)
|
||||
with pytest.raises(httpx.HTTPStatusError, match="Vertex AI batch create failed: boom") as exc_info:
|
||||
with pytest.raises(httpx.HTTPStatusError) as exc_info:
|
||||
_run(coro)
|
||||
assert exc_info.value.response.status_code == 429
|
||||
assert exc_info.value.response.headers["retry-after"] == "30"
|
||||
assert handle_exception_on_proxy(exc_info.value).code == "429"
|
||||
assert (getattr(exc_info.value, "message", None), getattr(exc_info.value, "text", None)) == ("boom", "boom")
|
||||
assert str(exc_info.value).splitlines() == [_CLIENT_ERROR_429, "boom"]
|
||||
|
||||
|
||||
def test_async_retrieve_batch_non_200_raises():
|
||||
|
|
|
|||
|
|
@ -169,6 +169,17 @@ class TestBatchObjectNaming:
|
|||
object_name = config._get_gcs_object_name_from_batch_jsonl([{"body": {"model": "gemini-2.5-flash"}}])
|
||||
assert object_name.startswith("litellm-vertex-files/publishers/google/models/gemini-2.5-flash/")
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("model", "stored_model"),
|
||||
[
|
||||
("multimodalembedding@001", "publishers/google/models/multimodalembedding_001/"),
|
||||
("claude-haiku-4-5@20251001", "publishers/anthropic/models/claude-haiku-4-5@20251001/"),
|
||||
],
|
||||
)
|
||||
def test_only_claude_models_keep_the_at_version_in_their_object_name(self, config, model, stored_model):
|
||||
object_name: Final = config._get_gcs_object_name_from_batch_jsonl([{"body": {"model": model}}])
|
||||
assert object_name.startswith(f"litellm-vertex-files/{stored_model}")
|
||||
|
||||
def test_should_store_fine_tuned_endpoint_under_endpoints_path(self, config):
|
||||
"""A numeric endpoint id must not be filed under publishers/google/models/gemini/<id>,
|
||||
which the batch transformation later mangles into a nonexistent publisher model (LIT-6899)."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue