mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
Merge pull request #27041 from BerriAI/litellm_vertex-batch-error-response-null-46dd
Some checks are pending
Unit Tests: Caching (Redis) / caching-redis (push) Waiting to run
Unit Tests: Proxy DB Operations / assert-shard-coverage (push) Waiting to run
Unit Tests: Proxy DB Operations / auth-checks (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / budgets (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / custom-logging (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / db-and-spend (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / endpoints-and-responses (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / guardrails-hooks (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / jwt-and-keys (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / key-generation (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / logging-misc (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / proxy-runtime (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / proxy-server-core (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / schema-migration (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / proxy-utils (push) Blocked by required conditions
Unit Tests: Security / security (push) Waiting to run
Some checks are pending
Unit Tests: Caching (Redis) / caching-redis (push) Waiting to run
Unit Tests: Proxy DB Operations / assert-shard-coverage (push) Waiting to run
Unit Tests: Proxy DB Operations / auth-checks (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / budgets (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / custom-logging (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / db-and-spend (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / endpoints-and-responses (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / guardrails-hooks (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / jwt-and-keys (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / key-generation (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / logging-misc (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / proxy-runtime (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / proxy-server-core (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / schema-migration (push) Blocked by required conditions
Unit Tests: Proxy DB Operations / proxy-utils (push) Blocked by required conditions
Unit Tests: Security / security (push) Waiting to run
fix(vertex-ai): set response=null on batch error entries per OpenAI spec
This commit is contained in:
commit
c011a7e3ba
2 changed files with 55 additions and 30 deletions
|
|
@ -731,25 +731,13 @@ class VertexAIFilesConfig(VertexBase, BaseFilesConfig):
|
|||
has_error = bool(status)
|
||||
|
||||
if has_error:
|
||||
# Return error response in OpenAI format
|
||||
return {
|
||||
"id": f"batch_req_{uuid.uuid4()}",
|
||||
"custom_id": custom_id,
|
||||
"response": {
|
||||
"status_code": 400,
|
||||
"request_id": "",
|
||||
"body": {
|
||||
"error": {
|
||||
"message": status,
|
||||
"type": "vertex_ai_error",
|
||||
"code": "vertex_ai_error",
|
||||
}
|
||||
},
|
||||
},
|
||||
"response": None,
|
||||
"error": {
|
||||
"message": status,
|
||||
"type": "vertex_ai_error",
|
||||
"code": "vertex_ai_error",
|
||||
"message": status,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -789,25 +777,13 @@ class VertexAIFilesConfig(VertexBase, BaseFilesConfig):
|
|||
}
|
||||
|
||||
except Exception as e:
|
||||
# If transformation fails, return error
|
||||
return {
|
||||
"id": f"batch_req_{uuid.uuid4()}",
|
||||
"custom_id": custom_id,
|
||||
"response": {
|
||||
"status_code": 500,
|
||||
"request_id": "",
|
||||
"body": {
|
||||
"error": {
|
||||
"message": f"Failed to transform response: {str(e)}",
|
||||
"type": "transformation_error",
|
||||
"code": "transformation_error",
|
||||
}
|
||||
},
|
||||
},
|
||||
"response": None,
|
||||
"error": {
|
||||
"message": f"Failed to transform response: {str(e)}",
|
||||
"type": "transformation_error",
|
||||
"code": "transformation_error",
|
||||
"message": f"Failed to transform response: {str(e)}",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -431,12 +431,61 @@ class TestVertexBatchOutputTransformation:
|
|||
)
|
||||
result = json.loads(transformed_content.decode("utf-8"))
|
||||
|
||||
# Verify error format
|
||||
assert result["response"]["status_code"] == 400
|
||||
# Per OpenAI Batch output spec, error entries set response to null
|
||||
# and populate the top-level error object.
|
||||
assert result["response"] is None
|
||||
assert result["error"] is not None
|
||||
assert "Invalid request" in result["error"]["message"]
|
||||
assert result["error"]["code"] == "vertex_ai_error"
|
||||
assert result["custom_id"] == "request-error"
|
||||
|
||||
def test_transform_exception_path_sets_response_null(self, config):
|
||||
"""
|
||||
The except-Exception branch in _transform_single_vertex_batch_output_to_openai
|
||||
must also emit response=null per the OpenAI Batch output spec. The outer
|
||||
_try_transform path swallows exceptions and falls back to original content,
|
||||
so this test invokes the single-line transformer directly with a vertex_gemini_config
|
||||
stub that raises during transformation.
|
||||
"""
|
||||
from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import (
|
||||
VertexGeminiConfig,
|
||||
)
|
||||
|
||||
vertex_output = {
|
||||
"status": "",
|
||||
"processed_time": "2024-11-01T18:13:16.826+00:00",
|
||||
"request": {
|
||||
"contents": [{"role": "user", "parts": [{"text": "Hello world!"}]}],
|
||||
"labels": {"litellm_custom_id": "request-boom"},
|
||||
},
|
||||
"response": {"modelVersion": "gemini-2.0-flash-001@default"},
|
||||
}
|
||||
|
||||
class _RaisingGeminiConfig(VertexGeminiConfig):
|
||||
def _transform_google_generate_content_to_openai_model_response(
|
||||
self, *args, **kwargs
|
||||
):
|
||||
raise ValueError("simulated transform failure")
|
||||
|
||||
mock_response = httpx.Response(
|
||||
status_code=200,
|
||||
headers={"content-type": "application/json"},
|
||||
request=httpx.Request(method="POST", url="https://example.com"),
|
||||
)
|
||||
|
||||
result = config._transform_single_vertex_batch_output_to_openai(
|
||||
vertex_output=vertex_output,
|
||||
vertex_gemini_config=_RaisingGeminiConfig(),
|
||||
logging_obj=MagicMock(),
|
||||
mock_httpx_response=mock_response,
|
||||
)
|
||||
|
||||
assert result["response"] is None
|
||||
assert result["error"] is not None
|
||||
assert result["error"]["code"] == "transformation_error"
|
||||
assert "simulated transform failure" in result["error"]["message"]
|
||||
assert result["custom_id"] == "request-boom"
|
||||
|
||||
def test_transform_vertex_batch_output_legacy_labels_only_sanitized(self, config):
|
||||
"""Older LiteLLM batches only stored litellm_custom_id (sanitized); read path still works."""
|
||||
vertex_output = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue