Skip to content

Commit

Permalink
feat: add TunedModelRef and RebaseTunedModel Api for Vertex GenAiTuni…
Browse files Browse the repository at this point in the history
…ngService (#7692)

docs: limit comment `SupervisedTuningSpec` for 1p tuning
PiperOrigin-RevId: 676969679
Source-Link: googleapis/googleapis@2a98f79
Source-Link: googleapis/googleapis-gen@eb6e7f5
Copy-Tag: eyJwIjoiQWlQbGF0Zm9ybS8uT3dsQm90LnlhbWwiLCJoIjoiZWI2ZTdmNTk1YTg2YjM4NWYxZjQ1OTNlNDNjYmUxMDE1YzI5ZWY3OSJ9
  • Loading branch information
gcf-owl-bot[bot] authored Sep 23, 2024
1 parent 55bcd8c commit d49e04c
Show file tree
Hide file tree
Showing 13 changed files with 891 additions and 5 deletions.
23 changes: 19 additions & 4 deletions AiPlatform/metadata/V1/GenaiTuningService.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified AiPlatform/metadata/V1/TuningJob.php
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/*
* Copyright 2024 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_GenAiTuningService_RebaseTunedModel_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\AIPlatform\V1\Client\GenAiTuningServiceClient;
use Google\Cloud\AIPlatform\V1\RebaseTunedModelRequest;
use Google\Cloud\AIPlatform\V1\TunedModelRef;
use Google\Cloud\AIPlatform\V1\TuningJob;
use Google\Rpc\Status;

/**
* Rebase a TunedModel.
* Creates a LongRunningOperation that takes a legacy Tuned GenAI model
* Reference and creates a TuningJob based on newly available model.
*
* @param string $formattedParent The resource name of the Location into which to rebase the Model.
* Format: `projects/{project}/locations/{location}`
* Please see {@see GenAiTuningServiceClient::locationName()} for help formatting this field.
*/
function rebase_tuned_model_sample(string $formattedParent): void
{
// Create a client.
$genAiTuningServiceClient = new GenAiTuningServiceClient();

// Prepare the request message.
$tunedModelRef = new TunedModelRef();
$request = (new RebaseTunedModelRequest())
->setParent($formattedParent)
->setTunedModelRef($tunedModelRef);

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

if ($response->operationSucceeded()) {
/** @var TuningJob $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
{
$formattedParent = GenAiTuningServiceClient::locationName('[PROJECT]', '[LOCATION]');

rebase_tuned_model_sample($formattedParent);
}
// [END aiplatform_v1_generated_GenAiTuningService_RebaseTunedModel_sync]
106 changes: 106 additions & 0 deletions AiPlatform/src/V1/Client/GenAiTuningServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand All @@ -37,6 +38,7 @@
use Google\Cloud\AIPlatform\V1\CreateTuningJobRequest;
use Google\Cloud\AIPlatform\V1\GetTuningJobRequest;
use Google\Cloud\AIPlatform\V1\ListTuningJobsRequest;
use Google\Cloud\AIPlatform\V1\RebaseTunedModelRequest;
use Google\Cloud\AIPlatform\V1\TuningJob;
use Google\Cloud\Iam\V1\GetIamPolicyRequest;
use Google\Cloud\Iam\V1\Policy;
Expand All @@ -46,6 +48,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;

/**
Expand All @@ -63,6 +67,7 @@
* @method PromiseInterface createTuningJobAsync(CreateTuningJobRequest $request, array $optionalArgs = [])
* @method PromiseInterface getTuningJobAsync(GetTuningJobRequest $request, array $optionalArgs = [])
* @method PromiseInterface listTuningJobsAsync(ListTuningJobsRequest $request, array $optionalArgs = [])
* @method PromiseInterface rebaseTunedModelAsync(RebaseTunedModelRequest $request, array $optionalArgs = [])
* @method PromiseInterface getLocationAsync(GetLocationRequest $request, array $optionalArgs = [])
* @method PromiseInterface listLocationsAsync(ListLocationsRequest $request, array $optionalArgs = [])
* @method PromiseInterface getIamPolicyAsync(GetIamPolicyRequest $request, array $optionalArgs = [])
Expand Down Expand Up @@ -96,6 +101,8 @@ final class GenAiTuningServiceClient
/** 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 @@ -115,6 +122,56 @@ 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 context
* resource.
Expand Down Expand Up @@ -195,6 +252,25 @@ public static function modelName(string $project, string $location, string $mode
]);
}

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

/**
* Formats a string containing the fully-qualified path to represent a
* project_location_endpoint resource.
Expand Down Expand Up @@ -266,6 +342,7 @@ public static function tuningJobName(string $project, string $location, string $
* - endpoint: projects/{project}/locations/{location}/endpoints/{endpoint}
* - location: projects/{project}/locations/{location}
* - model: projects/{project}/locations/{location}/models/{model}
* - pipelineJob: projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}
* - projectLocationEndpoint: projects/{project}/locations/{location}/endpoints/{endpoint}
* - projectLocationPublisherModel: projects/{project}/locations/{location}/publishers/{publisher}/models/{model}
* - tuningJob: projects/{project}/locations/{location}/tuningJobs/{tuning_job}
Expand Down Expand Up @@ -346,6 +423,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 Down Expand Up @@ -473,6 +551,34 @@ public function listTuningJobs(ListTuningJobsRequest $request, array $callOption
return $this->startApiCall('ListTuningJobs', $request, $callOptions);
}

/**
* Rebase a TunedModel.
* Creates a LongRunningOperation that takes a legacy Tuned GenAI model
* Reference and creates a TuningJob based on newly available model.
*
* The async variant is {@see GenAiTuningServiceClient::rebaseTunedModelAsync()} .
*
* @example samples/V1/GenAiTuningServiceClient/rebase_tuned_model.php
*
* @param RebaseTunedModelRequest $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 rebaseTunedModel(RebaseTunedModelRequest $request, array $callOptions = []): OperationResponse
{
return $this->startApiCall('RebaseTunedModel', $request, $callOptions)->wait();
}

/**
* Gets information about a location.
*
Expand Down
78 changes: 78 additions & 0 deletions AiPlatform/src/V1/RebaseTunedModelOperationMetadata.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d49e04c

Please sign in to comment.