diff --git a/google/cloud/aiplatform_v1/services/migration_service/client.py b/google/cloud/aiplatform_v1/services/migration_service/client.py index 074244583d..5d14719a74 100644 --- a/google/cloud/aiplatform_v1/services/migration_service/client.py +++ b/google/cloud/aiplatform_v1/services/migration_service/client.py @@ -293,40 +293,40 @@ def parse_dataset_path(path: str) -> Dict[str, str]: @staticmethod def dataset_path( project: str, + location: str, dataset: str, ) -> str: """Returns a fully-qualified dataset string.""" - return "projects/{project}/datasets/{dataset}".format( + return "projects/{project}/locations/{location}/datasets/{dataset}".format( project=project, + location=location, dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: """Parses a dataset path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/datasets/(?P.+?)$", path) + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", + path, + ) return m.groupdict() if m else {} @staticmethod def dataset_path( project: str, - location: str, dataset: str, ) -> str: """Returns a fully-qualified dataset string.""" - return "projects/{project}/locations/{location}/datasets/{dataset}".format( + return "projects/{project}/datasets/{dataset}".format( project=project, - location=location, dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: """Parses a dataset path into its component segments.""" - m = re.match( - r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", - path, - ) + m = re.match(r"^projects/(?P.+?)/datasets/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod diff --git a/google/cloud/aiplatform_v1/services/session_service/async_client.py b/google/cloud/aiplatform_v1/services/session_service/async_client.py index 4ccf4cd19c..8ae7bc9f23 100644 --- a/google/cloud/aiplatform_v1/services/session_service/async_client.py +++ b/google/cloud/aiplatform_v1/services/session_service/async_client.py @@ -323,6 +323,7 @@ async def create_session( *, parent: Optional[str] = None, session: Optional[gca_session.Session] = None, + session_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), @@ -380,6 +381,20 @@ async def sample_create_session(): This corresponds to the ``session`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + session_id (:class:`str`): + Optional. The user defined ID to use for session, which + will become the final component of the session resource + name. If not provided, Vertex AI will generate a value + for this ID. + + This value may be up to 63 characters, and valid + characters are ``[a-z0-9-]``. The first character must + be a letter, and the last character must be a letter or + number. + + This corresponds to the ``session_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -401,7 +416,7 @@ async def sample_create_session(): # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - flattened_params = [parent, session] + flattened_params = [parent, session, session_id] has_flattened_params = ( len([param for param in flattened_params if param is not None]) > 0 ) @@ -422,6 +437,8 @@ async def sample_create_session(): request.parent = parent if session is not None: request.session = session + if session_id is not None: + request.session_id = session_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/aiplatform_v1/services/session_service/client.py b/google/cloud/aiplatform_v1/services/session_service/client.py index 53d9ef4766..04f5d7e016 100644 --- a/google/cloud/aiplatform_v1/services/session_service/client.py +++ b/google/cloud/aiplatform_v1/services/session_service/client.py @@ -838,6 +838,7 @@ def create_session( *, parent: Optional[str] = None, session: Optional[gca_session.Session] = None, + session_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), @@ -895,6 +896,20 @@ def sample_create_session(): This corresponds to the ``session`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + session_id (str): + Optional. The user defined ID to use for session, which + will become the final component of the session resource + name. If not provided, Vertex AI will generate a value + for this ID. + + This value may be up to 63 characters, and valid + characters are ``[a-z0-9-]``. The first character must + be a letter, and the last character must be a letter or + number. + + This corresponds to the ``session_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -916,7 +931,7 @@ def sample_create_session(): # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - flattened_params = [parent, session] + flattened_params = [parent, session, session_id] has_flattened_params = ( len([param for param in flattened_params if param is not None]) > 0 ) @@ -936,6 +951,8 @@ def sample_create_session(): request.parent = parent if session is not None: request.session = session + if session_id is not None: + request.session_id = session_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/aiplatform_v1/types/session.py b/google/cloud/aiplatform_v1/types/session.py index 14d57cdc16..5b9655b1a9 100644 --- a/google/cloud/aiplatform_v1/types/session.py +++ b/google/cloud/aiplatform_v1/types/session.py @@ -166,6 +166,9 @@ class SessionEvent(proto.Message): error. event_metadata (google.cloud.aiplatform_v1.types.EventMetadata): Optional. Metadata relating to this event. + raw_event (google.protobuf.struct_pb2.Struct): + Optional. Weakly typed raw event data in + proto struct format. """ name: str = proto.Field( @@ -208,6 +211,11 @@ class SessionEvent(proto.Message): number=11, message="EventMetadata", ) + raw_event: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=12, + message=struct_pb2.Struct, + ) class EventMetadata(proto.Message): diff --git a/google/cloud/aiplatform_v1/types/session_service.py b/google/cloud/aiplatform_v1/types/session_service.py index dd0326d507..162fdddf4c 100644 --- a/google/cloud/aiplatform_v1/types/session_service.py +++ b/google/cloud/aiplatform_v1/types/session_service.py @@ -53,6 +53,14 @@ class CreateSessionRequest(proto.Message): ``projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}`` session (google.cloud.aiplatform_v1.types.Session): Required. The session to create. + session_id (str): + Optional. The user defined ID to use for session, which will + become the final component of the session resource name. If + not provided, Vertex AI will generate a value for this ID. + + This value may be up to 63 characters, and valid characters + are ``[a-z0-9-]``. The first character must be a letter, and + the last character must be a letter or number. """ parent: str = proto.Field( @@ -64,6 +72,10 @@ class CreateSessionRequest(proto.Message): number=2, message=gca_session.Session, ) + session_id: str = proto.Field( + proto.STRING, + number=3, + ) class CreateSessionOperationMetadata(proto.Message): diff --git a/google/cloud/aiplatform_v1beta1/services/memory_bank_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/memory_bank_service/async_client.py index 6f93eafef8..ac244739d4 100644 --- a/google/cloud/aiplatform_v1beta1/services/memory_bank_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/memory_bank_service/async_client.py @@ -320,6 +320,9 @@ async def create_memory( self, request: Optional[Union[memory_bank_service.CreateMemoryRequest, dict]] = None, *, + parent: Optional[str] = None, + memory: Optional[memory_bank.Memory] = None, + memory_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), @@ -364,6 +367,33 @@ async def sample_create_memory(): request (Optional[Union[google.cloud.aiplatform_v1beta1.types.CreateMemoryRequest, dict]]): The request object. Request message for [MemoryBankService.CreateMemory][google.cloud.aiplatform.v1beta1.MemoryBankService.CreateMemory]. + parent (:class:`str`): + Required. The resource name of the ReasoningEngine to + create the Memory under. Format: + ``projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + memory (:class:`google.cloud.aiplatform_v1beta1.types.Memory`): + Required. The Memory to be created. + This corresponds to the ``memory`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + memory_id (:class:`str`): + Optional. The user defined ID to use for memory, which + will become the final component of the memory resource + name. If not provided, Vertex AI will generate a value + for this ID. + + This value may be up to 63 characters, and valid + characters are ``[a-z0-9-]``. The first character must + be a letter, and the last character must be a letter or + number. + + This corresponds to the ``memory_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -382,11 +412,32 @@ async def sample_create_memory(): """ # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [parent, memory, memory_id] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + # - Use the request object if provided (there's no risk of modifying the input as # there are no flattened fields), or create one. if not isinstance(request, memory_bank_service.CreateMemoryRequest): request = memory_bank_service.CreateMemoryRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if memory is not None: + request.memory = memory + if memory_id is not None: + request.memory_id = memory_id + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._client._transport._wrapped_methods[ diff --git a/google/cloud/aiplatform_v1beta1/services/memory_bank_service/client.py b/google/cloud/aiplatform_v1beta1/services/memory_bank_service/client.py index ed4ec3309a..e045aff30f 100644 --- a/google/cloud/aiplatform_v1beta1/services/memory_bank_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/memory_bank_service/client.py @@ -836,6 +836,9 @@ def create_memory( self, request: Optional[Union[memory_bank_service.CreateMemoryRequest, dict]] = None, *, + parent: Optional[str] = None, + memory: Optional[memory_bank.Memory] = None, + memory_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), @@ -880,6 +883,33 @@ def sample_create_memory(): request (Union[google.cloud.aiplatform_v1beta1.types.CreateMemoryRequest, dict]): The request object. Request message for [MemoryBankService.CreateMemory][google.cloud.aiplatform.v1beta1.MemoryBankService.CreateMemory]. + parent (str): + Required. The resource name of the ReasoningEngine to + create the Memory under. Format: + ``projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + memory (google.cloud.aiplatform_v1beta1.types.Memory): + Required. The Memory to be created. + This corresponds to the ``memory`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + memory_id (str): + Optional. The user defined ID to use for memory, which + will become the final component of the memory resource + name. If not provided, Vertex AI will generate a value + for this ID. + + This value may be up to 63 characters, and valid + characters are ``[a-z0-9-]``. The first character must + be a letter, and the last character must be a letter or + number. + + This corresponds to the ``memory_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -898,10 +928,30 @@ def sample_create_memory(): """ # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [parent, memory, memory_id] + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + # - Use the request object if provided (there's no risk of modifying the input as # there are no flattened fields), or create one. if not isinstance(request, memory_bank_service.CreateMemoryRequest): request = memory_bank_service.CreateMemoryRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if memory is not None: + request.memory = memory + if memory_id is not None: + request.memory_id = memory_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/aiplatform_v1beta1/services/session_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/session_service/async_client.py index d365b52314..f181fde574 100644 --- a/google/cloud/aiplatform_v1beta1/services/session_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/session_service/async_client.py @@ -323,6 +323,7 @@ async def create_session( *, parent: Optional[str] = None, session: Optional[gca_session.Session] = None, + session_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), @@ -381,6 +382,20 @@ async def sample_create_session(): This corresponds to the ``session`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + session_id (:class:`str`): + Optional. The user defined ID to use for session, which + will become the final component of the session resource + name. If not provided, Vertex AI will generate a value + for this ID. + + This value may be up to 63 characters, and valid + characters are ``[a-z0-9-]``. The first character must + be a letter, and the last character must be a letter or + number. + + This corresponds to the ``session_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -402,7 +417,7 @@ async def sample_create_session(): # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - flattened_params = [parent, session] + flattened_params = [parent, session, session_id] has_flattened_params = ( len([param for param in flattened_params if param is not None]) > 0 ) @@ -423,6 +438,8 @@ async def sample_create_session(): request.parent = parent if session is not None: request.session = session + if session_id is not None: + request.session_id = session_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/aiplatform_v1beta1/services/session_service/client.py b/google/cloud/aiplatform_v1beta1/services/session_service/client.py index 392ca28df2..0f6c7d54c6 100644 --- a/google/cloud/aiplatform_v1beta1/services/session_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/session_service/client.py @@ -838,6 +838,7 @@ def create_session( *, parent: Optional[str] = None, session: Optional[gca_session.Session] = None, + session_id: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), @@ -896,6 +897,20 @@ def sample_create_session(): This corresponds to the ``session`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + session_id (str): + Optional. The user defined ID to use for session, which + will become the final component of the session resource + name. If not provided, Vertex AI will generate a value + for this ID. + + This value may be up to 63 characters, and valid + characters are ``[a-z0-9-]``. The first character must + be a letter, and the last character must be a letter or + number. + + This corresponds to the ``session_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -917,7 +932,7 @@ def sample_create_session(): # Create or coerce a protobuf request object. # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - flattened_params = [parent, session] + flattened_params = [parent, session, session_id] has_flattened_params = ( len([param for param in flattened_params if param is not None]) > 0 ) @@ -937,6 +952,8 @@ def sample_create_session(): request.parent = parent if session is not None: request.session = session + if session_id is not None: + request.session_id = session_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/aiplatform_v1beta1/types/memory_bank_service.py b/google/cloud/aiplatform_v1beta1/types/memory_bank_service.py index 7e6b1c0ee1..13ab468d63 100644 --- a/google/cloud/aiplatform_v1beta1/types/memory_bank_service.py +++ b/google/cloud/aiplatform_v1beta1/types/memory_bank_service.py @@ -58,6 +58,14 @@ class CreateMemoryRequest(proto.Message): ``projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}`` memory (google.cloud.aiplatform_v1beta1.types.Memory): Required. The Memory to be created. + memory_id (str): + Optional. The user defined ID to use for memory, which will + become the final component of the memory resource name. If + not provided, Vertex AI will generate a value for this ID. + + This value may be up to 63 characters, and valid characters + are ``[a-z0-9-]``. The first character must be a letter, and + the last character must be a letter or number. """ parent: str = proto.Field( @@ -69,6 +77,10 @@ class CreateMemoryRequest(proto.Message): number=2, message=memory_bank.Memory, ) + memory_id: str = proto.Field( + proto.STRING, + number=3, + ) class CreateMemoryOperationMetadata(proto.Message): diff --git a/google/cloud/aiplatform_v1beta1/types/session.py b/google/cloud/aiplatform_v1beta1/types/session.py index 08632760c4..a665cb5bb3 100644 --- a/google/cloud/aiplatform_v1beta1/types/session.py +++ b/google/cloud/aiplatform_v1beta1/types/session.py @@ -166,6 +166,9 @@ class SessionEvent(proto.Message): error. event_metadata (google.cloud.aiplatform_v1beta1.types.EventMetadata): Optional. Metadata relating to this event. + raw_event (google.protobuf.struct_pb2.Struct): + Optional. Weakly typed raw event data in + proto struct format. """ name: str = proto.Field( @@ -208,6 +211,11 @@ class SessionEvent(proto.Message): number=11, message="EventMetadata", ) + raw_event: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=12, + message=struct_pb2.Struct, + ) class EventMetadata(proto.Message): diff --git a/google/cloud/aiplatform_v1beta1/types/session_service.py b/google/cloud/aiplatform_v1beta1/types/session_service.py index 1c5bb3b719..be67687627 100644 --- a/google/cloud/aiplatform_v1beta1/types/session_service.py +++ b/google/cloud/aiplatform_v1beta1/types/session_service.py @@ -53,6 +53,14 @@ class CreateSessionRequest(proto.Message): ``projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}`` session (google.cloud.aiplatform_v1beta1.types.Session): Required. The session to create. + session_id (str): + Optional. The user defined ID to use for session, which will + become the final component of the session resource name. If + not provided, Vertex AI will generate a value for this ID. + + This value may be up to 63 characters, and valid characters + are ``[a-z0-9-]``. The first character must be a letter, and + the last character must be a letter or number. """ parent: str = proto.Field( @@ -64,6 +72,10 @@ class CreateSessionRequest(proto.Message): number=2, message=gca_session.Session, ) + session_id: str = proto.Field( + proto.STRING, + number=3, + ) class CreateSessionOperationMetadata(proto.Message): diff --git a/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1.json b/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1.json index 75851b50ba..00899eb0aa 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-aiplatform", - "version": "1.140.0" + "version": "0.0.0" }, "snippets": [ { @@ -44297,6 +44297,10 @@ "name": "session", "type": "google.cloud.aiplatform_v1.types.Session" }, + { + "name": "session_id", + "type": "str" + }, { "name": "retry", "type": "google.api_core.retry.Retry" @@ -44381,6 +44385,10 @@ "name": "session", "type": "google.cloud.aiplatform_v1.types.Session" }, + { + "name": "session_id", + "type": "str" + }, { "name": "retry", "type": "google.api_core.retry.Retry" diff --git a/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1beta1.json b/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1beta1.json index 981faca9aa..3a33d974f7 100644 --- a/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1beta1.json +++ b/samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-aiplatform", - "version": "1.140.0" + "version": "0.0.0" }, "snippets": [ { @@ -29616,6 +29616,18 @@ "name": "request", "type": "google.cloud.aiplatform_v1beta1.types.CreateMemoryRequest" }, + { + "name": "parent", + "type": "str" + }, + { + "name": "memory", + "type": "google.cloud.aiplatform_v1beta1.types.Memory" + }, + { + "name": "memory_id", + "type": "str" + }, { "name": "retry", "type": "google.api_core.retry.Retry" @@ -29692,6 +29704,18 @@ "name": "request", "type": "google.cloud.aiplatform_v1beta1.types.CreateMemoryRequest" }, + { + "name": "parent", + "type": "str" + }, + { + "name": "memory", + "type": "google.cloud.aiplatform_v1beta1.types.Memory" + }, + { + "name": "memory_id", + "type": "str" + }, { "name": "retry", "type": "google.api_core.retry.Retry" @@ -53208,6 +53232,10 @@ "name": "session", "type": "google.cloud.aiplatform_v1beta1.types.Session" }, + { + "name": "session_id", + "type": "str" + }, { "name": "retry", "type": "google.api_core.retry.Retry" @@ -53292,6 +53320,10 @@ "name": "session", "type": "google.cloud.aiplatform_v1beta1.types.Session" }, + { + "name": "session_id", + "type": "str" + }, { "name": "retry", "type": "google.api_core.retry.Retry" diff --git a/tests/unit/gapic/aiplatform_v1/test_migration_service.py b/tests/unit/gapic/aiplatform_v1/test_migration_service.py index 1aa93934c0..827bb18c1e 100644 --- a/tests/unit/gapic/aiplatform_v1/test_migration_service.py +++ b/tests/unit/gapic/aiplatform_v1/test_migration_service.py @@ -5623,19 +5623,22 @@ def test_parse_dataset_path(): def test_dataset_path(): project = "squid" - dataset = "clam" - expected = "projects/{project}/datasets/{dataset}".format( + location = "clam" + dataset = "whelk" + expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( project=project, + location=location, dataset=dataset, ) - actual = MigrationServiceClient.dataset_path(project, dataset) + actual = MigrationServiceClient.dataset_path(project, location, dataset) assert expected == actual def test_parse_dataset_path(): expected = { - "project": "whelk", - "dataset": "octopus", + "project": "octopus", + "location": "oyster", + "dataset": "nudibranch", } path = MigrationServiceClient.dataset_path(**expected) @@ -5645,22 +5648,19 @@ def test_parse_dataset_path(): def test_dataset_path(): - project = "oyster" - location = "nudibranch" - dataset = "cuttlefish" - expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( + project = "cuttlefish" + dataset = "mussel" + expected = "projects/{project}/datasets/{dataset}".format( project=project, - location=location, dataset=dataset, ) - actual = MigrationServiceClient.dataset_path(project, location, dataset) + actual = MigrationServiceClient.dataset_path(project, dataset) assert expected == actual def test_parse_dataset_path(): expected = { - "project": "mussel", - "location": "winkle", + "project": "winkle", "dataset": "nautilus", } path = MigrationServiceClient.dataset_path(**expected) diff --git a/tests/unit/gapic/aiplatform_v1/test_session_service.py b/tests/unit/gapic/aiplatform_v1/test_session_service.py index f27e1f13ce..6aecda95c3 100644 --- a/tests/unit/gapic/aiplatform_v1/test_session_service.py +++ b/tests/unit/gapic/aiplatform_v1/test_session_service.py @@ -1383,6 +1383,7 @@ def test_create_session_non_empty_request_with_auto_populated_field(): # if they meet the requirements of AIP 4235. request = session_service.CreateSessionRequest( parent="parent_value", + session_id="session_id_value", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1395,6 +1396,7 @@ def test_create_session_non_empty_request_with_auto_populated_field(): _, args, _ = call.mock_calls[0] assert args[0] == session_service.CreateSessionRequest( parent="parent_value", + session_id="session_id_value", ) @@ -1598,6 +1600,7 @@ def test_create_session_flattened(): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) # Establish that the underlying call was made with the expected @@ -1610,6 +1613,9 @@ def test_create_session_flattened(): arg = args[0].session mock_val = gca_session.Session(expire_time=timestamp_pb2.Timestamp(seconds=751)) assert arg == mock_val + arg = args[0].session_id + mock_val = "session_id_value" + assert arg == mock_val def test_create_session_flattened_error(): @@ -1626,6 +1632,7 @@ def test_create_session_flattened_error(): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) @@ -1650,6 +1657,7 @@ async def test_create_session_flattened_async(): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) # Establish that the underlying call was made with the expected @@ -1662,6 +1670,9 @@ async def test_create_session_flattened_async(): arg = args[0].session mock_val = gca_session.Session(expire_time=timestamp_pb2.Timestamp(seconds=751)) assert arg == mock_val + arg = args[0].session_id + mock_val = "session_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1679,6 +1690,7 @@ async def test_create_session_flattened_error_async(): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) @@ -4117,6 +4129,8 @@ def test_create_session_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() ).create_session._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("session_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -4170,7 +4184,7 @@ def test_create_session_rest_unset_required_fields(): unset_fields = transport.create_session._get_unset_required_fields({}) assert set(unset_fields) == ( - set(()) + set(("sessionId",)) & set( ( "parent", @@ -4202,6 +4216,7 @@ def test_create_session_rest_flattened(): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) mock_args.update(sample_request) @@ -4241,6 +4256,7 @@ def test_create_session_rest_flattened_error(transport: str = "rest"): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) @@ -7106,6 +7122,7 @@ def test_append_event_rest_call_success(request_type): "input_transcription": {"text": "text_value", "finished": True}, "output_transcription": {}, }, + "raw_event": {}, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency @@ -9328,6 +9345,7 @@ async def test_append_event_rest_asyncio_call_success(request_type): "input_transcription": {"text": "text_value", "finished": True}, "output_transcription": {}, }, + "raw_event": {}, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_memory_bank_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_memory_bank_service.py index 14a199d290..991896577d 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_memory_bank_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_memory_bank_service.py @@ -1420,6 +1420,7 @@ def test_create_memory_non_empty_request_with_auto_populated_field(): # if they meet the requirements of AIP 4235. request = memory_bank_service.CreateMemoryRequest( parent="parent_value", + memory_id="memory_id_value", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1432,6 +1433,7 @@ def test_create_memory_non_empty_request_with_auto_populated_field(): _, args, _ = call.mock_calls[0] assert args[0] == memory_bank_service.CreateMemoryRequest( parent="parent_value", + memory_id="memory_id_value", ) @@ -1620,6 +1622,108 @@ async def test_create_memory_field_headers_async(): ) in kw["metadata"] +def test_create_memory_flattened(): + client = MemoryBankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_memory), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_memory( + parent="parent_value", + memory=memory_bank.Memory(expire_time=timestamp_pb2.Timestamp(seconds=751)), + memory_id="memory_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].memory + mock_val = memory_bank.Memory(expire_time=timestamp_pb2.Timestamp(seconds=751)) + assert arg == mock_val + arg = args[0].memory_id + mock_val = "memory_id_value" + assert arg == mock_val + + +def test_create_memory_flattened_error(): + client = MemoryBankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_memory( + memory_bank_service.CreateMemoryRequest(), + parent="parent_value", + memory=memory_bank.Memory(expire_time=timestamp_pb2.Timestamp(seconds=751)), + memory_id="memory_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_memory_flattened_async(): + client = MemoryBankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_memory), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_memory( + parent="parent_value", + memory=memory_bank.Memory(expire_time=timestamp_pb2.Timestamp(seconds=751)), + memory_id="memory_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].memory + mock_val = memory_bank.Memory(expire_time=timestamp_pb2.Timestamp(seconds=751)) + assert arg == mock_val + arg = args[0].memory_id + mock_val = "memory_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_memory_flattened_error_async(): + client = MemoryBankServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_memory( + memory_bank_service.CreateMemoryRequest(), + parent="parent_value", + memory=memory_bank.Memory(expire_time=timestamp_pb2.Timestamp(seconds=751)), + memory_id="memory_id_value", + ) + + @pytest.mark.parametrize( "request_type", [ @@ -3885,6 +3989,8 @@ def test_create_memory_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() ).create_memory._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("memory_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -3938,7 +4044,7 @@ def test_create_memory_rest_unset_required_fields(): unset_fields = transport.create_memory._get_unset_required_fields({}) assert set(unset_fields) == ( - set(()) + set(("memoryId",)) & set( ( "parent", @@ -3948,6 +4054,68 @@ def test_create_memory_rest_unset_required_fields(): ) +def test_create_memory_rest_flattened(): + client = MemoryBankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "parent": "projects/sample1/locations/sample2/reasoningEngines/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + memory=memory_bank.Memory(expire_time=timestamp_pb2.Timestamp(seconds=751)), + memory_id="memory_id_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.create_memory(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1beta1/{parent=projects/*/locations/*/reasoningEngines/*}/memories" + % client.transport._host, + args[1], + ) + + +def test_create_memory_rest_flattened_error(transport: str = "rest"): + client = MemoryBankServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_memory( + memory_bank_service.CreateMemoryRequest(), + parent="parent_value", + memory=memory_bank.Memory(expire_time=timestamp_pb2.Timestamp(seconds=751)), + memory_id="memory_id_value", + ) + + def test_get_memory_rest_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_session_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_session_service.py index a81eb014f7..aad1d9c186 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_session_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_session_service.py @@ -1385,6 +1385,7 @@ def test_create_session_non_empty_request_with_auto_populated_field(): # if they meet the requirements of AIP 4235. request = session_service.CreateSessionRequest( parent="parent_value", + session_id="session_id_value", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1397,6 +1398,7 @@ def test_create_session_non_empty_request_with_auto_populated_field(): _, args, _ = call.mock_calls[0] assert args[0] == session_service.CreateSessionRequest( parent="parent_value", + session_id="session_id_value", ) @@ -1600,6 +1602,7 @@ def test_create_session_flattened(): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) # Establish that the underlying call was made with the expected @@ -1612,6 +1615,9 @@ def test_create_session_flattened(): arg = args[0].session mock_val = gca_session.Session(expire_time=timestamp_pb2.Timestamp(seconds=751)) assert arg == mock_val + arg = args[0].session_id + mock_val = "session_id_value" + assert arg == mock_val def test_create_session_flattened_error(): @@ -1628,6 +1634,7 @@ def test_create_session_flattened_error(): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) @@ -1652,6 +1659,7 @@ async def test_create_session_flattened_async(): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) # Establish that the underlying call was made with the expected @@ -1664,6 +1672,9 @@ async def test_create_session_flattened_async(): arg = args[0].session mock_val = gca_session.Session(expire_time=timestamp_pb2.Timestamp(seconds=751)) assert arg == mock_val + arg = args[0].session_id + mock_val = "session_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1681,6 +1692,7 @@ async def test_create_session_flattened_error_async(): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) @@ -4119,6 +4131,8 @@ def test_create_session_rest_required_fields( unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() ).create_session._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("session_id",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone @@ -4172,7 +4186,7 @@ def test_create_session_rest_unset_required_fields(): unset_fields = transport.create_session._get_unset_required_fields({}) assert set(unset_fields) == ( - set(()) + set(("sessionId",)) & set( ( "parent", @@ -4204,6 +4218,7 @@ def test_create_session_rest_flattened(): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) mock_args.update(sample_request) @@ -4243,6 +4258,7 @@ def test_create_session_rest_flattened_error(transport: str = "rest"): session=gca_session.Session( expire_time=timestamp_pb2.Timestamp(seconds=751) ), + session_id="session_id_value", ) @@ -7112,6 +7128,7 @@ def test_append_event_rest_call_success(request_type): "input_transcription": {"text": "text_value", "finished": True}, "output_transcription": {}, }, + "raw_event": {}, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency @@ -9338,6 +9355,7 @@ async def test_append_event_rest_asyncio_call_success(request_type): "input_transcription": {"text": "text_value", "finished": True}, "output_transcription": {}, }, + "raw_event": {}, } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency