mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
Merge branch 'main' into litellm_8864-feature-vertex-anyOf-support
This commit is contained in:
commit
b72fbdde74
220 changed files with 8566 additions and 1345 deletions
|
@ -3,6 +3,7 @@ from typing import Dict, List, Literal, Optional, Tuple, Union
|
|||
|
||||
import httpx
|
||||
|
||||
import litellm
|
||||
from litellm import supports_response_schema, supports_system_messages, verbose_logger
|
||||
from litellm.llms.base_llm.chat.transformation import BaseLLMException
|
||||
from litellm.types.llms.vertex_ai import PartType
|
||||
|
@ -28,6 +29,10 @@ def get_supports_system_message(
|
|||
supports_system_message = supports_system_messages(
|
||||
model=model, custom_llm_provider=_custom_llm_provider
|
||||
)
|
||||
|
||||
# Vertex Models called in the `/gemini` request/response format also support system messages
|
||||
if litellm.VertexGeminiConfig._is_model_gemini_spec_model(model):
|
||||
supports_system_message = True
|
||||
except Exception as e:
|
||||
verbose_logger.warning(
|
||||
"Unable to identify if system message supported. Defaulting to 'False'. Received error message - {}\nAdd it here - https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json".format(
|
||||
|
@ -55,7 +60,9 @@ def get_supports_response_schema(
|
|||
|
||||
from typing import Literal, Optional
|
||||
|
||||
all_gemini_url_modes = Literal["chat", "embedding", "batch_embedding"]
|
||||
all_gemini_url_modes = Literal[
|
||||
"chat", "embedding", "batch_embedding", "image_generation"
|
||||
]
|
||||
|
||||
|
||||
def _get_vertex_url(
|
||||
|
@ -68,6 +75,8 @@ def _get_vertex_url(
|
|||
) -> Tuple[str, str]:
|
||||
url: Optional[str] = None
|
||||
endpoint: Optional[str] = None
|
||||
|
||||
model = litellm.VertexGeminiConfig.get_model_for_vertex_ai_url(model=model)
|
||||
if mode == "chat":
|
||||
### SET RUNTIME ENDPOINT ###
|
||||
endpoint = "generateContent"
|
||||
|
@ -91,7 +100,11 @@ def _get_vertex_url(
|
|||
if model.isdigit():
|
||||
# https://us-central1-aiplatform.googleapis.com/v1/projects/$PROJECT_ID/locations/us-central1/endpoints/$ENDPOINT_ID:predict
|
||||
url = f"https://{vertex_location}-aiplatform.googleapis.com/{vertex_api_version}/projects/{vertex_project}/locations/{vertex_location}/endpoints/{model}:{endpoint}"
|
||||
|
||||
elif mode == "image_generation":
|
||||
endpoint = "predict"
|
||||
url = f"https://{vertex_location}-aiplatform.googleapis.com/v1/projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/{model}:{endpoint}"
|
||||
if model.isdigit():
|
||||
url = f"https://{vertex_location}-aiplatform.googleapis.com/{vertex_api_version}/projects/{vertex_project}/locations/{vertex_location}/endpoints/{model}:{endpoint}"
|
||||
if not url or not endpoint:
|
||||
raise ValueError(f"Unable to get vertex url/endpoint for mode: {mode}")
|
||||
return url, endpoint
|
||||
|
@ -127,6 +140,10 @@ def _get_gemini_url(
|
|||
url = "https://generativelanguage.googleapis.com/v1beta/{}:{}?key={}".format(
|
||||
_gemini_model_name, endpoint, gemini_api_key
|
||||
)
|
||||
elif mode == "image_generation":
|
||||
raise ValueError(
|
||||
"LiteLLM's `gemini/` route does not support image generation yet. Let us know if you need this feature by opening an issue at https://github.com/BerriAI/litellm/issues"
|
||||
)
|
||||
|
||||
return url, endpoint
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue