cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/gen_ai_tuning_client_example_test.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_test 18 19 import ( 20 "context" 21 22 aiplatform "cloud.google.com/go/aiplatform/apiv1beta1" 23 aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb" 24 iampb "cloud.google.com/go/iam/apiv1/iampb" 25 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 26 "google.golang.org/api/iterator" 27 locationpb "google.golang.org/genproto/googleapis/cloud/location" 28 ) 29 30 func ExampleNewGenAiTuningClient() { 31 ctx := context.Background() 32 // This snippet has been automatically generated and should be regarded as a code template only. 33 // It will require modifications to work: 34 // - It may require correct/in-range values for request initialization. 35 // - It may require specifying regional endpoints when creating the service client as shown in: 36 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 37 c, err := aiplatform.NewGenAiTuningClient(ctx) 38 if err != nil { 39 // TODO: Handle error. 40 } 41 defer c.Close() 42 43 // TODO: Use client. 44 _ = c 45 } 46 47 func ExampleNewGenAiTuningRESTClient() { 48 ctx := context.Background() 49 // This snippet has been automatically generated and should be regarded as a code template only. 50 // It will require modifications to work: 51 // - It may require correct/in-range values for request initialization. 52 // - It may require specifying regional endpoints when creating the service client as shown in: 53 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 54 c, err := aiplatform.NewGenAiTuningRESTClient(ctx) 55 if err != nil { 56 // TODO: Handle error. 57 } 58 defer c.Close() 59 60 // TODO: Use client. 61 _ = c 62 } 63 64 func ExampleGenAiTuningClient_CancelTuningJob() { 65 ctx := context.Background() 66 // This snippet has been automatically generated and should be regarded as a code template only. 67 // It will require modifications to work: 68 // - It may require correct/in-range values for request initialization. 69 // - It may require specifying regional endpoints when creating the service client as shown in: 70 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 71 c, err := aiplatform.NewGenAiTuningClient(ctx) 72 if err != nil { 73 // TODO: Handle error. 74 } 75 defer c.Close() 76 77 req := &aiplatformpb.CancelTuningJobRequest{ 78 // TODO: Fill request struct fields. 79 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#CancelTuningJobRequest. 80 } 81 err = c.CancelTuningJob(ctx, req) 82 if err != nil { 83 // TODO: Handle error. 84 } 85 } 86 87 func ExampleGenAiTuningClient_CreateTuningJob() { 88 ctx := context.Background() 89 // This snippet has been automatically generated and should be regarded as a code template only. 90 // It will require modifications to work: 91 // - It may require correct/in-range values for request initialization. 92 // - It may require specifying regional endpoints when creating the service client as shown in: 93 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 94 c, err := aiplatform.NewGenAiTuningClient(ctx) 95 if err != nil { 96 // TODO: Handle error. 97 } 98 defer c.Close() 99 100 req := &aiplatformpb.CreateTuningJobRequest{ 101 // TODO: Fill request struct fields. 102 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#CreateTuningJobRequest. 103 } 104 resp, err := c.CreateTuningJob(ctx, req) 105 if err != nil { 106 // TODO: Handle error. 107 } 108 // TODO: Use resp. 109 _ = resp 110 } 111 112 func ExampleGenAiTuningClient_GetTuningJob() { 113 ctx := context.Background() 114 // This snippet has been automatically generated and should be regarded as a code template only. 115 // It will require modifications to work: 116 // - It may require correct/in-range values for request initialization. 117 // - It may require specifying regional endpoints when creating the service client as shown in: 118 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 119 c, err := aiplatform.NewGenAiTuningClient(ctx) 120 if err != nil { 121 // TODO: Handle error. 122 } 123 defer c.Close() 124 125 req := &aiplatformpb.GetTuningJobRequest{ 126 // TODO: Fill request struct fields. 127 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#GetTuningJobRequest. 128 } 129 resp, err := c.GetTuningJob(ctx, req) 130 if err != nil { 131 // TODO: Handle error. 132 } 133 // TODO: Use resp. 134 _ = resp 135 } 136 137 func ExampleGenAiTuningClient_ListTuningJobs() { 138 ctx := context.Background() 139 // This snippet has been automatically generated and should be regarded as a code template only. 140 // It will require modifications to work: 141 // - It may require correct/in-range values for request initialization. 142 // - It may require specifying regional endpoints when creating the service client as shown in: 143 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 144 c, err := aiplatform.NewGenAiTuningClient(ctx) 145 if err != nil { 146 // TODO: Handle error. 147 } 148 defer c.Close() 149 150 req := &aiplatformpb.ListTuningJobsRequest{ 151 // TODO: Fill request struct fields. 152 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#ListTuningJobsRequest. 153 } 154 it := c.ListTuningJobs(ctx, req) 155 for { 156 resp, err := it.Next() 157 if err == iterator.Done { 158 break 159 } 160 if err != nil { 161 // TODO: Handle error. 162 } 163 // TODO: Use resp. 164 _ = resp 165 166 // If you need to access the underlying RPC response, 167 // you can do so by casting the `Response` as below. 168 // Otherwise, remove this line. Only populated after 169 // first call to Next(). Not safe for concurrent access. 170 _ = it.Response.(*aiplatformpb.ListTuningJobsResponse) 171 } 172 } 173 174 func ExampleGenAiTuningClient_RebaseTunedModel() { 175 ctx := context.Background() 176 // This snippet has been automatically generated and should be regarded as a code template only. 177 // It will require modifications to work: 178 // - It may require correct/in-range values for request initialization. 179 // - It may require specifying regional endpoints when creating the service client as shown in: 180 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 181 c, err := aiplatform.NewGenAiTuningClient(ctx) 182 if err != nil { 183 // TODO: Handle error. 184 } 185 defer c.Close() 186 187 req := &aiplatformpb.RebaseTunedModelRequest{ 188 // TODO: Fill request struct fields. 189 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#RebaseTunedModelRequest. 190 } 191 op, err := c.RebaseTunedModel(ctx, req) 192 if err != nil { 193 // TODO: Handle error. 194 } 195 196 resp, err := op.Wait(ctx) 197 if err != nil { 198 // TODO: Handle error. 199 } 200 // TODO: Use resp. 201 _ = resp 202 } 203 204 func ExampleGenAiTuningClient_GetLocation() { 205 ctx := context.Background() 206 // This snippet has been automatically generated and should be regarded as a code template only. 207 // It will require modifications to work: 208 // - It may require correct/in-range values for request initialization. 209 // - It may require specifying regional endpoints when creating the service client as shown in: 210 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 211 c, err := aiplatform.NewGenAiTuningClient(ctx) 212 if err != nil { 213 // TODO: Handle error. 214 } 215 defer c.Close() 216 217 req := &locationpb.GetLocationRequest{ 218 // TODO: Fill request struct fields. 219 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 220 } 221 resp, err := c.GetLocation(ctx, req) 222 if err != nil { 223 // TODO: Handle error. 224 } 225 // TODO: Use resp. 226 _ = resp 227 } 228 229 func ExampleGenAiTuningClient_ListLocations() { 230 ctx := context.Background() 231 // This snippet has been automatically generated and should be regarded as a code template only. 232 // It will require modifications to work: 233 // - It may require correct/in-range values for request initialization. 234 // - It may require specifying regional endpoints when creating the service client as shown in: 235 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 236 c, err := aiplatform.NewGenAiTuningClient(ctx) 237 if err != nil { 238 // TODO: Handle error. 239 } 240 defer c.Close() 241 242 req := &locationpb.ListLocationsRequest{ 243 // TODO: Fill request struct fields. 244 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 245 } 246 it := c.ListLocations(ctx, req) 247 for { 248 resp, err := it.Next() 249 if err == iterator.Done { 250 break 251 } 252 if err != nil { 253 // TODO: Handle error. 254 } 255 // TODO: Use resp. 256 _ = resp 257 258 // If you need to access the underlying RPC response, 259 // you can do so by casting the `Response` as below. 260 // Otherwise, remove this line. Only populated after 261 // first call to Next(). Not safe for concurrent access. 262 _ = it.Response.(*locationpb.ListLocationsResponse) 263 } 264 } 265 266 func ExampleGenAiTuningClient_GetIamPolicy() { 267 ctx := context.Background() 268 // This snippet has been automatically generated and should be regarded as a code template only. 269 // It will require modifications to work: 270 // - It may require correct/in-range values for request initialization. 271 // - It may require specifying regional endpoints when creating the service client as shown in: 272 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 273 c, err := aiplatform.NewGenAiTuningClient(ctx) 274 if err != nil { 275 // TODO: Handle error. 276 } 277 defer c.Close() 278 279 req := &iampb.GetIamPolicyRequest{ 280 // TODO: Fill request struct fields. 281 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 282 } 283 resp, err := c.GetIamPolicy(ctx, req) 284 if err != nil { 285 // TODO: Handle error. 286 } 287 // TODO: Use resp. 288 _ = resp 289 } 290 291 func ExampleGenAiTuningClient_SetIamPolicy() { 292 ctx := context.Background() 293 // This snippet has been automatically generated and should be regarded as a code template only. 294 // It will require modifications to work: 295 // - It may require correct/in-range values for request initialization. 296 // - It may require specifying regional endpoints when creating the service client as shown in: 297 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 298 c, err := aiplatform.NewGenAiTuningClient(ctx) 299 if err != nil { 300 // TODO: Handle error. 301 } 302 defer c.Close() 303 304 req := &iampb.SetIamPolicyRequest{ 305 // TODO: Fill request struct fields. 306 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 307 } 308 resp, err := c.SetIamPolicy(ctx, req) 309 if err != nil { 310 // TODO: Handle error. 311 } 312 // TODO: Use resp. 313 _ = resp 314 } 315 316 func ExampleGenAiTuningClient_TestIamPermissions() { 317 ctx := context.Background() 318 // This snippet has been automatically generated and should be regarded as a code template only. 319 // It will require modifications to work: 320 // - It may require correct/in-range values for request initialization. 321 // - It may require specifying regional endpoints when creating the service client as shown in: 322 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 323 c, err := aiplatform.NewGenAiTuningClient(ctx) 324 if err != nil { 325 // TODO: Handle error. 326 } 327 defer c.Close() 328 329 req := &iampb.TestIamPermissionsRequest{ 330 // TODO: Fill request struct fields. 331 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 332 } 333 resp, err := c.TestIamPermissions(ctx, req) 334 if err != nil { 335 // TODO: Handle error. 336 } 337 // TODO: Use resp. 338 _ = resp 339 } 340 341 func ExampleGenAiTuningClient_CancelOperation() { 342 ctx := context.Background() 343 // This snippet has been automatically generated and should be regarded as a code template only. 344 // It will require modifications to work: 345 // - It may require correct/in-range values for request initialization. 346 // - It may require specifying regional endpoints when creating the service client as shown in: 347 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 348 c, err := aiplatform.NewGenAiTuningClient(ctx) 349 if err != nil { 350 // TODO: Handle error. 351 } 352 defer c.Close() 353 354 req := &longrunningpb.CancelOperationRequest{ 355 // TODO: Fill request struct fields. 356 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 357 } 358 err = c.CancelOperation(ctx, req) 359 if err != nil { 360 // TODO: Handle error. 361 } 362 } 363 364 func ExampleGenAiTuningClient_DeleteOperation() { 365 ctx := context.Background() 366 // This snippet has been automatically generated and should be regarded as a code template only. 367 // It will require modifications to work: 368 // - It may require correct/in-range values for request initialization. 369 // - It may require specifying regional endpoints when creating the service client as shown in: 370 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 371 c, err := aiplatform.NewGenAiTuningClient(ctx) 372 if err != nil { 373 // TODO: Handle error. 374 } 375 defer c.Close() 376 377 req := &longrunningpb.DeleteOperationRequest{ 378 // TODO: Fill request struct fields. 379 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 380 } 381 err = c.DeleteOperation(ctx, req) 382 if err != nil { 383 // TODO: Handle error. 384 } 385 } 386 387 func ExampleGenAiTuningClient_GetOperation() { 388 ctx := context.Background() 389 // This snippet has been automatically generated and should be regarded as a code template only. 390 // It will require modifications to work: 391 // - It may require correct/in-range values for request initialization. 392 // - It may require specifying regional endpoints when creating the service client as shown in: 393 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 394 c, err := aiplatform.NewGenAiTuningClient(ctx) 395 if err != nil { 396 // TODO: Handle error. 397 } 398 defer c.Close() 399 400 req := &longrunningpb.GetOperationRequest{ 401 // TODO: Fill request struct fields. 402 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 403 } 404 resp, err := c.GetOperation(ctx, req) 405 if err != nil { 406 // TODO: Handle error. 407 } 408 // TODO: Use resp. 409 _ = resp 410 } 411 412 func ExampleGenAiTuningClient_ListOperations() { 413 ctx := context.Background() 414 // This snippet has been automatically generated and should be regarded as a code template only. 415 // It will require modifications to work: 416 // - It may require correct/in-range values for request initialization. 417 // - It may require specifying regional endpoints when creating the service client as shown in: 418 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 419 c, err := aiplatform.NewGenAiTuningClient(ctx) 420 if err != nil { 421 // TODO: Handle error. 422 } 423 defer c.Close() 424 425 req := &longrunningpb.ListOperationsRequest{ 426 // TODO: Fill request struct fields. 427 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 428 } 429 it := c.ListOperations(ctx, req) 430 for { 431 resp, err := it.Next() 432 if err == iterator.Done { 433 break 434 } 435 if err != nil { 436 // TODO: Handle error. 437 } 438 // TODO: Use resp. 439 _ = resp 440 441 // If you need to access the underlying RPC response, 442 // you can do so by casting the `Response` as below. 443 // Otherwise, remove this line. Only populated after 444 // first call to Next(). Not safe for concurrent access. 445 _ = it.Response.(*longrunningpb.ListOperationsResponse) 446 } 447 } 448 449 func ExampleGenAiTuningClient_WaitOperation() { 450 ctx := context.Background() 451 // This snippet has been automatically generated and should be regarded as a code template only. 452 // It will require modifications to work: 453 // - It may require correct/in-range values for request initialization. 454 // - It may require specifying regional endpoints when creating the service client as shown in: 455 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 456 c, err := aiplatform.NewGenAiTuningClient(ctx) 457 if err != nil { 458 // TODO: Handle error. 459 } 460 defer c.Close() 461 462 req := &longrunningpb.WaitOperationRequest{ 463 // TODO: Fill request struct fields. 464 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 465 } 466 resp, err := c.WaitOperation(ctx, req) 467 if err != nil { 468 // TODO: Handle error. 469 } 470 // TODO: Use resp. 471 _ = resp 472 }