cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/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 "bytes" 21 "context" 22 "fmt" 23 "log/slog" 24 "math" 25 "net/http" 26 "net/url" 27 28 aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb" 29 iampb "cloud.google.com/go/iam/apiv1/iampb" 30 "cloud.google.com/go/longrunning" 31 lroauto "cloud.google.com/go/longrunning/autogen" 32 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 33 gax "github.com/googleapis/gax-go/v2" 34 "google.golang.org/api/iterator" 35 "google.golang.org/api/option" 36 "google.golang.org/api/option/internaloption" 37 gtransport "google.golang.org/api/transport/grpc" 38 httptransport "google.golang.org/api/transport/http" 39 locationpb "google.golang.org/genproto/googleapis/cloud/location" 40 "google.golang.org/grpc" 41 "google.golang.org/protobuf/encoding/protojson" 42 "google.golang.org/protobuf/proto" 43 ) 44 45 var newGenAiTuningClientHook clientHook 46 47 // GenAiTuningCallOptions contains the retry settings for each method of GenAiTuningClient. 48 type GenAiTuningCallOptions struct { 49 CreateTuningJob []gax.CallOption 50 GetTuningJob []gax.CallOption 51 ListTuningJobs []gax.CallOption 52 CancelTuningJob []gax.CallOption 53 RebaseTunedModel []gax.CallOption 54 GetLocation []gax.CallOption 55 ListLocations []gax.CallOption 56 GetIamPolicy []gax.CallOption 57 SetIamPolicy []gax.CallOption 58 TestIamPermissions []gax.CallOption 59 CancelOperation []gax.CallOption 60 DeleteOperation []gax.CallOption 61 GetOperation []gax.CallOption 62 ListOperations []gax.CallOption 63 WaitOperation []gax.CallOption 64 } 65 66 func defaultGenAiTuningGRPCClientOptions() []option.ClientOption { 67 return []option.ClientOption{ 68 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 69 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 70 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 71 internaloption.WithDefaultUniverseDomain("googleapis.com"), 72 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 73 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 74 internaloption.EnableJwtWithScope(), 75 internaloption.EnableNewAuthLibrary(), 76 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 77 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 78 } 79 } 80 81 func defaultGenAiTuningCallOptions() *GenAiTuningCallOptions { 82 return &GenAiTuningCallOptions{ 83 CreateTuningJob: []gax.CallOption{}, 84 GetTuningJob: []gax.CallOption{}, 85 ListTuningJobs: []gax.CallOption{}, 86 CancelTuningJob: []gax.CallOption{}, 87 RebaseTunedModel: []gax.CallOption{}, 88 GetLocation: []gax.CallOption{}, 89 ListLocations: []gax.CallOption{}, 90 GetIamPolicy: []gax.CallOption{}, 91 SetIamPolicy: []gax.CallOption{}, 92 TestIamPermissions: []gax.CallOption{}, 93 CancelOperation: []gax.CallOption{}, 94 DeleteOperation: []gax.CallOption{}, 95 GetOperation: []gax.CallOption{}, 96 ListOperations: []gax.CallOption{}, 97 WaitOperation: []gax.CallOption{}, 98 } 99 } 100 101 func defaultGenAiTuningRESTCallOptions() *GenAiTuningCallOptions { 102 return &GenAiTuningCallOptions{ 103 CreateTuningJob: []gax.CallOption{}, 104 GetTuningJob: []gax.CallOption{}, 105 ListTuningJobs: []gax.CallOption{}, 106 CancelTuningJob: []gax.CallOption{}, 107 RebaseTunedModel: []gax.CallOption{}, 108 GetLocation: []gax.CallOption{}, 109 ListLocations: []gax.CallOption{}, 110 GetIamPolicy: []gax.CallOption{}, 111 SetIamPolicy: []gax.CallOption{}, 112 TestIamPermissions: []gax.CallOption{}, 113 CancelOperation: []gax.CallOption{}, 114 DeleteOperation: []gax.CallOption{}, 115 GetOperation: []gax.CallOption{}, 116 ListOperations: []gax.CallOption{}, 117 WaitOperation: []gax.CallOption{}, 118 } 119 } 120 121 // internalGenAiTuningClient is an interface that defines the methods available from Vertex AI API. 122 type internalGenAiTuningClient interface { 123 Close() error 124 setGoogleClientInfo(...string) 125 Connection() *grpc.ClientConn 126 CreateTuningJob(context.Context, *aiplatformpb.CreateTuningJobRequest, ...gax.CallOption) (*aiplatformpb.TuningJob, error) 127 GetTuningJob(context.Context, *aiplatformpb.GetTuningJobRequest, ...gax.CallOption) (*aiplatformpb.TuningJob, error) 128 ListTuningJobs(context.Context, *aiplatformpb.ListTuningJobsRequest, ...gax.CallOption) *TuningJobIterator 129 CancelTuningJob(context.Context, *aiplatformpb.CancelTuningJobRequest, ...gax.CallOption) error 130 RebaseTunedModel(context.Context, *aiplatformpb.RebaseTunedModelRequest, ...gax.CallOption) (*RebaseTunedModelOperation, error) 131 RebaseTunedModelOperation(name string) *RebaseTunedModelOperation 132 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 133 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 134 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 135 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 136 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 137 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 138 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 139 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 140 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 141 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 142 } 143 144 // GenAiTuningClient is a client for interacting with Vertex AI API. 145 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 146 // 147 // A service for creating and managing GenAI Tuning Jobs. 148 type GenAiTuningClient struct { 149 // The internal transport-dependent client. 150 internalClient internalGenAiTuningClient 151 152 // The call options for this service. 153 CallOptions *GenAiTuningCallOptions 154 155 // LROClient is used internally to handle long-running operations. 156 // It is exposed so that its CallOptions can be modified if required. 157 // Users should not Close this client. 158 LROClient *lroauto.OperationsClient 159 } 160 161 // Wrapper methods routed to the internal client. 162 163 // Close closes the connection to the API service. The user should invoke this when 164 // the client is no longer required. 165 func (c *GenAiTuningClient) Close() error { 166 return c.internalClient.Close() 167 } 168 169 // setGoogleClientInfo sets the name and version of the application in 170 // the `x-goog-api-client` header passed on each request. Intended for 171 // use by Google-written clients. 172 func (c *GenAiTuningClient) setGoogleClientInfo(keyval ...string) { 173 c.internalClient.setGoogleClientInfo(keyval...) 174 } 175 176 // Connection returns a connection to the API service. 177 // 178 // Deprecated: Connections are now pooled so this method does not always 179 // return the same resource. 180 func (c *GenAiTuningClient) Connection() *grpc.ClientConn { 181 return c.internalClient.Connection() 182 } 183 184 // CreateTuningJob creates a TuningJob. A created TuningJob right away will be attempted to 185 // be run. 186 func (c *GenAiTuningClient) CreateTuningJob(ctx context.Context, req *aiplatformpb.CreateTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.TuningJob, error) { 187 return c.internalClient.CreateTuningJob(ctx, req, opts...) 188 } 189 190 // GetTuningJob gets a TuningJob. 191 func (c *GenAiTuningClient) GetTuningJob(ctx context.Context, req *aiplatformpb.GetTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.TuningJob, error) { 192 return c.internalClient.GetTuningJob(ctx, req, opts...) 193 } 194 195 // ListTuningJobs lists TuningJobs in a Location. 196 func (c *GenAiTuningClient) ListTuningJobs(ctx context.Context, req *aiplatformpb.ListTuningJobsRequest, opts ...gax.CallOption) *TuningJobIterator { 197 return c.internalClient.ListTuningJobs(ctx, req, opts...) 198 } 199 200 // CancelTuningJob cancels a TuningJob. 201 // Starts asynchronous cancellation on the TuningJob. The server makes a best 202 // effort to cancel the job, but success is not guaranteed. Clients can use 203 // GenAiTuningService.GetTuningJob 204 // or other methods to check whether the cancellation succeeded or whether the 205 // job completed despite cancellation. On successful cancellation, the 206 // TuningJob is not deleted; instead it becomes a job with a 207 // TuningJob.error value 208 // with a google.rpc.Status.code of 1, corresponding 209 // to Code.CANCELLED, and 210 // TuningJob.state is set 211 // to CANCELLED. 212 func (c *GenAiTuningClient) CancelTuningJob(ctx context.Context, req *aiplatformpb.CancelTuningJobRequest, opts ...gax.CallOption) error { 213 return c.internalClient.CancelTuningJob(ctx, req, opts...) 214 } 215 216 // RebaseTunedModel rebase a TunedModel. 217 // Creates a LongRunningOperation that takes a legacy Tuned GenAI model 218 // Reference and creates a TuningJob based on newly available model. 219 func (c *GenAiTuningClient) RebaseTunedModel(ctx context.Context, req *aiplatformpb.RebaseTunedModelRequest, opts ...gax.CallOption) (*RebaseTunedModelOperation, error) { 220 return c.internalClient.RebaseTunedModel(ctx, req, opts...) 221 } 222 223 // RebaseTunedModelOperation returns a new RebaseTunedModelOperation from a given name. 224 // The name must be that of a previously created RebaseTunedModelOperation, possibly from a different process. 225 func (c *GenAiTuningClient) RebaseTunedModelOperation(name string) *RebaseTunedModelOperation { 226 return c.internalClient.RebaseTunedModelOperation(name) 227 } 228 229 // GetLocation gets information about a location. 230 func (c *GenAiTuningClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 231 return c.internalClient.GetLocation(ctx, req, opts...) 232 } 233 234 // ListLocations lists information about the supported locations for this service. 235 func (c *GenAiTuningClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 236 return c.internalClient.ListLocations(ctx, req, opts...) 237 } 238 239 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 240 // if the resource exists and does not have a policy set. 241 func (c *GenAiTuningClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 242 return c.internalClient.GetIamPolicy(ctx, req, opts...) 243 } 244 245 // SetIamPolicy sets the access control policy on the specified resource. Replaces 246 // any existing policy. 247 // 248 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 249 // errors. 250 func (c *GenAiTuningClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 251 return c.internalClient.SetIamPolicy(ctx, req, opts...) 252 } 253 254 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 255 // resource does not exist, this will return an empty set of 256 // permissions, not a NOT_FOUND error. 257 // 258 // Note: This operation is designed to be used for building 259 // permission-aware UIs and command-line tools, not for authorization 260 // checking. This operation may “fail open” without warning. 261 func (c *GenAiTuningClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 262 return c.internalClient.TestIamPermissions(ctx, req, opts...) 263 } 264 265 // CancelOperation is a utility method from google.longrunning.Operations. 266 func (c *GenAiTuningClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 267 return c.internalClient.CancelOperation(ctx, req, opts...) 268 } 269 270 // DeleteOperation is a utility method from google.longrunning.Operations. 271 func (c *GenAiTuningClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 272 return c.internalClient.DeleteOperation(ctx, req, opts...) 273 } 274 275 // GetOperation is a utility method from google.longrunning.Operations. 276 func (c *GenAiTuningClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 277 return c.internalClient.GetOperation(ctx, req, opts...) 278 } 279 280 // ListOperations is a utility method from google.longrunning.Operations. 281 func (c *GenAiTuningClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 282 return c.internalClient.ListOperations(ctx, req, opts...) 283 } 284 285 // WaitOperation is a utility method from google.longrunning.Operations. 286 func (c *GenAiTuningClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 287 return c.internalClient.WaitOperation(ctx, req, opts...) 288 } 289 290 // genAiTuningGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 291 // 292 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 293 type genAiTuningGRPCClient struct { 294 // Connection pool of gRPC connections to the service. 295 connPool gtransport.ConnPool 296 297 // Points back to the CallOptions field of the containing GenAiTuningClient 298 CallOptions **GenAiTuningCallOptions 299 300 // The gRPC API client. 301 genAiTuningClient aiplatformpb.GenAiTuningServiceClient 302 303 // LROClient is used internally to handle long-running operations. 304 // It is exposed so that its CallOptions can be modified if required. 305 // Users should not Close this client. 306 LROClient **lroauto.OperationsClient 307 308 operationsClient longrunningpb.OperationsClient 309 310 iamPolicyClient iampb.IAMPolicyClient 311 312 locationsClient locationpb.LocationsClient 313 314 // The x-goog-* metadata to be sent with each request. 315 xGoogHeaders []string 316 317 logger *slog.Logger 318 } 319 320 // NewGenAiTuningClient creates a new gen ai tuning service client based on gRPC. 321 // The returned client must be Closed when it is done being used to clean up its underlying connections. 322 // 323 // A service for creating and managing GenAI Tuning Jobs. 324 func NewGenAiTuningClient(ctx context.Context, opts ...option.ClientOption) (*GenAiTuningClient, error) { 325 clientOpts := defaultGenAiTuningGRPCClientOptions() 326 if newGenAiTuningClientHook != nil { 327 hookOpts, err := newGenAiTuningClientHook(ctx, clientHookParams{}) 328 if err != nil { 329 return nil, err 330 } 331 clientOpts = append(clientOpts, hookOpts...) 332 } 333 334 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 335 if err != nil { 336 return nil, err 337 } 338 client := GenAiTuningClient{CallOptions: defaultGenAiTuningCallOptions()} 339 340 c := &genAiTuningGRPCClient{ 341 connPool: connPool, 342 genAiTuningClient: aiplatformpb.NewGenAiTuningServiceClient(connPool), 343 CallOptions: &client.CallOptions, 344 logger: internaloption.GetLogger(opts), 345 operationsClient: longrunningpb.NewOperationsClient(connPool), 346 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 347 locationsClient: locationpb.NewLocationsClient(connPool), 348 } 349 c.setGoogleClientInfo() 350 351 client.internalClient = c 352 353 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 354 if err != nil { 355 // This error "should not happen", since we are just reusing old connection pool 356 // and never actually need to dial. 357 // If this does happen, we could leak connp. However, we cannot close conn: 358 // If the user invoked the constructor with option.WithGRPCConn, 359 // we would close a connection that's still in use. 360 // TODO: investigate error conditions. 361 return nil, err 362 } 363 c.LROClient = &client.LROClient 364 return &client, nil 365 } 366 367 // Connection returns a connection to the API service. 368 // 369 // Deprecated: Connections are now pooled so this method does not always 370 // return the same resource. 371 func (c *genAiTuningGRPCClient) Connection() *grpc.ClientConn { 372 return c.connPool.Conn() 373 } 374 375 // setGoogleClientInfo sets the name and version of the application in 376 // the `x-goog-api-client` header passed on each request. Intended for 377 // use by Google-written clients. 378 func (c *genAiTuningGRPCClient) setGoogleClientInfo(keyval ...string) { 379 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 380 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 381 c.xGoogHeaders = []string{ 382 "x-goog-api-client", gax.XGoogHeader(kv...), 383 } 384 } 385 386 // Close closes the connection to the API service. The user should invoke this when 387 // the client is no longer required. 388 func (c *genAiTuningGRPCClient) Close() error { 389 return c.connPool.Close() 390 } 391 392 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 393 type genAiTuningRESTClient struct { 394 // The http endpoint to connect to. 395 endpoint string 396 397 // The http client. 398 httpClient *http.Client 399 400 // LROClient is used internally to handle long-running operations. 401 // It is exposed so that its CallOptions can be modified if required. 402 // Users should not Close this client. 403 LROClient **lroauto.OperationsClient 404 405 // The x-goog-* headers to be sent with each request. 406 xGoogHeaders []string 407 408 // Points back to the CallOptions field of the containing GenAiTuningClient 409 CallOptions **GenAiTuningCallOptions 410 411 logger *slog.Logger 412 } 413 414 // NewGenAiTuningRESTClient creates a new gen ai tuning service rest client. 415 // 416 // A service for creating and managing GenAI Tuning Jobs. 417 func NewGenAiTuningRESTClient(ctx context.Context, opts ...option.ClientOption) (*GenAiTuningClient, error) { 418 clientOpts := append(defaultGenAiTuningRESTClientOptions(), opts...) 419 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) 420 if err != nil { 421 return nil, err 422 } 423 424 callOpts := defaultGenAiTuningRESTCallOptions() 425 c := &genAiTuningRESTClient{ 426 endpoint: endpoint, 427 httpClient: httpClient, 428 CallOptions: &callOpts, 429 logger: internaloption.GetLogger(opts), 430 } 431 c.setGoogleClientInfo() 432 433 lroOpts := []option.ClientOption{ 434 option.WithHTTPClient(httpClient), 435 option.WithEndpoint(endpoint), 436 } 437 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...) 438 if err != nil { 439 return nil, err 440 } 441 c.LROClient = &opClient 442 443 return &GenAiTuningClient{internalClient: c, CallOptions: callOpts}, nil 444 } 445 446 func defaultGenAiTuningRESTClientOptions() []option.ClientOption { 447 return []option.ClientOption{ 448 internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"), 449 internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"), 450 internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"), 451 internaloption.WithDefaultUniverseDomain("googleapis.com"), 452 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 453 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 454 internaloption.EnableNewAuthLibrary(), 455 } 456 } 457 458 // setGoogleClientInfo sets the name and version of the application in 459 // the `x-goog-api-client` header passed on each request. Intended for 460 // use by Google-written clients. 461 func (c *genAiTuningRESTClient) setGoogleClientInfo(keyval ...string) { 462 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 463 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) 464 c.xGoogHeaders = []string{ 465 "x-goog-api-client", gax.XGoogHeader(kv...), 466 } 467 } 468 469 // Close closes the connection to the API service. The user should invoke this when 470 // the client is no longer required. 471 func (c *genAiTuningRESTClient) Close() error { 472 // Replace httpClient with nil to force cleanup. 473 c.httpClient = nil 474 return nil 475 } 476 477 // Connection returns a connection to the API service. 478 // 479 // Deprecated: This method always returns nil. 480 func (c *genAiTuningRESTClient) Connection() *grpc.ClientConn { 481 return nil 482 } 483 func (c *genAiTuningGRPCClient) CreateTuningJob(ctx context.Context, req *aiplatformpb.CreateTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.TuningJob, error) { 484 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 485 486 hds = append(c.xGoogHeaders, hds...) 487 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 488 opts = append((*c.CallOptions).CreateTuningJob[0:len((*c.CallOptions).CreateTuningJob):len((*c.CallOptions).CreateTuningJob)], opts...) 489 var resp *aiplatformpb.TuningJob 490 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 491 var err error 492 resp, err = executeRPC(ctx, c.genAiTuningClient.CreateTuningJob, req, settings.GRPC, c.logger, "CreateTuningJob") 493 return err 494 }, opts...) 495 if err != nil { 496 return nil, err 497 } 498 return resp, nil 499 } 500 501 func (c *genAiTuningGRPCClient) GetTuningJob(ctx context.Context, req *aiplatformpb.GetTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.TuningJob, error) { 502 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 503 504 hds = append(c.xGoogHeaders, hds...) 505 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 506 opts = append((*c.CallOptions).GetTuningJob[0:len((*c.CallOptions).GetTuningJob):len((*c.CallOptions).GetTuningJob)], opts...) 507 var resp *aiplatformpb.TuningJob 508 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 509 var err error 510 resp, err = executeRPC(ctx, c.genAiTuningClient.GetTuningJob, req, settings.GRPC, c.logger, "GetTuningJob") 511 return err 512 }, opts...) 513 if err != nil { 514 return nil, err 515 } 516 return resp, nil 517 } 518 519 func (c *genAiTuningGRPCClient) ListTuningJobs(ctx context.Context, req *aiplatformpb.ListTuningJobsRequest, opts ...gax.CallOption) *TuningJobIterator { 520 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 521 522 hds = append(c.xGoogHeaders, hds...) 523 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 524 opts = append((*c.CallOptions).ListTuningJobs[0:len((*c.CallOptions).ListTuningJobs):len((*c.CallOptions).ListTuningJobs)], opts...) 525 it := &TuningJobIterator{} 526 req = proto.Clone(req).(*aiplatformpb.ListTuningJobsRequest) 527 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.TuningJob, string, error) { 528 resp := &aiplatformpb.ListTuningJobsResponse{} 529 if pageToken != "" { 530 req.PageToken = pageToken 531 } 532 if pageSize > math.MaxInt32 { 533 req.PageSize = math.MaxInt32 534 } else if pageSize != 0 { 535 req.PageSize = int32(pageSize) 536 } 537 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 538 var err error 539 resp, err = executeRPC(ctx, c.genAiTuningClient.ListTuningJobs, req, settings.GRPC, c.logger, "ListTuningJobs") 540 return err 541 }, opts...) 542 if err != nil { 543 return nil, "", err 544 } 545 546 it.Response = resp 547 return resp.GetTuningJobs(), resp.GetNextPageToken(), nil 548 } 549 fetch := func(pageSize int, pageToken string) (string, error) { 550 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 551 if err != nil { 552 return "", err 553 } 554 it.items = append(it.items, items...) 555 return nextPageToken, nil 556 } 557 558 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 559 it.pageInfo.MaxSize = int(req.GetPageSize()) 560 it.pageInfo.Token = req.GetPageToken() 561 562 return it 563 } 564 565 func (c *genAiTuningGRPCClient) CancelTuningJob(ctx context.Context, req *aiplatformpb.CancelTuningJobRequest, opts ...gax.CallOption) error { 566 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 567 568 hds = append(c.xGoogHeaders, hds...) 569 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 570 opts = append((*c.CallOptions).CancelTuningJob[0:len((*c.CallOptions).CancelTuningJob):len((*c.CallOptions).CancelTuningJob)], opts...) 571 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 572 var err error 573 _, err = executeRPC(ctx, c.genAiTuningClient.CancelTuningJob, req, settings.GRPC, c.logger, "CancelTuningJob") 574 return err 575 }, opts...) 576 return err 577 } 578 579 func (c *genAiTuningGRPCClient) RebaseTunedModel(ctx context.Context, req *aiplatformpb.RebaseTunedModelRequest, opts ...gax.CallOption) (*RebaseTunedModelOperation, error) { 580 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 581 582 hds = append(c.xGoogHeaders, hds...) 583 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 584 opts = append((*c.CallOptions).RebaseTunedModel[0:len((*c.CallOptions).RebaseTunedModel):len((*c.CallOptions).RebaseTunedModel)], opts...) 585 var resp *longrunningpb.Operation 586 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 587 var err error 588 resp, err = executeRPC(ctx, c.genAiTuningClient.RebaseTunedModel, req, settings.GRPC, c.logger, "RebaseTunedModel") 589 return err 590 }, opts...) 591 if err != nil { 592 return nil, err 593 } 594 return &RebaseTunedModelOperation{ 595 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 596 }, nil 597 } 598 599 func (c *genAiTuningGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 600 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 601 602 hds = append(c.xGoogHeaders, hds...) 603 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 604 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 605 var resp *locationpb.Location 606 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 607 var err error 608 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 609 return err 610 }, opts...) 611 if err != nil { 612 return nil, err 613 } 614 return resp, nil 615 } 616 617 func (c *genAiTuningGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 618 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 619 620 hds = append(c.xGoogHeaders, hds...) 621 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 622 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 623 it := &LocationIterator{} 624 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 625 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 626 resp := &locationpb.ListLocationsResponse{} 627 if pageToken != "" { 628 req.PageToken = pageToken 629 } 630 if pageSize > math.MaxInt32 { 631 req.PageSize = math.MaxInt32 632 } else if pageSize != 0 { 633 req.PageSize = int32(pageSize) 634 } 635 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 636 var err error 637 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 638 return err 639 }, opts...) 640 if err != nil { 641 return nil, "", err 642 } 643 644 it.Response = resp 645 return resp.GetLocations(), resp.GetNextPageToken(), nil 646 } 647 fetch := func(pageSize int, pageToken string) (string, error) { 648 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 649 if err != nil { 650 return "", err 651 } 652 it.items = append(it.items, items...) 653 return nextPageToken, nil 654 } 655 656 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 657 it.pageInfo.MaxSize = int(req.GetPageSize()) 658 it.pageInfo.Token = req.GetPageToken() 659 660 return it 661 } 662 663 func (c *genAiTuningGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 664 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 665 666 hds = append(c.xGoogHeaders, hds...) 667 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 668 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 669 var resp *iampb.Policy 670 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 671 var err error 672 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 673 return err 674 }, opts...) 675 if err != nil { 676 return nil, err 677 } 678 return resp, nil 679 } 680 681 func (c *genAiTuningGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 682 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 683 684 hds = append(c.xGoogHeaders, hds...) 685 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 686 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 687 var resp *iampb.Policy 688 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 689 var err error 690 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 691 return err 692 }, opts...) 693 if err != nil { 694 return nil, err 695 } 696 return resp, nil 697 } 698 699 func (c *genAiTuningGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 700 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 701 702 hds = append(c.xGoogHeaders, hds...) 703 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 704 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 705 var resp *iampb.TestIamPermissionsResponse 706 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 707 var err error 708 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 709 return err 710 }, opts...) 711 if err != nil { 712 return nil, err 713 } 714 return resp, nil 715 } 716 717 func (c *genAiTuningGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 718 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 719 720 hds = append(c.xGoogHeaders, hds...) 721 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 722 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 723 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 724 var err error 725 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 726 return err 727 }, opts...) 728 return err 729 } 730 731 func (c *genAiTuningGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 732 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 733 734 hds = append(c.xGoogHeaders, hds...) 735 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 736 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 737 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 738 var err error 739 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 740 return err 741 }, opts...) 742 return err 743 } 744 745 func (c *genAiTuningGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 746 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 747 748 hds = append(c.xGoogHeaders, hds...) 749 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 750 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 751 var resp *longrunningpb.Operation 752 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 753 var err error 754 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 755 return err 756 }, opts...) 757 if err != nil { 758 return nil, err 759 } 760 return resp, nil 761 } 762 763 func (c *genAiTuningGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 764 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 765 766 hds = append(c.xGoogHeaders, hds...) 767 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 768 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 769 it := &OperationIterator{} 770 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 771 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 772 resp := &longrunningpb.ListOperationsResponse{} 773 if pageToken != "" { 774 req.PageToken = pageToken 775 } 776 if pageSize > math.MaxInt32 { 777 req.PageSize = math.MaxInt32 778 } else if pageSize != 0 { 779 req.PageSize = int32(pageSize) 780 } 781 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 782 var err error 783 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 784 return err 785 }, opts...) 786 if err != nil { 787 return nil, "", err 788 } 789 790 it.Response = resp 791 return resp.GetOperations(), resp.GetNextPageToken(), nil 792 } 793 fetch := func(pageSize int, pageToken string) (string, error) { 794 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 795 if err != nil { 796 return "", err 797 } 798 it.items = append(it.items, items...) 799 return nextPageToken, nil 800 } 801 802 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 803 it.pageInfo.MaxSize = int(req.GetPageSize()) 804 it.pageInfo.Token = req.GetPageToken() 805 806 return it 807 } 808 809 func (c *genAiTuningGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 810 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 811 812 hds = append(c.xGoogHeaders, hds...) 813 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 814 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 815 var resp *longrunningpb.Operation 816 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 817 var err error 818 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 819 return err 820 }, opts...) 821 if err != nil { 822 return nil, err 823 } 824 return resp, nil 825 } 826 827 // CreateTuningJob creates a TuningJob. A created TuningJob right away will be attempted to 828 // be run. 829 func (c *genAiTuningRESTClient) CreateTuningJob(ctx context.Context, req *aiplatformpb.CreateTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.TuningJob, error) { 830 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 831 body := req.GetTuningJob() 832 jsonReq, err := m.Marshal(body) 833 if err != nil { 834 return nil, err 835 } 836 837 baseUrl, err := url.Parse(c.endpoint) 838 if err != nil { 839 return nil, err 840 } 841 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/tuningJobs", req.GetParent()) 842 843 params := url.Values{} 844 params.Add("$alt", "json;enum-encoding=int") 845 846 baseUrl.RawQuery = params.Encode() 847 848 // Build HTTP headers from client and context metadata. 849 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 850 851 hds = append(c.xGoogHeaders, hds...) 852 hds = append(hds, "Content-Type", "application/json") 853 headers := gax.BuildHeaders(ctx, hds...) 854 opts = append((*c.CallOptions).CreateTuningJob[0:len((*c.CallOptions).CreateTuningJob):len((*c.CallOptions).CreateTuningJob)], opts...) 855 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 856 resp := &aiplatformpb.TuningJob{} 857 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 858 if settings.Path != "" { 859 baseUrl.Path = settings.Path 860 } 861 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 862 if err != nil { 863 return err 864 } 865 httpReq = httpReq.WithContext(ctx) 866 httpReq.Header = headers 867 868 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateTuningJob") 869 if err != nil { 870 return err 871 } 872 873 if err := unm.Unmarshal(buf, resp); err != nil { 874 return err 875 } 876 877 return nil 878 }, opts...) 879 if e != nil { 880 return nil, e 881 } 882 return resp, nil 883 } 884 885 // GetTuningJob gets a TuningJob. 886 func (c *genAiTuningRESTClient) GetTuningJob(ctx context.Context, req *aiplatformpb.GetTuningJobRequest, opts ...gax.CallOption) (*aiplatformpb.TuningJob, error) { 887 baseUrl, err := url.Parse(c.endpoint) 888 if err != nil { 889 return nil, err 890 } 891 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 892 893 params := url.Values{} 894 params.Add("$alt", "json;enum-encoding=int") 895 896 baseUrl.RawQuery = params.Encode() 897 898 // Build HTTP headers from client and context metadata. 899 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 900 901 hds = append(c.xGoogHeaders, hds...) 902 hds = append(hds, "Content-Type", "application/json") 903 headers := gax.BuildHeaders(ctx, hds...) 904 opts = append((*c.CallOptions).GetTuningJob[0:len((*c.CallOptions).GetTuningJob):len((*c.CallOptions).GetTuningJob)], opts...) 905 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 906 resp := &aiplatformpb.TuningJob{} 907 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 908 if settings.Path != "" { 909 baseUrl.Path = settings.Path 910 } 911 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 912 if err != nil { 913 return err 914 } 915 httpReq = httpReq.WithContext(ctx) 916 httpReq.Header = headers 917 918 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTuningJob") 919 if err != nil { 920 return err 921 } 922 923 if err := unm.Unmarshal(buf, resp); err != nil { 924 return err 925 } 926 927 return nil 928 }, opts...) 929 if e != nil { 930 return nil, e 931 } 932 return resp, nil 933 } 934 935 // ListTuningJobs lists TuningJobs in a Location. 936 func (c *genAiTuningRESTClient) ListTuningJobs(ctx context.Context, req *aiplatformpb.ListTuningJobsRequest, opts ...gax.CallOption) *TuningJobIterator { 937 it := &TuningJobIterator{} 938 req = proto.Clone(req).(*aiplatformpb.ListTuningJobsRequest) 939 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 940 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.TuningJob, string, error) { 941 resp := &aiplatformpb.ListTuningJobsResponse{} 942 if pageToken != "" { 943 req.PageToken = pageToken 944 } 945 if pageSize > math.MaxInt32 { 946 req.PageSize = math.MaxInt32 947 } else if pageSize != 0 { 948 req.PageSize = int32(pageSize) 949 } 950 baseUrl, err := url.Parse(c.endpoint) 951 if err != nil { 952 return nil, "", err 953 } 954 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/tuningJobs", req.GetParent()) 955 956 params := url.Values{} 957 params.Add("$alt", "json;enum-encoding=int") 958 if req.GetFilter() != "" { 959 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 960 } 961 if req.GetPageSize() != 0 { 962 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 963 } 964 if req.GetPageToken() != "" { 965 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 966 } 967 968 baseUrl.RawQuery = params.Encode() 969 970 // Build HTTP headers from client and context metadata. 971 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 972 headers := gax.BuildHeaders(ctx, hds...) 973 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 974 if settings.Path != "" { 975 baseUrl.Path = settings.Path 976 } 977 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 978 if err != nil { 979 return err 980 } 981 httpReq.Header = headers 982 983 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListTuningJobs") 984 if err != nil { 985 return err 986 } 987 if err := unm.Unmarshal(buf, resp); err != nil { 988 return err 989 } 990 991 return nil 992 }, opts...) 993 if e != nil { 994 return nil, "", e 995 } 996 it.Response = resp 997 return resp.GetTuningJobs(), resp.GetNextPageToken(), nil 998 } 999 1000 fetch := func(pageSize int, pageToken string) (string, error) { 1001 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1002 if err != nil { 1003 return "", err 1004 } 1005 it.items = append(it.items, items...) 1006 return nextPageToken, nil 1007 } 1008 1009 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1010 it.pageInfo.MaxSize = int(req.GetPageSize()) 1011 it.pageInfo.Token = req.GetPageToken() 1012 1013 return it 1014 } 1015 1016 // CancelTuningJob cancels a TuningJob. 1017 // Starts asynchronous cancellation on the TuningJob. The server makes a best 1018 // effort to cancel the job, but success is not guaranteed. Clients can use 1019 // GenAiTuningService.GetTuningJob 1020 // or other methods to check whether the cancellation succeeded or whether the 1021 // job completed despite cancellation. On successful cancellation, the 1022 // TuningJob is not deleted; instead it becomes a job with a 1023 // TuningJob.error value 1024 // with a google.rpc.Status.code of 1, corresponding 1025 // to Code.CANCELLED, and 1026 // TuningJob.state is set 1027 // to CANCELLED. 1028 func (c *genAiTuningRESTClient) CancelTuningJob(ctx context.Context, req *aiplatformpb.CancelTuningJobRequest, opts ...gax.CallOption) error { 1029 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1030 jsonReq, err := m.Marshal(req) 1031 if err != nil { 1032 return err 1033 } 1034 1035 baseUrl, err := url.Parse(c.endpoint) 1036 if err != nil { 1037 return err 1038 } 1039 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:cancel", req.GetName()) 1040 1041 params := url.Values{} 1042 params.Add("$alt", "json;enum-encoding=int") 1043 1044 baseUrl.RawQuery = params.Encode() 1045 1046 // Build HTTP headers from client and context metadata. 1047 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1048 1049 hds = append(c.xGoogHeaders, hds...) 1050 hds = append(hds, "Content-Type", "application/json") 1051 headers := gax.BuildHeaders(ctx, hds...) 1052 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1053 if settings.Path != "" { 1054 baseUrl.Path = settings.Path 1055 } 1056 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1057 if err != nil { 1058 return err 1059 } 1060 httpReq = httpReq.WithContext(ctx) 1061 httpReq.Header = headers 1062 1063 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelTuningJob") 1064 return err 1065 }, opts...) 1066 } 1067 1068 // RebaseTunedModel rebase a TunedModel. 1069 // Creates a LongRunningOperation that takes a legacy Tuned GenAI model 1070 // Reference and creates a TuningJob based on newly available model. 1071 func (c *genAiTuningRESTClient) RebaseTunedModel(ctx context.Context, req *aiplatformpb.RebaseTunedModelRequest, opts ...gax.CallOption) (*RebaseTunedModelOperation, error) { 1072 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1073 jsonReq, err := m.Marshal(req) 1074 if err != nil { 1075 return nil, err 1076 } 1077 1078 baseUrl, err := url.Parse(c.endpoint) 1079 if err != nil { 1080 return nil, err 1081 } 1082 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/tuningJobs:rebaseTunedModel", req.GetParent()) 1083 1084 params := url.Values{} 1085 params.Add("$alt", "json;enum-encoding=int") 1086 1087 baseUrl.RawQuery = params.Encode() 1088 1089 // Build HTTP headers from client and context metadata. 1090 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 1091 1092 hds = append(c.xGoogHeaders, hds...) 1093 hds = append(hds, "Content-Type", "application/json") 1094 headers := gax.BuildHeaders(ctx, hds...) 1095 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1096 resp := &longrunningpb.Operation{} 1097 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1098 if settings.Path != "" { 1099 baseUrl.Path = settings.Path 1100 } 1101 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1102 if err != nil { 1103 return err 1104 } 1105 httpReq = httpReq.WithContext(ctx) 1106 httpReq.Header = headers 1107 1108 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RebaseTunedModel") 1109 if err != nil { 1110 return err 1111 } 1112 if err := unm.Unmarshal(buf, resp); err != nil { 1113 return err 1114 } 1115 1116 return nil 1117 }, opts...) 1118 if e != nil { 1119 return nil, e 1120 } 1121 1122 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1123 return &RebaseTunedModelOperation{ 1124 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1125 pollPath: override, 1126 }, nil 1127 } 1128 1129 // GetLocation gets information about a location. 1130 func (c *genAiTuningRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 1131 baseUrl, err := url.Parse(c.endpoint) 1132 if err != nil { 1133 return nil, err 1134 } 1135 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1136 1137 params := url.Values{} 1138 params.Add("$alt", "json;enum-encoding=int") 1139 1140 baseUrl.RawQuery = params.Encode() 1141 1142 // Build HTTP headers from client and context metadata. 1143 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1144 1145 hds = append(c.xGoogHeaders, hds...) 1146 hds = append(hds, "Content-Type", "application/json") 1147 headers := gax.BuildHeaders(ctx, hds...) 1148 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 1149 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1150 resp := &locationpb.Location{} 1151 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1152 if settings.Path != "" { 1153 baseUrl.Path = settings.Path 1154 } 1155 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1156 if err != nil { 1157 return err 1158 } 1159 httpReq = httpReq.WithContext(ctx) 1160 httpReq.Header = headers 1161 1162 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") 1163 if err != nil { 1164 return err 1165 } 1166 1167 if err := unm.Unmarshal(buf, resp); err != nil { 1168 return err 1169 } 1170 1171 return nil 1172 }, opts...) 1173 if e != nil { 1174 return nil, e 1175 } 1176 return resp, nil 1177 } 1178 1179 // ListLocations lists information about the supported locations for this service. 1180 func (c *genAiTuningRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 1181 it := &LocationIterator{} 1182 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 1183 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1184 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 1185 resp := &locationpb.ListLocationsResponse{} 1186 if pageToken != "" { 1187 req.PageToken = pageToken 1188 } 1189 if pageSize > math.MaxInt32 { 1190 req.PageSize = math.MaxInt32 1191 } else if pageSize != 0 { 1192 req.PageSize = int32(pageSize) 1193 } 1194 baseUrl, err := url.Parse(c.endpoint) 1195 if err != nil { 1196 return nil, "", err 1197 } 1198 baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName()) 1199 1200 params := url.Values{} 1201 params.Add("$alt", "json;enum-encoding=int") 1202 if req.GetFilter() != "" { 1203 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1204 } 1205 if req.GetPageSize() != 0 { 1206 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1207 } 1208 if req.GetPageToken() != "" { 1209 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1210 } 1211 1212 baseUrl.RawQuery = params.Encode() 1213 1214 // Build HTTP headers from client and context metadata. 1215 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1216 headers := gax.BuildHeaders(ctx, hds...) 1217 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1218 if settings.Path != "" { 1219 baseUrl.Path = settings.Path 1220 } 1221 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1222 if err != nil { 1223 return err 1224 } 1225 httpReq.Header = headers 1226 1227 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") 1228 if err != nil { 1229 return err 1230 } 1231 if err := unm.Unmarshal(buf, resp); err != nil { 1232 return err 1233 } 1234 1235 return nil 1236 }, opts...) 1237 if e != nil { 1238 return nil, "", e 1239 } 1240 it.Response = resp 1241 return resp.GetLocations(), resp.GetNextPageToken(), nil 1242 } 1243 1244 fetch := func(pageSize int, pageToken string) (string, error) { 1245 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1246 if err != nil { 1247 return "", err 1248 } 1249 it.items = append(it.items, items...) 1250 return nextPageToken, nil 1251 } 1252 1253 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1254 it.pageInfo.MaxSize = int(req.GetPageSize()) 1255 it.pageInfo.Token = req.GetPageToken() 1256 1257 return it 1258 } 1259 1260 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 1261 // if the resource exists and does not have a policy set. 1262 func (c *genAiTuningRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1263 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1264 jsonReq, err := m.Marshal(req) 1265 if err != nil { 1266 return nil, err 1267 } 1268 1269 baseUrl, err := url.Parse(c.endpoint) 1270 if err != nil { 1271 return nil, err 1272 } 1273 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource()) 1274 1275 params := url.Values{} 1276 params.Add("$alt", "json;enum-encoding=int") 1277 1278 baseUrl.RawQuery = params.Encode() 1279 1280 // Build HTTP headers from client and context metadata. 1281 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1282 1283 hds = append(c.xGoogHeaders, hds...) 1284 hds = append(hds, "Content-Type", "application/json") 1285 headers := gax.BuildHeaders(ctx, hds...) 1286 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 1287 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1288 resp := &iampb.Policy{} 1289 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1290 if settings.Path != "" { 1291 baseUrl.Path = settings.Path 1292 } 1293 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1294 if err != nil { 1295 return err 1296 } 1297 httpReq = httpReq.WithContext(ctx) 1298 httpReq.Header = headers 1299 1300 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy") 1301 if err != nil { 1302 return err 1303 } 1304 1305 if err := unm.Unmarshal(buf, resp); err != nil { 1306 return err 1307 } 1308 1309 return nil 1310 }, opts...) 1311 if e != nil { 1312 return nil, e 1313 } 1314 return resp, nil 1315 } 1316 1317 // SetIamPolicy sets the access control policy on the specified resource. Replaces 1318 // any existing policy. 1319 // 1320 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 1321 // errors. 1322 func (c *genAiTuningRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1323 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1324 jsonReq, err := m.Marshal(req) 1325 if err != nil { 1326 return nil, err 1327 } 1328 1329 baseUrl, err := url.Parse(c.endpoint) 1330 if err != nil { 1331 return nil, err 1332 } 1333 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource()) 1334 1335 params := url.Values{} 1336 params.Add("$alt", "json;enum-encoding=int") 1337 1338 baseUrl.RawQuery = params.Encode() 1339 1340 // Build HTTP headers from client and context metadata. 1341 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1342 1343 hds = append(c.xGoogHeaders, hds...) 1344 hds = append(hds, "Content-Type", "application/json") 1345 headers := gax.BuildHeaders(ctx, hds...) 1346 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 1347 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1348 resp := &iampb.Policy{} 1349 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1350 if settings.Path != "" { 1351 baseUrl.Path = settings.Path 1352 } 1353 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1354 if err != nil { 1355 return err 1356 } 1357 httpReq = httpReq.WithContext(ctx) 1358 httpReq.Header = headers 1359 1360 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy") 1361 if err != nil { 1362 return err 1363 } 1364 1365 if err := unm.Unmarshal(buf, resp); err != nil { 1366 return err 1367 } 1368 1369 return nil 1370 }, opts...) 1371 if e != nil { 1372 return nil, e 1373 } 1374 return resp, nil 1375 } 1376 1377 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 1378 // resource does not exist, this will return an empty set of 1379 // permissions, not a NOT_FOUND error. 1380 // 1381 // Note: This operation is designed to be used for building 1382 // permission-aware UIs and command-line tools, not for authorization 1383 // checking. This operation may “fail open” without warning. 1384 func (c *genAiTuningRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 1385 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1386 jsonReq, err := m.Marshal(req) 1387 if err != nil { 1388 return nil, err 1389 } 1390 1391 baseUrl, err := url.Parse(c.endpoint) 1392 if err != nil { 1393 return nil, err 1394 } 1395 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource()) 1396 1397 params := url.Values{} 1398 params.Add("$alt", "json;enum-encoding=int") 1399 1400 baseUrl.RawQuery = params.Encode() 1401 1402 // Build HTTP headers from client and context metadata. 1403 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1404 1405 hds = append(c.xGoogHeaders, hds...) 1406 hds = append(hds, "Content-Type", "application/json") 1407 headers := gax.BuildHeaders(ctx, hds...) 1408 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 1409 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1410 resp := &iampb.TestIamPermissionsResponse{} 1411 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1412 if settings.Path != "" { 1413 baseUrl.Path = settings.Path 1414 } 1415 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1416 if err != nil { 1417 return err 1418 } 1419 httpReq = httpReq.WithContext(ctx) 1420 httpReq.Header = headers 1421 1422 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions") 1423 if err != nil { 1424 return err 1425 } 1426 1427 if err := unm.Unmarshal(buf, resp); err != nil { 1428 return err 1429 } 1430 1431 return nil 1432 }, opts...) 1433 if e != nil { 1434 return nil, e 1435 } 1436 return resp, nil 1437 } 1438 1439 // CancelOperation is a utility method from google.longrunning.Operations. 1440 func (c *genAiTuningRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 1441 baseUrl, err := url.Parse(c.endpoint) 1442 if err != nil { 1443 return err 1444 } 1445 baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName()) 1446 1447 params := url.Values{} 1448 params.Add("$alt", "json;enum-encoding=int") 1449 1450 baseUrl.RawQuery = params.Encode() 1451 1452 // Build HTTP headers from client and context metadata. 1453 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1454 1455 hds = append(c.xGoogHeaders, hds...) 1456 hds = append(hds, "Content-Type", "application/json") 1457 headers := gax.BuildHeaders(ctx, hds...) 1458 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1459 if settings.Path != "" { 1460 baseUrl.Path = settings.Path 1461 } 1462 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 1463 if err != nil { 1464 return err 1465 } 1466 httpReq = httpReq.WithContext(ctx) 1467 httpReq.Header = headers 1468 1469 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation") 1470 return err 1471 }, opts...) 1472 } 1473 1474 // DeleteOperation is a utility method from google.longrunning.Operations. 1475 func (c *genAiTuningRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 1476 baseUrl, err := url.Parse(c.endpoint) 1477 if err != nil { 1478 return err 1479 } 1480 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1481 1482 params := url.Values{} 1483 params.Add("$alt", "json;enum-encoding=int") 1484 1485 baseUrl.RawQuery = params.Encode() 1486 1487 // Build HTTP headers from client and context metadata. 1488 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1489 1490 hds = append(c.xGoogHeaders, hds...) 1491 hds = append(hds, "Content-Type", "application/json") 1492 headers := gax.BuildHeaders(ctx, hds...) 1493 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1494 if settings.Path != "" { 1495 baseUrl.Path = settings.Path 1496 } 1497 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1498 if err != nil { 1499 return err 1500 } 1501 httpReq = httpReq.WithContext(ctx) 1502 httpReq.Header = headers 1503 1504 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") 1505 return err 1506 }, opts...) 1507 } 1508 1509 // GetOperation is a utility method from google.longrunning.Operations. 1510 func (c *genAiTuningRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1511 baseUrl, err := url.Parse(c.endpoint) 1512 if err != nil { 1513 return nil, err 1514 } 1515 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1516 1517 params := url.Values{} 1518 params.Add("$alt", "json;enum-encoding=int") 1519 1520 baseUrl.RawQuery = params.Encode() 1521 1522 // Build HTTP headers from client and context metadata. 1523 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1524 1525 hds = append(c.xGoogHeaders, hds...) 1526 hds = append(hds, "Content-Type", "application/json") 1527 headers := gax.BuildHeaders(ctx, hds...) 1528 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 1529 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1530 resp := &longrunningpb.Operation{} 1531 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1532 if settings.Path != "" { 1533 baseUrl.Path = settings.Path 1534 } 1535 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1536 if err != nil { 1537 return err 1538 } 1539 httpReq = httpReq.WithContext(ctx) 1540 httpReq.Header = headers 1541 1542 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") 1543 if err != nil { 1544 return err 1545 } 1546 1547 if err := unm.Unmarshal(buf, resp); err != nil { 1548 return err 1549 } 1550 1551 return nil 1552 }, opts...) 1553 if e != nil { 1554 return nil, e 1555 } 1556 return resp, nil 1557 } 1558 1559 // ListOperations is a utility method from google.longrunning.Operations. 1560 func (c *genAiTuningRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 1561 it := &OperationIterator{} 1562 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 1563 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1564 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 1565 resp := &longrunningpb.ListOperationsResponse{} 1566 if pageToken != "" { 1567 req.PageToken = pageToken 1568 } 1569 if pageSize > math.MaxInt32 { 1570 req.PageSize = math.MaxInt32 1571 } else if pageSize != 0 { 1572 req.PageSize = int32(pageSize) 1573 } 1574 baseUrl, err := url.Parse(c.endpoint) 1575 if err != nil { 1576 return nil, "", err 1577 } 1578 baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName()) 1579 1580 params := url.Values{} 1581 params.Add("$alt", "json;enum-encoding=int") 1582 if req.GetFilter() != "" { 1583 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1584 } 1585 if req.GetPageSize() != 0 { 1586 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1587 } 1588 if req.GetPageToken() != "" { 1589 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1590 } 1591 1592 baseUrl.RawQuery = params.Encode() 1593 1594 // Build HTTP headers from client and context metadata. 1595 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1596 headers := gax.BuildHeaders(ctx, hds...) 1597 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1598 if settings.Path != "" { 1599 baseUrl.Path = settings.Path 1600 } 1601 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1602 if err != nil { 1603 return err 1604 } 1605 httpReq.Header = headers 1606 1607 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") 1608 if err != nil { 1609 return err 1610 } 1611 if err := unm.Unmarshal(buf, resp); err != nil { 1612 return err 1613 } 1614 1615 return nil 1616 }, opts...) 1617 if e != nil { 1618 return nil, "", e 1619 } 1620 it.Response = resp 1621 return resp.GetOperations(), resp.GetNextPageToken(), nil 1622 } 1623 1624 fetch := func(pageSize int, pageToken string) (string, error) { 1625 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1626 if err != nil { 1627 return "", err 1628 } 1629 it.items = append(it.items, items...) 1630 return nextPageToken, nil 1631 } 1632 1633 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1634 it.pageInfo.MaxSize = int(req.GetPageSize()) 1635 it.pageInfo.Token = req.GetPageToken() 1636 1637 return it 1638 } 1639 1640 // WaitOperation is a utility method from google.longrunning.Operations. 1641 func (c *genAiTuningRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1642 baseUrl, err := url.Parse(c.endpoint) 1643 if err != nil { 1644 return nil, err 1645 } 1646 baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName()) 1647 1648 params := url.Values{} 1649 params.Add("$alt", "json;enum-encoding=int") 1650 if req.GetTimeout() != nil { 1651 field, err := protojson.Marshal(req.GetTimeout()) 1652 if err != nil { 1653 return nil, err 1654 } 1655 params.Add("timeout", string(field[1:len(field)-1])) 1656 } 1657 1658 baseUrl.RawQuery = params.Encode() 1659 1660 // Build HTTP headers from client and context metadata. 1661 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1662 1663 hds = append(c.xGoogHeaders, hds...) 1664 hds = append(hds, "Content-Type", "application/json") 1665 headers := gax.BuildHeaders(ctx, hds...) 1666 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 1667 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1668 resp := &longrunningpb.Operation{} 1669 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1670 if settings.Path != "" { 1671 baseUrl.Path = settings.Path 1672 } 1673 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 1674 if err != nil { 1675 return err 1676 } 1677 httpReq = httpReq.WithContext(ctx) 1678 httpReq.Header = headers 1679 1680 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation") 1681 if err != nil { 1682 return err 1683 } 1684 1685 if err := unm.Unmarshal(buf, resp); err != nil { 1686 return err 1687 } 1688 1689 return nil 1690 }, opts...) 1691 if e != nil { 1692 return nil, e 1693 } 1694 return resp, nil 1695 } 1696 1697 // RebaseTunedModelOperation returns a new RebaseTunedModelOperation from a given name. 1698 // The name must be that of a previously created RebaseTunedModelOperation, possibly from a different process. 1699 func (c *genAiTuningGRPCClient) RebaseTunedModelOperation(name string) *RebaseTunedModelOperation { 1700 return &RebaseTunedModelOperation{ 1701 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1702 } 1703 } 1704 1705 // RebaseTunedModelOperation returns a new RebaseTunedModelOperation from a given name. 1706 // The name must be that of a previously created RebaseTunedModelOperation, possibly from a different process. 1707 func (c *genAiTuningRESTClient) RebaseTunedModelOperation(name string) *RebaseTunedModelOperation { 1708 override := fmt.Sprintf("/ui/%s", name) 1709 return &RebaseTunedModelOperation{ 1710 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1711 pollPath: override, 1712 } 1713 }