mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
Fix calling vertex anthropic via /v1/messages + log anthropic model name on vertex passthrough
* fix(vertex_ai/anthropic): extract vertex credentials from correct dict Fixes passing credentials for vertex anthropic via `/v1/messages` * fix(vertex_ai/anthropic): working e2e vertex ai anthropic messages via `/v1/messages` Ensures vertex anthropic models can be called via /v1/messages * fix(vertex_passthrough_logging_handler.py): fix vertex anthropic logging to emit the model name on spend logs enables observability of passthrough route * fix(vertex_passthrough_logging_handler.py): don't redefine variable
This commit is contained in:
parent
6f2d28c8af
commit
01ce21667c
3 changed files with 29 additions and 8 deletions
|
|
@ -29,14 +29,14 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vert
|
|||
"""
|
||||
if "Authorization" not in headers:
|
||||
vertex_ai_project = (
|
||||
optional_params.pop("vertex_project", None)
|
||||
or optional_params.pop("vertex_ai_project", None)
|
||||
litellm_params.pop("vertex_project", None)
|
||||
or litellm_params.pop("vertex_ai_project", None)
|
||||
or litellm.vertex_project
|
||||
or get_secret_str("VERTEXAI_PROJECT")
|
||||
)
|
||||
vertex_credentials = (
|
||||
optional_params.pop("vertex_credentials", None)
|
||||
or optional_params.pop("vertex_ai_credentials", None)
|
||||
litellm_params.pop("vertex_credentials", None)
|
||||
or litellm_params.pop("vertex_ai_credentials", None)
|
||||
or get_secret_str("VERTEXAI_CREDENTIALS")
|
||||
)
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vert
|
|||
|
||||
api_base = self.get_complete_vertex_url(
|
||||
custom_api_base=api_base,
|
||||
vertex_location=optional_params.pop("vertex_location", None),
|
||||
vertex_location=litellm_params.pop("vertex_location", None),
|
||||
vertex_project=vertex_ai_project,
|
||||
project_id=project_id,
|
||||
partner=VertexPartnerProvider.claude,
|
||||
|
|
@ -93,4 +93,8 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vert
|
|||
)
|
||||
|
||||
anthropic_messages_request["anthropic_version"] = "vertex-2023-10-16"
|
||||
|
||||
anthropic_messages_request.pop(
|
||||
"model", None
|
||||
) # do not pass model in request body to vertex ai
|
||||
return anthropic_messages_request
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ class VertexPassthroughLoggingHandler:
|
|||
vertex_image_generation_class = VertexImageGeneration()
|
||||
|
||||
model = VertexPassthroughLoggingHandler.extract_model_from_url(url_route)
|
||||
|
||||
_json_response = httpx_response.json()
|
||||
|
||||
litellm_prediction_response: Union[
|
||||
|
|
@ -121,6 +122,20 @@ class VertexPassthroughLoggingHandler:
|
|||
"result": litellm_prediction_response,
|
||||
"kwargs": kwargs,
|
||||
}
|
||||
elif "rawPredict" in url_route or "streamRawPredict" in url_route:
|
||||
model = VertexPassthroughLoggingHandler.extract_model_from_url(url_route)
|
||||
|
||||
_json_response = httpx_response.json()
|
||||
|
||||
litellm_prediction_response = ModelResponse()
|
||||
|
||||
logging_obj.model = model
|
||||
logging_obj.model_call_details["model"] = logging_obj.model
|
||||
|
||||
return {
|
||||
"result": None,
|
||||
"kwargs": kwargs,
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"result": None,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ class PassThroughEndpointLogging:
|
|||
"generateContent",
|
||||
"streamGenerateContent",
|
||||
"predict",
|
||||
"rawPredict",
|
||||
"streamRawPredict",
|
||||
]
|
||||
|
||||
# Anthropic
|
||||
|
|
@ -101,9 +103,9 @@ class PassThroughEndpointLogging:
|
|||
standard_logging_response_object: Optional[
|
||||
PassThroughEndpointLoggingResultValues
|
||||
] = None
|
||||
logging_obj.model_call_details["passthrough_logging_payload"] = (
|
||||
passthrough_logging_payload
|
||||
)
|
||||
logging_obj.model_call_details[
|
||||
"passthrough_logging_payload"
|
||||
] = passthrough_logging_payload
|
||||
if self.is_vertex_route(url_route):
|
||||
vertex_passthrough_logging_handler_result = (
|
||||
VertexPassthroughLoggingHandler.vertex_passthrough_handler(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue