cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/endpoint_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 ExampleNewEndpointClient() { 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.NewEndpointClient(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 ExampleNewEndpointRESTClient() { 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.NewEndpointRESTClient(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 ExampleEndpointClient_CreateEndpoint() { 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.NewEndpointClient(ctx) 72 if err != nil { 73 // TODO: Handle error. 74 } 75 defer c.Close() 76 77 req := &aiplatformpb.CreateEndpointRequest{ 78 // TODO: Fill request struct fields. 79 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#CreateEndpointRequest. 80 } 81 op, err := c.CreateEndpoint(ctx, req) 82 if err != nil { 83 // TODO: Handle error. 84 } 85 86 resp, err := op.Wait(ctx) 87 if err != nil { 88 // TODO: Handle error. 89 } 90 // TODO: Use resp. 91 _ = resp 92 } 93 94 func ExampleEndpointClient_DeleteEndpoint() { 95 ctx := context.Background() 96 // This snippet has been automatically generated and should be regarded as a code template only. 97 // It will require modifications to work: 98 // - It may require correct/in-range values for request initialization. 99 // - It may require specifying regional endpoints when creating the service client as shown in: 100 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 101 c, err := aiplatform.NewEndpointClient(ctx) 102 if err != nil { 103 // TODO: Handle error. 104 } 105 defer c.Close() 106 107 req := &aiplatformpb.DeleteEndpointRequest{ 108 // TODO: Fill request struct fields. 109 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#DeleteEndpointRequest. 110 } 111 op, err := c.DeleteEndpoint(ctx, req) 112 if err != nil { 113 // TODO: Handle error. 114 } 115 116 err = op.Wait(ctx) 117 if err != nil { 118 // TODO: Handle error. 119 } 120 } 121 122 func ExampleEndpointClient_DeployModel() { 123 ctx := context.Background() 124 // This snippet has been automatically generated and should be regarded as a code template only. 125 // It will require modifications to work: 126 // - It may require correct/in-range values for request initialization. 127 // - It may require specifying regional endpoints when creating the service client as shown in: 128 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 129 c, err := aiplatform.NewEndpointClient(ctx) 130 if err != nil { 131 // TODO: Handle error. 132 } 133 defer c.Close() 134 135 req := &aiplatformpb.DeployModelRequest{ 136 // TODO: Fill request struct fields. 137 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#DeployModelRequest. 138 } 139 op, err := c.DeployModel(ctx, req) 140 if err != nil { 141 // TODO: Handle error. 142 } 143 144 resp, err := op.Wait(ctx) 145 if err != nil { 146 // TODO: Handle error. 147 } 148 // TODO: Use resp. 149 _ = resp 150 } 151 152 func ExampleEndpointClient_FetchPublisherModelConfig() { 153 ctx := context.Background() 154 // This snippet has been automatically generated and should be regarded as a code template only. 155 // It will require modifications to work: 156 // - It may require correct/in-range values for request initialization. 157 // - It may require specifying regional endpoints when creating the service client as shown in: 158 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 159 c, err := aiplatform.NewEndpointClient(ctx) 160 if err != nil { 161 // TODO: Handle error. 162 } 163 defer c.Close() 164 165 req := &aiplatformpb.FetchPublisherModelConfigRequest{ 166 // TODO: Fill request struct fields. 167 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#FetchPublisherModelConfigRequest. 168 } 169 resp, err := c.FetchPublisherModelConfig(ctx, req) 170 if err != nil { 171 // TODO: Handle error. 172 } 173 // TODO: Use resp. 174 _ = resp 175 } 176 177 func ExampleEndpointClient_GetEndpoint() { 178 ctx := context.Background() 179 // This snippet has been automatically generated and should be regarded as a code template only. 180 // It will require modifications to work: 181 // - It may require correct/in-range values for request initialization. 182 // - It may require specifying regional endpoints when creating the service client as shown in: 183 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 184 c, err := aiplatform.NewEndpointClient(ctx) 185 if err != nil { 186 // TODO: Handle error. 187 } 188 defer c.Close() 189 190 req := &aiplatformpb.GetEndpointRequest{ 191 // TODO: Fill request struct fields. 192 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#GetEndpointRequest. 193 } 194 resp, err := c.GetEndpoint(ctx, req) 195 if err != nil { 196 // TODO: Handle error. 197 } 198 // TODO: Use resp. 199 _ = resp 200 } 201 202 func ExampleEndpointClient_ListEndpoints() { 203 ctx := context.Background() 204 // This snippet has been automatically generated and should be regarded as a code template only. 205 // It will require modifications to work: 206 // - It may require correct/in-range values for request initialization. 207 // - It may require specifying regional endpoints when creating the service client as shown in: 208 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 209 c, err := aiplatform.NewEndpointClient(ctx) 210 if err != nil { 211 // TODO: Handle error. 212 } 213 defer c.Close() 214 215 req := &aiplatformpb.ListEndpointsRequest{ 216 // TODO: Fill request struct fields. 217 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#ListEndpointsRequest. 218 } 219 it := c.ListEndpoints(ctx, req) 220 for { 221 resp, err := it.Next() 222 if err == iterator.Done { 223 break 224 } 225 if err != nil { 226 // TODO: Handle error. 227 } 228 // TODO: Use resp. 229 _ = resp 230 231 // If you need to access the underlying RPC response, 232 // you can do so by casting the `Response` as below. 233 // Otherwise, remove this line. Only populated after 234 // first call to Next(). Not safe for concurrent access. 235 _ = it.Response.(*aiplatformpb.ListEndpointsResponse) 236 } 237 } 238 239 func ExampleEndpointClient_MutateDeployedModel() { 240 ctx := context.Background() 241 // This snippet has been automatically generated and should be regarded as a code template only. 242 // It will require modifications to work: 243 // - It may require correct/in-range values for request initialization. 244 // - It may require specifying regional endpoints when creating the service client as shown in: 245 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 246 c, err := aiplatform.NewEndpointClient(ctx) 247 if err != nil { 248 // TODO: Handle error. 249 } 250 defer c.Close() 251 252 req := &aiplatformpb.MutateDeployedModelRequest{ 253 // TODO: Fill request struct fields. 254 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#MutateDeployedModelRequest. 255 } 256 op, err := c.MutateDeployedModel(ctx, req) 257 if err != nil { 258 // TODO: Handle error. 259 } 260 261 resp, err := op.Wait(ctx) 262 if err != nil { 263 // TODO: Handle error. 264 } 265 // TODO: Use resp. 266 _ = resp 267 } 268 269 func ExampleEndpointClient_SetPublisherModelConfig() { 270 ctx := context.Background() 271 // This snippet has been automatically generated and should be regarded as a code template only. 272 // It will require modifications to work: 273 // - It may require correct/in-range values for request initialization. 274 // - It may require specifying regional endpoints when creating the service client as shown in: 275 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 276 c, err := aiplatform.NewEndpointClient(ctx) 277 if err != nil { 278 // TODO: Handle error. 279 } 280 defer c.Close() 281 282 req := &aiplatformpb.SetPublisherModelConfigRequest{ 283 // TODO: Fill request struct fields. 284 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#SetPublisherModelConfigRequest. 285 } 286 op, err := c.SetPublisherModelConfig(ctx, req) 287 if err != nil { 288 // TODO: Handle error. 289 } 290 291 resp, err := op.Wait(ctx) 292 if err != nil { 293 // TODO: Handle error. 294 } 295 // TODO: Use resp. 296 _ = resp 297 } 298 299 func ExampleEndpointClient_UndeployModel() { 300 ctx := context.Background() 301 // This snippet has been automatically generated and should be regarded as a code template only. 302 // It will require modifications to work: 303 // - It may require correct/in-range values for request initialization. 304 // - It may require specifying regional endpoints when creating the service client as shown in: 305 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 306 c, err := aiplatform.NewEndpointClient(ctx) 307 if err != nil { 308 // TODO: Handle error. 309 } 310 defer c.Close() 311 312 req := &aiplatformpb.UndeployModelRequest{ 313 // TODO: Fill request struct fields. 314 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#UndeployModelRequest. 315 } 316 op, err := c.UndeployModel(ctx, req) 317 if err != nil { 318 // TODO: Handle error. 319 } 320 321 resp, err := op.Wait(ctx) 322 if err != nil { 323 // TODO: Handle error. 324 } 325 // TODO: Use resp. 326 _ = resp 327 } 328 329 func ExampleEndpointClient_UpdateEndpoint() { 330 ctx := context.Background() 331 // This snippet has been automatically generated and should be regarded as a code template only. 332 // It will require modifications to work: 333 // - It may require correct/in-range values for request initialization. 334 // - It may require specifying regional endpoints when creating the service client as shown in: 335 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 336 c, err := aiplatform.NewEndpointClient(ctx) 337 if err != nil { 338 // TODO: Handle error. 339 } 340 defer c.Close() 341 342 req := &aiplatformpb.UpdateEndpointRequest{ 343 // TODO: Fill request struct fields. 344 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#UpdateEndpointRequest. 345 } 346 resp, err := c.UpdateEndpoint(ctx, req) 347 if err != nil { 348 // TODO: Handle error. 349 } 350 // TODO: Use resp. 351 _ = resp 352 } 353 354 func ExampleEndpointClient_UpdateEndpointLongRunning() { 355 ctx := context.Background() 356 // This snippet has been automatically generated and should be regarded as a code template only. 357 // It will require modifications to work: 358 // - It may require correct/in-range values for request initialization. 359 // - It may require specifying regional endpoints when creating the service client as shown in: 360 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 361 c, err := aiplatform.NewEndpointClient(ctx) 362 if err != nil { 363 // TODO: Handle error. 364 } 365 defer c.Close() 366 367 req := &aiplatformpb.UpdateEndpointLongRunningRequest{ 368 // TODO: Fill request struct fields. 369 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#UpdateEndpointLongRunningRequest. 370 } 371 op, err := c.UpdateEndpointLongRunning(ctx, req) 372 if err != nil { 373 // TODO: Handle error. 374 } 375 376 resp, err := op.Wait(ctx) 377 if err != nil { 378 // TODO: Handle error. 379 } 380 // TODO: Use resp. 381 _ = resp 382 } 383 384 func ExampleEndpointClient_GetLocation() { 385 ctx := context.Background() 386 // This snippet has been automatically generated and should be regarded as a code template only. 387 // It will require modifications to work: 388 // - It may require correct/in-range values for request initialization. 389 // - It may require specifying regional endpoints when creating the service client as shown in: 390 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 391 c, err := aiplatform.NewEndpointClient(ctx) 392 if err != nil { 393 // TODO: Handle error. 394 } 395 defer c.Close() 396 397 req := &locationpb.GetLocationRequest{ 398 // TODO: Fill request struct fields. 399 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 400 } 401 resp, err := c.GetLocation(ctx, req) 402 if err != nil { 403 // TODO: Handle error. 404 } 405 // TODO: Use resp. 406 _ = resp 407 } 408 409 func ExampleEndpointClient_ListLocations() { 410 ctx := context.Background() 411 // This snippet has been automatically generated and should be regarded as a code template only. 412 // It will require modifications to work: 413 // - It may require correct/in-range values for request initialization. 414 // - It may require specifying regional endpoints when creating the service client as shown in: 415 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 416 c, err := aiplatform.NewEndpointClient(ctx) 417 if err != nil { 418 // TODO: Handle error. 419 } 420 defer c.Close() 421 422 req := &locationpb.ListLocationsRequest{ 423 // TODO: Fill request struct fields. 424 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 425 } 426 it := c.ListLocations(ctx, req) 427 for { 428 resp, err := it.Next() 429 if err == iterator.Done { 430 break 431 } 432 if err != nil { 433 // TODO: Handle error. 434 } 435 // TODO: Use resp. 436 _ = resp 437 438 // If you need to access the underlying RPC response, 439 // you can do so by casting the `Response` as below. 440 // Otherwise, remove this line. Only populated after 441 // first call to Next(). Not safe for concurrent access. 442 _ = it.Response.(*locationpb.ListLocationsResponse) 443 } 444 } 445 446 func ExampleEndpointClient_GetIamPolicy() { 447 ctx := context.Background() 448 // This snippet has been automatically generated and should be regarded as a code template only. 449 // It will require modifications to work: 450 // - It may require correct/in-range values for request initialization. 451 // - It may require specifying regional endpoints when creating the service client as shown in: 452 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 453 c, err := aiplatform.NewEndpointClient(ctx) 454 if err != nil { 455 // TODO: Handle error. 456 } 457 defer c.Close() 458 459 req := &iampb.GetIamPolicyRequest{ 460 // TODO: Fill request struct fields. 461 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 462 } 463 resp, err := c.GetIamPolicy(ctx, req) 464 if err != nil { 465 // TODO: Handle error. 466 } 467 // TODO: Use resp. 468 _ = resp 469 } 470 471 func ExampleEndpointClient_SetIamPolicy() { 472 ctx := context.Background() 473 // This snippet has been automatically generated and should be regarded as a code template only. 474 // It will require modifications to work: 475 // - It may require correct/in-range values for request initialization. 476 // - It may require specifying regional endpoints when creating the service client as shown in: 477 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 478 c, err := aiplatform.NewEndpointClient(ctx) 479 if err != nil { 480 // TODO: Handle error. 481 } 482 defer c.Close() 483 484 req := &iampb.SetIamPolicyRequest{ 485 // TODO: Fill request struct fields. 486 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 487 } 488 resp, err := c.SetIamPolicy(ctx, req) 489 if err != nil { 490 // TODO: Handle error. 491 } 492 // TODO: Use resp. 493 _ = resp 494 } 495 496 func ExampleEndpointClient_TestIamPermissions() { 497 ctx := context.Background() 498 // This snippet has been automatically generated and should be regarded as a code template only. 499 // It will require modifications to work: 500 // - It may require correct/in-range values for request initialization. 501 // - It may require specifying regional endpoints when creating the service client as shown in: 502 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 503 c, err := aiplatform.NewEndpointClient(ctx) 504 if err != nil { 505 // TODO: Handle error. 506 } 507 defer c.Close() 508 509 req := &iampb.TestIamPermissionsRequest{ 510 // TODO: Fill request struct fields. 511 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 512 } 513 resp, err := c.TestIamPermissions(ctx, req) 514 if err != nil { 515 // TODO: Handle error. 516 } 517 // TODO: Use resp. 518 _ = resp 519 } 520 521 func ExampleEndpointClient_CancelOperation() { 522 ctx := context.Background() 523 // This snippet has been automatically generated and should be regarded as a code template only. 524 // It will require modifications to work: 525 // - It may require correct/in-range values for request initialization. 526 // - It may require specifying regional endpoints when creating the service client as shown in: 527 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 528 c, err := aiplatform.NewEndpointClient(ctx) 529 if err != nil { 530 // TODO: Handle error. 531 } 532 defer c.Close() 533 534 req := &longrunningpb.CancelOperationRequest{ 535 // TODO: Fill request struct fields. 536 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 537 } 538 err = c.CancelOperation(ctx, req) 539 if err != nil { 540 // TODO: Handle error. 541 } 542 } 543 544 func ExampleEndpointClient_DeleteOperation() { 545 ctx := context.Background() 546 // This snippet has been automatically generated and should be regarded as a code template only. 547 // It will require modifications to work: 548 // - It may require correct/in-range values for request initialization. 549 // - It may require specifying regional endpoints when creating the service client as shown in: 550 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 551 c, err := aiplatform.NewEndpointClient(ctx) 552 if err != nil { 553 // TODO: Handle error. 554 } 555 defer c.Close() 556 557 req := &longrunningpb.DeleteOperationRequest{ 558 // TODO: Fill request struct fields. 559 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 560 } 561 err = c.DeleteOperation(ctx, req) 562 if err != nil { 563 // TODO: Handle error. 564 } 565 } 566 567 func ExampleEndpointClient_GetOperation() { 568 ctx := context.Background() 569 // This snippet has been automatically generated and should be regarded as a code template only. 570 // It will require modifications to work: 571 // - It may require correct/in-range values for request initialization. 572 // - It may require specifying regional endpoints when creating the service client as shown in: 573 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 574 c, err := aiplatform.NewEndpointClient(ctx) 575 if err != nil { 576 // TODO: Handle error. 577 } 578 defer c.Close() 579 580 req := &longrunningpb.GetOperationRequest{ 581 // TODO: Fill request struct fields. 582 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 583 } 584 resp, err := c.GetOperation(ctx, req) 585 if err != nil { 586 // TODO: Handle error. 587 } 588 // TODO: Use resp. 589 _ = resp 590 } 591 592 func ExampleEndpointClient_ListOperations() { 593 ctx := context.Background() 594 // This snippet has been automatically generated and should be regarded as a code template only. 595 // It will require modifications to work: 596 // - It may require correct/in-range values for request initialization. 597 // - It may require specifying regional endpoints when creating the service client as shown in: 598 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 599 c, err := aiplatform.NewEndpointClient(ctx) 600 if err != nil { 601 // TODO: Handle error. 602 } 603 defer c.Close() 604 605 req := &longrunningpb.ListOperationsRequest{ 606 // TODO: Fill request struct fields. 607 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 608 } 609 it := c.ListOperations(ctx, req) 610 for { 611 resp, err := it.Next() 612 if err == iterator.Done { 613 break 614 } 615 if err != nil { 616 // TODO: Handle error. 617 } 618 // TODO: Use resp. 619 _ = resp 620 621 // If you need to access the underlying RPC response, 622 // you can do so by casting the `Response` as below. 623 // Otherwise, remove this line. Only populated after 624 // first call to Next(). Not safe for concurrent access. 625 _ = it.Response.(*longrunningpb.ListOperationsResponse) 626 } 627 } 628 629 func ExampleEndpointClient_WaitOperation() { 630 ctx := context.Background() 631 // This snippet has been automatically generated and should be regarded as a code template only. 632 // It will require modifications to work: 633 // - It may require correct/in-range values for request initialization. 634 // - It may require specifying regional endpoints when creating the service client as shown in: 635 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 636 c, err := aiplatform.NewEndpointClient(ctx) 637 if err != nil { 638 // TODO: Handle error. 639 } 640 defer c.Close() 641 642 req := &longrunningpb.WaitOperationRequest{ 643 // TODO: Fill request struct fields. 644 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 645 } 646 resp, err := c.WaitOperation(ctx, req) 647 if err != nil { 648 // TODO: Handle error. 649 } 650 // TODO: Use resp. 651 _ = resp 652 }