Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified AiPlatform/metadata/V1/ModelGardenService.php
Binary file not shown.
84 changes: 84 additions & 0 deletions AiPlatform/samples/V1/ModelGardenServiceClient/deploy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START aiplatform_v1_generated_ModelGardenService_Deploy_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\AIPlatform\V1\Client\ModelGardenServiceClient;
use Google\Cloud\AIPlatform\V1\DeployRequest;
use Google\Cloud\AIPlatform\V1\DeployResponse;
use Google\Rpc\Status;

/**
* Deploys a model to a new endpoint.
*
* @param string $formattedDestination The resource name of the Location to deploy the model in.
* Format: `projects/{project}/locations/{location}`
* Please see {@see ModelGardenServiceClient::locationName()} for help formatting this field.
*/
function deploy_sample(string $formattedDestination): void
{
// Create a client.
$modelGardenServiceClient = new ModelGardenServiceClient();

// Prepare the request message.
$request = (new DeployRequest())
->setDestination($formattedDestination);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $modelGardenServiceClient->deploy($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
/** @var DeployResponse $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedDestination = ModelGardenServiceClient::locationName('[PROJECT]', '[LOCATION]');

deploy_sample($formattedDestination);
}
// [END aiplatform_v1_generated_ModelGardenService_Deploy_sync]
122 changes: 122 additions & 0 deletions AiPlatform/src/V1/Client/ModelGardenServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
use Google\ApiCore\ApiException;
use Google\ApiCore\CredentialsWrapper;
use Google\ApiCore\GapicClientTrait;
use Google\ApiCore\OperationResponse;
use Google\ApiCore\PagedListResponse;
use Google\ApiCore\ResourceHelperTrait;
use Google\ApiCore\RetrySettings;
use Google\ApiCore\Transport\TransportInterface;
use Google\ApiCore\ValidationException;
use Google\Auth\FetchAuthTokenInterface;
use Google\Cloud\AIPlatform\V1\DeployRequest;
use Google\Cloud\AIPlatform\V1\GetPublisherModelRequest;
use Google\Cloud\AIPlatform\V1\PublisherModel;
use Google\Cloud\Iam\V1\GetIamPolicyRequest;
Expand All @@ -43,6 +45,8 @@
use Google\Cloud\Location\GetLocationRequest;
use Google\Cloud\Location\ListLocationsRequest;
use Google\Cloud\Location\Location;
use Google\LongRunning\Client\OperationsClient;
use Google\LongRunning\Operation;
use GuzzleHttp\Promise\PromiseInterface;
use Psr\Log\LoggerInterface;

Expand All @@ -57,6 +61,7 @@
* name, and additionally a parseName method to extract the individual identifiers
* contained within formatted names that are returned by the API.
*
* @method PromiseInterface<OperationResponse> deployAsync(DeployRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PublisherModel> getPublisherModelAsync(GetPublisherModelRequest $request, array $optionalArgs = [])
* @method PromiseInterface<Location> getLocationAsync(GetLocationRequest $request, array $optionalArgs = [])
* @method PromiseInterface<PagedListResponse> listLocationsAsync(ListLocationsRequest $request, array $optionalArgs = [])
Expand Down Expand Up @@ -91,6 +96,8 @@ final class ModelGardenServiceClient
/** The default scopes required by the service. */
public static $serviceScopes = ['https://www.googleapis.com/auth/cloud-platform'];

private $operationsClient;

private static function getClientDefaults()
{
return [
Expand All @@ -110,6 +117,73 @@ private static function getClientDefaults()
];
}

/**
* Return an OperationsClient object with the same endpoint as $this.
*
* @return OperationsClient
*/
public function getOperationsClient()
{
return $this->operationsClient;
}

/**
* Resume an existing long running operation that was previously started by a long
* running API method. If $methodName is not provided, or does not match a long
* running API method, then the operation can still be resumed, but the
* OperationResponse object will not deserialize the final response.
*
* @param string $operationName The name of the long running operation
* @param string $methodName The name of the method used to start the operation
*
* @return OperationResponse
*/
public function resumeOperation($operationName, $methodName = null)
{
$options = isset($this->descriptors[$methodName]['longRunning'])
? $this->descriptors[$methodName]['longRunning']
: [];
$operation = new OperationResponse($operationName, $this->getOperationsClient(), $options);
$operation->reload();
return $operation;
}

/**
* Create the default operation client for the service.
*
* @param array $options ClientOptions for the client.
*
* @return OperationsClient
*/
private function createOperationsClient(array $options)
{
// Unset client-specific configuration options
unset($options['serviceName'], $options['clientConfig'], $options['descriptorsConfigPath']);

if (isset($options['operationsClient'])) {
return $options['operationsClient'];
}

return new OperationsClient($options);
}

/**
* Formats a string containing the fully-qualified path to represent a location
* resource.
*
* @param string $project
* @param string $location
*
* @return string The formatted location resource.
*/
public static function locationName(string $project, string $location): string
{
return self::getPathTemplate('location')->render([
'project' => $project,
'location' => $location,
]);
}

/**
* Formats a string containing the fully-qualified path to represent a
* publisher_model resource.
Expand All @@ -127,11 +201,32 @@ public static function publisherModelName(string $publisher, string $model): str
]);
}

/**
* Formats a string containing the fully-qualified path to represent a reservation
* resource.
*
* @param string $projectIdOrNumber
* @param string $zone
* @param string $reservationName
*
* @return string The formatted reservation resource.
*/
public static function reservationName(string $projectIdOrNumber, string $zone, string $reservationName): string
{
return self::getPathTemplate('reservation')->render([
'project_id_or_number' => $projectIdOrNumber,
'zone' => $zone,
'reservation_name' => $reservationName,
]);
}

/**
* Parses a formatted name string and returns an associative array of the components in the name.
* The following name formats are supported:
* Template: Pattern
* - location: projects/{project}/locations/{location}
* - publisherModel: publishers/{publisher}/models/{model}
* - reservation: projects/{project_id_or_number}/zones/{zone}/reservations/{reservation_name}
*
* The optional $template argument can be supplied to specify a particular pattern,
* and must match one of the templates listed above. If no $template argument is
Expand Down Expand Up @@ -218,6 +313,7 @@ public function __construct(array $options = [])
{
$clientOptions = $this->buildClientOptions($options);
$this->setClientOptions($clientOptions);
$this->operationsClient = $this->createOperationsClient($clientOptions);
}

/** Handles execution of the async variants for each documented method. */
Expand All @@ -231,6 +327,32 @@ public function __call($method, $args)
return call_user_func_array([$this, 'startAsyncCall'], $args);
}

/**
* Deploys a model to a new endpoint.
*
* The async variant is {@see ModelGardenServiceClient::deployAsync()} .
*
* @example samples/V1/ModelGardenServiceClient/deploy.php
*
* @param DeployRequest $request A request to house fields associated with the call.
* @param array $callOptions {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return OperationResponse
*
* @throws ApiException Thrown if the API call fails.
*/
public function deploy(DeployRequest $request, array $callOptions = []): OperationResponse
{
return $this->startApiCall('Deploy', $request, $callOptions)->wait();
}

/**
* Gets a Model Garden publisher model.
*
Expand Down
Loading
Loading