diff --git a/test/collection/test_classes_generative.py b/test/collection/test_classes_generative.py index 5d9496417..bcce1d160 100644 --- a/test/collection/test_classes_generative.py +++ b/test/collection/test_classes_generative.py @@ -275,6 +275,47 @@ def test_generative_parameters_images_parsing( ), ), ), + ( + GenerativeConfig.google_vertex( + api_endpoint="http://localhost:8080", + project_id="my-project", + endpoint_id="12345678901234567890123456789012", + region="us-west1", + frequency_penalty=0.5, + max_tokens=100, + model="text-to-image", + presence_penalty=0.5, + temperature=0.5, + top_k=50, + top_p=0.9, + stop_sequences=["\n"], + location="us-central1", + )._to_grpc( + _GenerativeConfigRuntimeOptions( + return_metadata=True, images=[LOGO_ENCODED], image_properties=["image"] + ) + ), + generative_pb2.GenerativeProvider( + return_metadata=True, + google=generative_pb2.GenerativeGoogle( + api_endpoint="localhost:8080", + endpoint_id="12345678901234567890123456789012", + frequency_penalty=0.5, + max_tokens=100, + model="text-to-image", + presence_penalty=0.5, + project_id="my-project", + region="us-west1", + location="us-central1", + stop_sequences=base_pb2.TextArray(values=["\n"]), + temperature=0.5, + top_k=50, + top_p=0.9, + images=base_pb2.TextArray(values=[LOGO_ENCODED]), + image_properties=base_pb2.TextArray(values=["image"]), + ), + ), + ), ( GenerativeConfig.mistral( base_url="http://localhost:8080", diff --git a/weaviate/collections/classes/generative.py b/weaviate/collections/classes/generative.py index d5c1a5de2..f494661dd 100644 --- a/weaviate/collections/classes/generative.py +++ b/weaviate/collections/classes/generative.py @@ -423,6 +423,7 @@ class _GenerativeGoogle(_GenerativeConfigRuntime): presence_penalty: Optional[float] project_id: Optional[str] region: Optional[str] + location: Optional[str] stop_sequences: Optional[List[str]] temperature: Optional[float] top_k: Optional[int] @@ -447,6 +448,7 @@ def _to_grpc(self, opts: _GenerativeConfigRuntimeOptions) -> generative_pb2.Gene presence_penalty=self.presence_penalty, project_id=self.project_id, region=self.region, + location=self.location, stop_sequences=_to_text_array(self.stop_sequences), temperature=self.temperature, top_k=self.top_k, @@ -945,6 +947,7 @@ def google( presence_penalty=presence_penalty, project_id=project_id, region=region, + location=None, stop_sequences=stop_sequences, temperature=temperature, top_k=top_k, @@ -966,6 +969,7 @@ def google_vertex( top_k: Optional[int] = None, top_p: Optional[float] = None, stop_sequences: Optional[List[str]] = None, + location: Optional[str] = None, ) -> _GenerativeConfigRuntime: """Create a `_GenerativeGoogle` object for use when performing AI generation using the `generative-google` module. @@ -980,11 +984,17 @@ def google_vertex( model: The model ID to use. Defaults to `None`, which uses the server-defined default presence_penalty: The presence penalty to use. Defaults to `None`, which uses the server-defined default project_id: The project ID to use. Defaults to `None`, which uses the server-defined default - region: The region to use. Defaults to `None`, which uses the server-defined default + region: The region the Vertex AI endpoint is served from. For `gemini*` models this selects the API host + (`-aiplatform.googleapis.com`); for the other models the host comes from `api_endpoint` instead. + Defaults to `None`, which uses the server-defined default stop_sequences: The stop sequences to use. Defaults to `None`, which uses the server-defined default temperature: The temperature to use. Defaults to `None`, which uses the server-defined default top_k: The top K to use. Defaults to `None`, which uses the server-defined default top_p: The top P to use. Defaults to `None`, which uses the server-defined default + location: The Vertex AI location, i.e. the `locations/` segment of the request URL. This is + distinct from `region`: `region` picks the host, `location` picks the path. For `gemini*` models the + special value `"global"` selects the region-less `aiplatform.googleapis.com` host, so `region` is then + unused. Defaults to `None`, which uses the server-defined default of `us-central1` """ return _GenerativeGoogle( api_endpoint=TypeAdapter(AnyHttpUrl).validate_python(api_endpoint) @@ -997,6 +1007,7 @@ def google_vertex( presence_penalty=presence_penalty, project_id=project_id, region=region, + location=location, stop_sequences=stop_sequences, temperature=temperature, top_k=top_k, @@ -1041,6 +1052,7 @@ def google_gemini( presence_penalty=presence_penalty, project_id=None, region=None, + location=None, stop_sequences=stop_sequences, temperature=temperature, top_k=top_k,