cloud.google.com/go/aiplatform@v1.106.0/apiv1/gen_ai_tuning_client.go (about) 1 // Copyright 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17 package aiplatform 18 19 import ( 20 "context" 21 "fmt" 22 "log/slog" 23 "math" 24 "net/url" 25 26 aiplatformpb "cloud.google.com/go/aiplatform/apiv1/aiplatformpb" 27 iampb "cloud.google.com/go/iam/apiv1/iampb" 28 "cloud.google.com/go/longrunning" 29 lroauto "cloud.google.com/go/longrunning/autogen" 30 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 31 gax "github.com/googleapis/gax-go/v2" 32 "google.golang.org/api/iterator" 33 "google.golang.org/api/option" 34 "google.golang.org/api/option/internaloption" 35 gtransport "google.golang.org/api/transport/grpc" 36 locationpb "google.golang.org/genproto/googleapis/cloud/location" 37 "google.golang.org/grpc" 38 "google.golang.org/protobuf/proto" 39 ) 40 41 var newGenAiTuningClientHook clientHook 42 43 // GenAiTuningCallOptions contains the retry settings for each method of GenAiTuningClient. 44 type GenAiTuningCallOptions struct { 45 CreateTuningJob []gax.CallOption 46 GetTuningJob []gax.CallOption 47 ListTuningJobs []gax.CallOption 48 CancelTuningJob []gax.CallOption 49 RebaseTunedModel []gax.CallOption 50 GetLocation []gax.CallOption 51 ListLocations []gax.CallOption 52 GetIamPolicy []gax.CallOption 53 SetIamPolicy []gax.CallOption 54 TestIamPermissions []gax.CallOption 55 CancelOperation []gax.CallOption 56 DeleteOperation []gax.CallOption 57 GetOperation []gax.CallOption 58 ListOperations []gax.CallOption 59 WaitOperation []gax.CallOption 60 } 61 62 func defaultGenAiTuningGRPCClientOptions() []option.ClientOption { 63 return []option.ClientOption{ 64 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 65 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 66 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 67 internaloption.WithDefaultUniverseDomain("googleapis.com"), 68 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 69 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 70 internaloption.EnableJwtWithScope(), 71 internaloption.EnableNewAuthLibrary(), 72 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 73 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 74 } 75 } 76 77 func defaultGenAiTuningCallOptions() *GenAiTuningCallOptions { 78 return &GenAiTuningCallOptions{ 79 CreateTuningJob: []gax.CallOption{}, 80 GetTuningJob: []gax.CallOption{}, 81 ListTuningJobs: []gax.CallOption{}, 82 CancelTuningJob: []gax.CallOption{}, 83 RebaseTunedModel: []gax.CallOption{}, 84 GetLocation: []gax.CallOption{}, 85 ListLocations: []gax.CallOption{}, 86 GetIamPolicy: []gax.CallOption{}, 87 SetIamPolicy: []gax.CallOption{}, 88 TestIamPermissions: []gax.CallOption{}, 89 CancelOperation: []gax.CallOption{}, 90 DeleteOperation: []gax.CallOption{}, 91 GetOperation: []gax.CallOption{}, 92 ListOperations: []gax.CallOption{}, 93 WaitOperation: []gax.CallOption{}, 94 } 95 } 96 97 // internalGenAiTuningClient is an interface that defines the methods available from Vertex AI API. 98 type internalGenAiTuningClient interface { 99 Close() error 100 setGoogleClientInfo(...string) 101 Connection() *grpc.ClientConn 102 CreateTuningJob(context.Context, *aiplatformpb.CreateTuningJobRequest, ...gax.CallOption) (*aiplatformpb.TuningJob, error) 103 GetTuningJob(context.Context, *aiplatformpb.GetTuningJobRequest, ...gax.CallOption) (*aiplatformpb.TuningJob, error) 104 ListTuningJobs(context.Context, *aiplatformpb.ListTuningJobsRequest, ...gax.CallOption) *TuningJobIterator 105 CancelTuningJob(context.Context, *aiplatformpb.CancelTuningJobRequest, ...gax.CallOption) error 106 RebaseTunedModel(context.Context, *aiplatformpb.RebaseTunedModelRequest, ...gax.CallOption) (*RebaseTunedModelOperation, error) 107 RebaseTunedModelOperation(name string) *RebaseTunedModelOperation 108 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 109 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 110 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 111 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 112 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 113 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 114 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 115 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 116 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 117 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 118 } 119 120 // GenAiTuningClient is a client for interacting with Vertex AI API. 121 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 122 // 123 // A service for creating and managing GenAI Tuning Jobs. 124 type GenAiTuningClient struct { 125 // The internal transport-dependent client. 126 internalClient internalGenAiTuningClient 127 128 // The call options for this service. 129 CallOptions *GenAiTuningCallOptions 130 131 // LROClient is used internally to handle long-running operations. 132 // It is exposed so that its CallOptions can be modified if required. 133 // Users should not Close this client. 134 LROClient *lroauto.OperationsClient 135 } 136 137 // Wrapper methods routed to the internal client. 138 139 // Close closes the connection to the API service. The user should invoke this when 140 // the client is no longer required. 141 func (c *GenAiTuningClient) Close() error { 142 return c.internalClient.Close() 143 } 144 145 // setGoogleClientInfo sets the name and version of the application in 146 // the `x-goog-api-client` header passed on each request. Intended for 147 // use by Google-written clients. 148 func (c *GenAiTuningClient) setGoogleClientInfo(keyval ...string) { 149 c.internalClient.setGoogleClientInfo(keyval...) 150 } 151 152 // Connection returns a connection to the API service. 153 // 154 // Deprecated: Connections are now pooled so this method does not always 155 // return the same resource. 156 func (c *GenAiTuningClient) Connection() *grpc.ClientConn { 157 return c.internalClient.Connection() 158 } 159 160 // CreateTuningJob creates a TuningJob. A created TuningJob right away will be attempted to 161 // be run. 162 func (c *GenAiTuningClient) CreateTuningJob(ctx context.Context, req *aiplatformpb.CreateTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.TuningJob, error) { 163 return c.internalClient.CreateTuningJob(ctx, req, opts...) 164 } 165 166 // GetTuningJob gets a TuningJob. 167 func (c *GenAiTuningClient) GetTuningJob(ctx context.Context, req *aiplatformpb.GetTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.TuningJob, error) { 168 return c.internalClient.GetTuningJob(ctx, req, opts...) 169 } 170 171 // ListTuningJobs lists TuningJobs in a Location. 172 func (c *GenAiTuningClient) ListTuningJobs(ctx context.Context, req *aiplatformpb.ListTuningJobsRequest, opts ...gax.CallOption) *TuningJobIterator { 173 return c.internalClient.ListTuningJobs(ctx, req, opts...) 174 } 175 176 // CancelTuningJob cancels a TuningJob. 177 // Starts asynchronous cancellation on the TuningJob. The server makes a best 178 // effort to cancel the job, but success is not guaranteed. Clients can use 179 // GenAiTuningService.GetTuningJob 180 // or other methods to check whether the cancellation succeeded or whether the 181 // job completed despite cancellation. On successful cancellation, the 182 // TuningJob is not deleted; instead it becomes a job with a 183 // TuningJob.error value with a 184 // google.rpc.Status.code of 1, corresponding to 185 // Code.CANCELLED, and 186 // TuningJob.state is set to 187 // CANCELLED. 188 func (c *GenAiTuningClient) CancelTuningJob(ctx context.Context, req *aiplatformpb.CancelTuningJobRequest, opts ...gax.CallOption) error { 189 return c.internalClient.CancelTuningJob(ctx, req, opts...) 190 } 191 192 // RebaseTunedModel rebase a TunedModel. 193 func (c *GenAiTuningClient) RebaseTunedModel(ctx context.Context, req *aiplatformpb.RebaseTunedModelRequest, opts ...gax.CallOption) (*RebaseTunedModelOperation, error) { 194 return c.internalClient.RebaseTunedModel(ctx, req, opts...) 195 } 196 197 // RebaseTunedModelOperation returns a new RebaseTunedModelOperation from a given name. 198 // The name must be that of a previously created RebaseTunedModelOperation, possibly from a different process. 199 func (c *GenAiTuningClient) RebaseTunedModelOperation(name string) *RebaseTunedModelOperation { 200 return c.internalClient.RebaseTunedModelOperation(name) 201 } 202 203 // GetLocation gets information about a location. 204 func (c *GenAiTuningClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 205 return c.internalClient.GetLocation(ctx, req, opts...) 206 } 207 208 // ListLocations lists information about the supported locations for this service. 209 func (c *GenAiTuningClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 210 return c.internalClient.ListLocations(ctx, req, opts...) 211 } 212 213 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 214 // if the resource exists and does not have a policy set. 215 func (c *GenAiTuningClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 216 return c.internalClient.GetIamPolicy(ctx, req, opts...) 217 } 218 219 // SetIamPolicy sets the access control policy on the specified resource. Replaces 220 // any existing policy. 221 // 222 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 223 // errors. 224 func (c *GenAiTuningClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 225 return c.internalClient.SetIamPolicy(ctx, req, opts...) 226 } 227 228 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 229 // resource does not exist, this will return an empty set of 230 // permissions, not a NOT_FOUND error. 231 // 232 // Note: This operation is designed to be used for building 233 // permission-aware UIs and command-line tools, not for authorization 234 // checking. This operation may “fail open” without warning. 235 func (c *GenAiTuningClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 236 return c.internalClient.TestIamPermissions(ctx, req, opts...) 237 } 238 239 // CancelOperation is a utility method from google.longrunning.Operations. 240 func (c *GenAiTuningClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 241 return c.internalClient.CancelOperation(ctx, req, opts...) 242 } 243 244 // DeleteOperation is a utility method from google.longrunning.Operations. 245 func (c *GenAiTuningClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 246 return c.internalClient.DeleteOperation(ctx, req, opts...) 247 } 248 249 // GetOperation is a utility method from google.longrunning.Operations. 250 func (c *GenAiTuningClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 251 return c.internalClient.GetOperation(ctx, req, opts...) 252 } 253 254 // ListOperations is a utility method from google.longrunning.Operations. 255 func (c *GenAiTuningClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 256 return c.internalClient.ListOperations(ctx, req, opts...) 257 } 258 259 // WaitOperation is a utility method from google.longrunning.Operations. 260 func (c *GenAiTuningClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 261 return c.internalClient.WaitOperation(ctx, req, opts...) 262 } 263 264 // genAiTuningGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 265 // 266 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 267 type genAiTuningGRPCClient struct { 268 // Connection pool of gRPC connections to the service. 269 connPool gtransport.ConnPool 270 271 // Points back to the CallOptions field of the containing GenAiTuningClient 272 CallOptions **GenAiTuningCallOptions 273 274 // The gRPC API client. 275 genAiTuningClient aiplatformpb.GenAiTuningServiceClient 276 277 // LROClient is used internally to handle long-running operations. 278 // It is exposed so that its CallOptions can be modified if required. 279 // Users should not Close this client. 280 LROClient **lroauto.OperationsClient 281 282 operationsClient longrunningpb.OperationsClient 283 284 iamPolicyClient iampb.IAMPolicyClient 285 286 locationsClient locationpb.LocationsClient 287 288 // The x-goog-* metadata to be sent with each request. 289 xGoogHeaders []string 290 291 logger *slog.Logger 292 } 293 294 // NewGenAiTuningClient creates a new gen ai tuning service client based on gRPC. 295 // The returned client must be Closed when it is done being used to clean up its underlying connections. 296 // 297 // A service for creating and managing GenAI Tuning Jobs. 298 func NewGenAiTuningClient(ctx context.Context, opts ...option.ClientOption) (*GenAiTuningClient, error) { 299 clientOpts := defaultGenAiTuningGRPCClientOptions() 300 if newGenAiTuningClientHook != nil { 301 hookOpts, err := newGenAiTuningClientHook(ctx, clientHookParams{}) 302 if err != nil { 303 return nil, err 304 } 305 clientOpts = append(clientOpts, hookOpts...) 306 } 307 308 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 309 if err != nil { 310 return nil, err 311 } 312 client := GenAiTuningClient{CallOptions: defaultGenAiTuningCallOptions()} 313 314 c := &genAiTuningGRPCClient{ 315 connPool: connPool, 316 genAiTuningClient: aiplatformpb.NewGenAiTuningServiceClient(connPool), 317 CallOptions: &client.CallOptions, 318 logger: internaloption.GetLogger(opts), 319 operationsClient: longrunningpb.NewOperationsClient(connPool), 320 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 321 locationsClient: locationpb.NewLocationsClient(connPool), 322 } 323 c.setGoogleClientInfo() 324 325 client.internalClient = c 326 327 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 328 if err != nil { 329 // This error "should not happen", since we are just reusing old connection pool 330 // and never actually need to dial. 331 // If this does happen, we could leak connp. However, we cannot close conn: 332 // If the user invoked the constructor with option.WithGRPCConn, 333 // we would close a connection that's still in use. 334 // TODO: investigate error conditions. 335 return nil, err 336 } 337 c.LROClient = &client.LROClient 338 return &client, nil 339 } 340 341 // Connection returns a connection to the API service. 342 // 343 // Deprecated: Connections are now pooled so this method does not always 344 // return the same resource. 345 func (c *genAiTuningGRPCClient) Connection() *grpc.ClientConn { 346 return c.connPool.Conn() 347 } 348 349 // setGoogleClientInfo sets the name and version of the application in 350 // the `x-goog-api-client` header passed on each request. Intended for 351 // use by Google-written clients. 352 func (c *genAiTuningGRPCClient) setGoogleClientInfo(keyval ...string) { 353 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 354 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 355 c.xGoogHeaders = []string{ 356 "x-goog-api-client", gax.XGoogHeader(kv...), 357 } 358 } 359 360 // Close closes the connection to the API service. The user should invoke this when 361 // the client is no longer required. 362 func (c *genAiTuningGRPCClient) Close() error { 363 return c.connPool.Close() 364 } 365 366 func (c *genAiTuningGRPCClient) CreateTuningJob(ctx context.Context, req *aiplatformpb.CreateTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.TuningJob, error) { 367 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 368 369 hds = append(c.xGoogHeaders, hds...) 370 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 371 opts = append((*c.CallOptions).CreateTuningJob[0:len((*c.CallOptions).CreateTuningJob):len((*c.CallOptions).CreateTuningJob)], opts...) 372 var resp *aiplatformpb.TuningJob 373 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 374 var err error 375 resp, err = executeRPC(ctx, c.genAiTuningClient.CreateTuningJob, req, settings.GRPC, c.logger, "CreateTuningJob") 376 return err 377 }, opts...) 378 if err != nil { 379 return nil, err 380 } 381 return resp, nil 382 } 383 384 func (c *genAiTuningGRPCClient) GetTuningJob(ctx context.Context, req *aiplatformpb.GetTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.TuningJob, error) { 385 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 386 387 hds = append(c.xGoogHeaders, hds...) 388 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 389 opts = append((*c.CallOptions).GetTuningJob[0:len((*c.CallOptions).GetTuningJob):len((*c.CallOptions).GetTuningJob)], opts...) 390 var resp *aiplatformpb.TuningJob 391 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 392 var err error 393 resp, err = executeRPC(ctx, c.genAiTuningClient.GetTuningJob, req, settings.GRPC, c.logger, "GetTuningJob") 394 return err 395 }, opts...) 396 if err != nil { 397 return nil, err 398 } 399 return resp, nil 400 } 401 402 func (c *genAiTuningGRPCClient) ListTuningJobs(ctx context.Context, req *aiplatformpb.ListTuningJobsRequest, opts ...gax.CallOption) *TuningJobIterator { 403 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 404 405 hds = append(c.xGoogHeaders, hds...) 406 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 407 opts = append((*c.CallOptions).ListTuningJobs[0:len((*c.CallOptions).ListTuningJobs):len((*c.CallOptions).ListTuningJobs)], opts...) 408 it := &TuningJobIterator{} 409 req = proto.Clone(req).(*aiplatformpb.ListTuningJobsRequest) 410 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.TuningJob, string, error) { 411 resp := &aiplatformpb.ListTuningJobsResponse{} 412 if pageToken != "" { 413 req.PageToken = pageToken 414 } 415 if pageSize > math.MaxInt32 { 416 req.PageSize = math.MaxInt32 417 } else if pageSize != 0 { 418 req.PageSize = int32(pageSize) 419 } 420 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 421 var err error 422 resp, err = executeRPC(ctx, c.genAiTuningClient.ListTuningJobs, req, settings.GRPC, c.logger, "ListTuningJobs") 423 return err 424 }, opts...) 425 if err != nil { 426 return nil, "", err 427 } 428 429 it.Response = resp 430 return resp.GetTuningJobs(), resp.GetNextPageToken(), nil 431 } 432 fetch := func(pageSize int, pageToken string) (string, error) { 433 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 434 if err != nil { 435 return "", err 436 } 437 it.items = append(it.items, items...) 438 return nextPageToken, nil 439 } 440 441 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 442 it.pageInfo.MaxSize = int(req.GetPageSize()) 443 it.pageInfo.Token = req.GetPageToken() 444 445 return it 446 } 447 448 func (c *genAiTuningGRPCClient) CancelTuningJob(ctx context.Context, req *aiplatformpb.CancelTuningJobRequest, opts ...gax.CallOption) error { 449 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 450 451 hds = append(c.xGoogHeaders, hds...) 452 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 453 opts = append((*c.CallOptions).CancelTuningJob[0:len((*c.CallOptions).CancelTuningJob):len((*c.CallOptions).CancelTuningJob)], opts...) 454 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 455 var err error 456 _, err = executeRPC(ctx, c.genAiTuningClient.CancelTuningJob, req, settings.GRPC, c.logger, "CancelTuningJob") 457 return err 458 }, opts...) 459 return err 460 } 461 462 func (c *genAiTuningGRPCClient) RebaseTunedModel(ctx context.Context, req *aiplatformpb.RebaseTunedModelRequest, opts ...gax.CallOption) (*RebaseTunedModelOperation, error) { 463 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 464 465 hds = append(c.xGoogHeaders, hds...) 466 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 467 opts = append((*c.CallOptions).RebaseTunedModel[0:len((*c.CallOptions).RebaseTunedModel):len((*c.CallOptions).RebaseTunedModel)], opts...) 468 var resp *longrunningpb.Operation 469 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 470 var err error 471 resp, err = executeRPC(ctx, c.genAiTuningClient.RebaseTunedModel, req, settings.GRPC, c.logger, "RebaseTunedModel") 472 return err 473 }, opts...) 474 if err != nil { 475 return nil, err 476 } 477 return &RebaseTunedModelOperation{ 478 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 479 }, nil 480 } 481 482 func (c *genAiTuningGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 483 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 484 485 hds = append(c.xGoogHeaders, hds...) 486 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 487 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 488 var resp *locationpb.Location 489 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 490 var err error 491 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 492 return err 493 }, opts...) 494 if err != nil { 495 return nil, err 496 } 497 return resp, nil 498 } 499 500 func (c *genAiTuningGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 501 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 502 503 hds = append(c.xGoogHeaders, hds...) 504 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 505 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 506 it := &LocationIterator{} 507 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 508 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 509 resp := &locationpb.ListLocationsResponse{} 510 if pageToken != "" { 511 req.PageToken = pageToken 512 } 513 if pageSize > math.MaxInt32 { 514 req.PageSize = math.MaxInt32 515 } else if pageSize != 0 { 516 req.PageSize = int32(pageSize) 517 } 518 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 519 var err error 520 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 521 return err 522 }, opts...) 523 if err != nil { 524 return nil, "", err 525 } 526 527 it.Response = resp 528 return resp.GetLocations(), resp.GetNextPageToken(), nil 529 } 530 fetch := func(pageSize int, pageToken string) (string, error) { 531 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 532 if err != nil { 533 return "", err 534 } 535 it.items = append(it.items, items...) 536 return nextPageToken, nil 537 } 538 539 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 540 it.pageInfo.MaxSize = int(req.GetPageSize()) 541 it.pageInfo.Token = req.GetPageToken() 542 543 return it 544 } 545 546 func (c *genAiTuningGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 547 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 548 549 hds = append(c.xGoogHeaders, hds...) 550 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 551 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 552 var resp *iampb.Policy 553 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 554 var err error 555 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 556 return err 557 }, opts...) 558 if err != nil { 559 return nil, err 560 } 561 return resp, nil 562 } 563 564 func (c *genAiTuningGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 565 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 566 567 hds = append(c.xGoogHeaders, hds...) 568 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 569 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 570 var resp *iampb.Policy 571 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 572 var err error 573 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 574 return err 575 }, opts...) 576 if err != nil { 577 return nil, err 578 } 579 return resp, nil 580 } 581 582 func (c *genAiTuningGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 583 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 584 585 hds = append(c.xGoogHeaders, hds...) 586 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 587 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 588 var resp *iampb.TestIamPermissionsResponse 589 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 590 var err error 591 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 592 return err 593 }, opts...) 594 if err != nil { 595 return nil, err 596 } 597 return resp, nil 598 } 599 600 func (c *genAiTuningGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 601 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 602 603 hds = append(c.xGoogHeaders, hds...) 604 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 605 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 606 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 607 var err error 608 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 609 return err 610 }, opts...) 611 return err 612 } 613 614 func (c *genAiTuningGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 615 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 616 617 hds = append(c.xGoogHeaders, hds...) 618 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 619 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 620 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 621 var err error 622 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 623 return err 624 }, opts...) 625 return err 626 } 627 628 func (c *genAiTuningGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 629 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 630 631 hds = append(c.xGoogHeaders, hds...) 632 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 633 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 634 var resp *longrunningpb.Operation 635 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 636 var err error 637 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 638 return err 639 }, opts...) 640 if err != nil { 641 return nil, err 642 } 643 return resp, nil 644 } 645 646 func (c *genAiTuningGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 647 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 648 649 hds = append(c.xGoogHeaders, hds...) 650 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 651 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 652 it := &OperationIterator{} 653 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 654 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 655 resp := &longrunningpb.ListOperationsResponse{} 656 if pageToken != "" { 657 req.PageToken = pageToken 658 } 659 if pageSize > math.MaxInt32 { 660 req.PageSize = math.MaxInt32 661 } else if pageSize != 0 { 662 req.PageSize = int32(pageSize) 663 } 664 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 665 var err error 666 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 667 return err 668 }, opts...) 669 if err != nil { 670 return nil, "", err 671 } 672 673 it.Response = resp 674 return resp.GetOperations(), resp.GetNextPageToken(), nil 675 } 676 fetch := func(pageSize int, pageToken string) (string, error) { 677 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 678 if err != nil { 679 return "", err 680 } 681 it.items = append(it.items, items...) 682 return nextPageToken, nil 683 } 684 685 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 686 it.pageInfo.MaxSize = int(req.GetPageSize()) 687 it.pageInfo.Token = req.GetPageToken() 688 689 return it 690 } 691 692 func (c *genAiTuningGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 693 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 694 695 hds = append(c.xGoogHeaders, hds...) 696 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 697 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 698 var resp *longrunningpb.Operation 699 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 700 var err error 701 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 702 return err 703 }, opts...) 704 if err != nil { 705 return nil, err 706 } 707 return resp, nil 708 } 709 710 // RebaseTunedModelOperation returns a new RebaseTunedModelOperation from a given name. 711 // The name must be that of a previously created RebaseTunedModelOperation, possibly from a different process. 712 func (c *genAiTuningGRPCClient) RebaseTunedModelOperation(name string) *RebaseTunedModelOperation { 713 return &RebaseTunedModelOperation{ 714 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 715 } 716 }