forked from phoenix/litellm-mirror
(patch) using image_urls with vertex/anthropic
models (#6775)
* fix is_pdf_used check anthropic * fix validate_environment * add comment on is_vertex_request
This commit is contained in:
parent
401531a8c9
commit
0c7360d470
2 changed files with 17 additions and 7 deletions
|
@ -60,6 +60,7 @@ def validate_environment(
|
||||||
user_headers,
|
user_headers,
|
||||||
model,
|
model,
|
||||||
messages: List[AllMessageValues],
|
messages: List[AllMessageValues],
|
||||||
|
is_vertex_request: bool,
|
||||||
tools: Optional[List[AllAnthropicToolsValues]],
|
tools: Optional[List[AllAnthropicToolsValues]],
|
||||||
anthropic_version: Optional[str] = None,
|
anthropic_version: Optional[str] = None,
|
||||||
):
|
):
|
||||||
|
@ -80,6 +81,7 @@ def validate_environment(
|
||||||
prompt_caching_set=prompt_caching_set,
|
prompt_caching_set=prompt_caching_set,
|
||||||
pdf_used=pdf_used,
|
pdf_used=pdf_used,
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
|
is_vertex_request=is_vertex_request,
|
||||||
)
|
)
|
||||||
|
|
||||||
if user_headers is not None and isinstance(user_headers, dict):
|
if user_headers is not None and isinstance(user_headers, dict):
|
||||||
|
@ -486,19 +488,20 @@ class AnthropicChatCompletion(BaseLLM):
|
||||||
headers={},
|
headers={},
|
||||||
client=None,
|
client=None,
|
||||||
):
|
):
|
||||||
|
optional_params = copy.deepcopy(optional_params)
|
||||||
|
stream = optional_params.pop("stream", None)
|
||||||
|
json_mode: bool = optional_params.pop("json_mode", False)
|
||||||
|
is_vertex_request: bool = optional_params.pop("is_vertex_request", False)
|
||||||
|
_is_function_call = False
|
||||||
|
messages = copy.deepcopy(messages)
|
||||||
headers = validate_environment(
|
headers = validate_environment(
|
||||||
api_key,
|
api_key,
|
||||||
headers,
|
headers,
|
||||||
model,
|
model,
|
||||||
messages=messages,
|
messages=messages,
|
||||||
tools=optional_params.get("tools"),
|
tools=optional_params.get("tools"),
|
||||||
|
is_vertex_request=is_vertex_request,
|
||||||
)
|
)
|
||||||
_is_function_call = False
|
|
||||||
messages = copy.deepcopy(messages)
|
|
||||||
optional_params = copy.deepcopy(optional_params)
|
|
||||||
stream = optional_params.pop("stream", None)
|
|
||||||
json_mode: bool = optional_params.pop("json_mode", False)
|
|
||||||
is_vertex_request: bool = optional_params.pop("is_vertex_request", False)
|
|
||||||
|
|
||||||
data = AnthropicConfig()._transform_request(
|
data = AnthropicConfig()._transform_request(
|
||||||
model=model,
|
model=model,
|
||||||
|
|
|
@ -107,6 +107,7 @@ class AnthropicConfig:
|
||||||
computer_tool_used: bool = False,
|
computer_tool_used: bool = False,
|
||||||
prompt_caching_set: bool = False,
|
prompt_caching_set: bool = False,
|
||||||
pdf_used: bool = False,
|
pdf_used: bool = False,
|
||||||
|
is_vertex_request: bool = False,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
@ -123,8 +124,13 @@ class AnthropicConfig:
|
||||||
"accept": "application/json",
|
"accept": "application/json",
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
}
|
}
|
||||||
if len(betas) > 0:
|
|
||||||
|
# Don't send any beta headers to Vertex, Vertex has failed requests when they are sent
|
||||||
|
if is_vertex_request is True:
|
||||||
|
pass
|
||||||
|
elif len(betas) > 0:
|
||||||
headers["anthropic-beta"] = ",".join(betas)
|
headers["anthropic-beta"] = ",".join(betas)
|
||||||
|
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
def _map_tool_choice(
|
def _map_tool_choice(
|
||||||
|
@ -403,6 +409,7 @@ class AnthropicConfig:
|
||||||
def is_pdf_used(self, messages: List[AllMessageValues]) -> bool:
|
def is_pdf_used(self, messages: List[AllMessageValues]) -> bool:
|
||||||
"""
|
"""
|
||||||
Set to true if media passed into messages.
|
Set to true if media passed into messages.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for message in messages:
|
for message in messages:
|
||||||
if (
|
if (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue