Improve how we're deprecating location and project_id in GoogleVertexLLMService, allowing user code to (correctly) continue referring to GoogleVertexLLMService.InputParams.
Also fix the slightly wrong (but so far harmless) pattern of initializing `OpenAILLMService.InputParams()` in the `GoogleVertexLLMService` if `params` wasn't provided—we should be letting the superclass decide what to do if the argument isn't specified.
This commit is contained in:
@@ -51,32 +51,45 @@ class GoogleVertexLLMService(OpenAILLMService):
|
|||||||
class InputParams(OpenAILLMService.InputParams):
|
class InputParams(OpenAILLMService.InputParams):
|
||||||
"""Input parameters specific to Vertex AI.
|
"""Input parameters specific to Vertex AI.
|
||||||
|
|
||||||
.. deprecated:: 0.0.90
|
|
||||||
Use `OpenAILLMService.InputParams` instead and provide `location` and
|
|
||||||
`project_id` as direct arguments to `GoogleVertexLLMService.__init__()`.
|
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
location: GCP region for Vertex AI endpoint (e.g., "us-east4").
|
location: GCP region for Vertex AI endpoint (e.g., "us-east4").
|
||||||
|
|
||||||
|
.. deprecated:: 0.0.90
|
||||||
|
Use `location` as a direct argument to
|
||||||
|
`GoogleVertexLLMService.__init__()` instead.
|
||||||
|
|
||||||
project_id: Google Cloud project ID.
|
project_id: Google Cloud project ID.
|
||||||
|
|
||||||
|
.. deprecated:: 0.0.90
|
||||||
|
Use `project_id` as a direct argument to
|
||||||
|
`GoogleVertexLLMService.__init__()` instead.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations
|
# https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations
|
||||||
location: str = "us-east4"
|
location: Optional[str] = None
|
||||||
project_id: str
|
project_id: Optional[str] = None
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
"""Initializes the InputParams."""
|
"""Initializes the InputParams."""
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("ignore", DeprecationWarning)
|
warnings.simplefilter("always")
|
||||||
warnings.warn(
|
if "location" in kwargs and kwargs["location"] is not None:
|
||||||
"GoogleVertexLLMService.InputParams is deprecated. "
|
warnings.warn(
|
||||||
"Please use OpenAILLMService.InputParams instead and provide "
|
"GoogleVertexLLMService.InputParams.location is deprecated. "
|
||||||
"'location' and 'project_id' as direct arguments to __init__.",
|
"Please provide 'location' as a direct argument to GoogleVertexLLMService.__init__() instead.",
|
||||||
DeprecationWarning,
|
DeprecationWarning,
|
||||||
stacklevel=2,
|
stacklevel=2,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if "project_id" in kwargs and kwargs["project_id"] is not None:
|
||||||
|
warnings.warn(
|
||||||
|
"GoogleVertexLLMService.InputParams.project_id is deprecated. "
|
||||||
|
"Please provide 'project_id' as a direct argument to GoogleVertexLLMService.__init__() instead.",
|
||||||
|
DeprecationWarning,
|
||||||
|
stacklevel=2,
|
||||||
|
)
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -87,7 +100,6 @@ class GoogleVertexLLMService(OpenAILLMService):
|
|||||||
model: str = "google/gemini-2.0-flash-001",
|
model: str = "google/gemini-2.0-flash-001",
|
||||||
location: Optional[str] = None,
|
location: Optional[str] = None,
|
||||||
project_id: Optional[str] = None,
|
project_id: Optional[str] = None,
|
||||||
params: Optional[InputParams] = None,
|
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""Initializes the VertexLLMService.
|
"""Initializes the VertexLLMService.
|
||||||
@@ -98,17 +110,13 @@ class GoogleVertexLLMService(OpenAILLMService):
|
|||||||
model: Model identifier (e.g., "google/gemini-2.0-flash-001").
|
model: Model identifier (e.g., "google/gemini-2.0-flash-001").
|
||||||
location: GCP region for Vertex AI endpoint (e.g., "us-east4").
|
location: GCP region for Vertex AI endpoint (e.g., "us-east4").
|
||||||
project_id: Google Cloud project ID.
|
project_id: Google Cloud project ID.
|
||||||
params: Vertex AI input parameters including location and project.
|
|
||||||
|
|
||||||
.. deprecated:: 0.0.90
|
|
||||||
Use `OpenAILLMService.InputParams` instead and provide `location`
|
|
||||||
and `project_id` as direct arguments to `__init__()`.
|
|
||||||
|
|
||||||
**kwargs: Additional arguments passed to OpenAILLMService.
|
**kwargs: Additional arguments passed to OpenAILLMService.
|
||||||
"""
|
"""
|
||||||
# Handle deprecated InputParams
|
# Handle deprecated InputParams fields
|
||||||
if params is not None and isinstance(params, GoogleVertexLLMService.InputParams):
|
if "params" in kwargs and isinstance(kwargs["params"], GoogleVertexLLMService.InputParams):
|
||||||
# Extract location and project_id from params if not provided directly
|
params = kwargs["params"]
|
||||||
|
# Extract location and project_id from params if not provided
|
||||||
|
# directly, for backward compatibility
|
||||||
if project_id is None:
|
if project_id is None:
|
||||||
project_id = params.project_id
|
project_id = params.project_id
|
||||||
if location is None:
|
if location is None:
|
||||||
@@ -117,15 +125,15 @@ class GoogleVertexLLMService(OpenAILLMService):
|
|||||||
params = OpenAILLMService.InputParams(
|
params = OpenAILLMService.InputParams(
|
||||||
**params.model_dump(exclude={"location", "project_id"}, exclude_unset=True)
|
**params.model_dump(exclude={"location", "project_id"}, exclude_unset=True)
|
||||||
)
|
)
|
||||||
else:
|
kwargs["params"] = params
|
||||||
params = params or OpenAILLMService.InputParams()
|
|
||||||
|
|
||||||
# Validate parameters
|
# Validate project_id and location parameters
|
||||||
# NOTE: once we remove deprecated InputParams, we can update __init__()
|
# NOTE: once we remove Vertex-spcific InputParams class, we can update
|
||||||
# signature with the following:
|
# __init__() signature as follows:
|
||||||
# - location: str = "us-east4",
|
# - location: str = "us-east4",
|
||||||
# - project_id: str,
|
# - project_id: str,
|
||||||
# For now, we need them as-is to maintain backward compatibility.
|
# But for now, we need them as-is to maintain proper backward
|
||||||
|
# compatibility.
|
||||||
if project_id is None:
|
if project_id is None:
|
||||||
raise ValueError("project_id is required")
|
raise ValueError("project_id is required")
|
||||||
if location is None:
|
if location is None:
|
||||||
@@ -138,7 +146,6 @@ class GoogleVertexLLMService(OpenAILLMService):
|
|||||||
api_key=self._api_key,
|
api_key=self._api_key,
|
||||||
base_url=base_url,
|
base_url=base_url,
|
||||||
model=model,
|
model=model,
|
||||||
params=params,
|
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user