cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/session_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 ExampleNewSessionClient() { 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.NewSessionClient(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 ExampleNewSessionRESTClient() { 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.NewSessionRESTClient(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 ExampleSessionClient_AppendEvent() { 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.NewSessionClient(ctx) 72 if err != nil { 73 // TODO: Handle error. 74 } 75 defer c.Close() 76 77 req := &aiplatformpb.AppendEventRequest{ 78 // TODO: Fill request struct fields. 79 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#AppendEventRequest. 80 } 81 resp, err := c.AppendEvent(ctx, req) 82 if err != nil { 83 // TODO: Handle error. 84 } 85 // TODO: Use resp. 86 _ = resp 87 } 88 89 func ExampleSessionClient_CreateSession() { 90 ctx := context.Background() 91 // This snippet has been automatically generated and should be regarded as a code template only. 92 // It will require modifications to work: 93 // - It may require correct/in-range values for request initialization. 94 // - It may require specifying regional endpoints when creating the service client as shown in: 95 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 96 c, err := aiplatform.NewSessionClient(ctx) 97 if err != nil { 98 // TODO: Handle error. 99 } 100 defer c.Close() 101 102 req := &aiplatformpb.CreateSessionRequest{ 103 // TODO: Fill request struct fields. 104 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#CreateSessionRequest. 105 } 106 op, err := c.CreateSession(ctx, req) 107 if err != nil { 108 // TODO: Handle error. 109 } 110 111 resp, err := op.Wait(ctx) 112 if err != nil { 113 // TODO: Handle error. 114 } 115 // TODO: Use resp. 116 _ = resp 117 } 118 119 func ExampleSessionClient_DeleteSession() { 120 ctx := context.Background() 121 // This snippet has been automatically generated and should be regarded as a code template only. 122 // It will require modifications to work: 123 // - It may require correct/in-range values for request initialization. 124 // - It may require specifying regional endpoints when creating the service client as shown in: 125 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 126 c, err := aiplatform.NewSessionClient(ctx) 127 if err != nil { 128 // TODO: Handle error. 129 } 130 defer c.Close() 131 132 req := &aiplatformpb.DeleteSessionRequest{ 133 // TODO: Fill request struct fields. 134 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#DeleteSessionRequest. 135 } 136 op, err := c.DeleteSession(ctx, req) 137 if err != nil { 138 // TODO: Handle error. 139 } 140 141 err = op.Wait(ctx) 142 if err != nil { 143 // TODO: Handle error. 144 } 145 } 146 147 func ExampleSessionClient_GetSession() { 148 ctx := context.Background() 149 // This snippet has been automatically generated and should be regarded as a code template only. 150 // It will require modifications to work: 151 // - It may require correct/in-range values for request initialization. 152 // - It may require specifying regional endpoints when creating the service client as shown in: 153 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 154 c, err := aiplatform.NewSessionClient(ctx) 155 if err != nil { 156 // TODO: Handle error. 157 } 158 defer c.Close() 159 160 req := &aiplatformpb.GetSessionRequest{ 161 // TODO: Fill request struct fields. 162 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#GetSessionRequest. 163 } 164 resp, err := c.GetSession(ctx, req) 165 if err != nil { 166 // TODO: Handle error. 167 } 168 // TODO: Use resp. 169 _ = resp 170 } 171 172 func ExampleSessionClient_ListEvents() { 173 ctx := context.Background() 174 // This snippet has been automatically generated and should be regarded as a code template only. 175 // It will require modifications to work: 176 // - It may require correct/in-range values for request initialization. 177 // - It may require specifying regional endpoints when creating the service client as shown in: 178 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 179 c, err := aiplatform.NewSessionClient(ctx) 180 if err != nil { 181 // TODO: Handle error. 182 } 183 defer c.Close() 184 185 req := &aiplatformpb.ListEventsRequest{ 186 // TODO: Fill request struct fields. 187 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#ListEventsRequest. 188 } 189 it := c.ListEvents(ctx, req) 190 for { 191 resp, err := it.Next() 192 if err == iterator.Done { 193 break 194 } 195 if err != nil { 196 // TODO: Handle error. 197 } 198 // TODO: Use resp. 199 _ = resp 200 201 // If you need to access the underlying RPC response, 202 // you can do so by casting the `Response` as below. 203 // Otherwise, remove this line. Only populated after 204 // first call to Next(). Not safe for concurrent access. 205 _ = it.Response.(*aiplatformpb.ListEventsResponse) 206 } 207 } 208 209 func ExampleSessionClient_ListSessions() { 210 ctx := context.Background() 211 // This snippet has been automatically generated and should be regarded as a code template only. 212 // It will require modifications to work: 213 // - It may require correct/in-range values for request initialization. 214 // - It may require specifying regional endpoints when creating the service client as shown in: 215 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 216 c, err := aiplatform.NewSessionClient(ctx) 217 if err != nil { 218 // TODO: Handle error. 219 } 220 defer c.Close() 221 222 req := &aiplatformpb.ListSessionsRequest{ 223 // TODO: Fill request struct fields. 224 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#ListSessionsRequest. 225 } 226 it := c.ListSessions(ctx, req) 227 for { 228 resp, err := it.Next() 229 if err == iterator.Done { 230 break 231 } 232 if err != nil { 233 // TODO: Handle error. 234 } 235 // TODO: Use resp. 236 _ = resp 237 238 // If you need to access the underlying RPC response, 239 // you can do so by casting the `Response` as below. 240 // Otherwise, remove this line. Only populated after 241 // first call to Next(). Not safe for concurrent access. 242 _ = it.Response.(*aiplatformpb.ListSessionsResponse) 243 } 244 } 245 246 func ExampleSessionClient_UpdateSession() { 247 ctx := context.Background() 248 // This snippet has been automatically generated and should be regarded as a code template only. 249 // It will require modifications to work: 250 // - It may require correct/in-range values for request initialization. 251 // - It may require specifying regional endpoints when creating the service client as shown in: 252 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 253 c, err := aiplatform.NewSessionClient(ctx) 254 if err != nil { 255 // TODO: Handle error. 256 } 257 defer c.Close() 258 259 req := &aiplatformpb.UpdateSessionRequest{ 260 // TODO: Fill request struct fields. 261 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#UpdateSessionRequest. 262 } 263 resp, err := c.UpdateSession(ctx, req) 264 if err != nil { 265 // TODO: Handle error. 266 } 267 // TODO: Use resp. 268 _ = resp 269 } 270 271 func ExampleSessionClient_GetLocation() { 272 ctx := context.Background() 273 // This snippet has been automatically generated and should be regarded as a code template only. 274 // It will require modifications to work: 275 // - It may require correct/in-range values for request initialization. 276 // - It may require specifying regional endpoints when creating the service client as shown in: 277 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 278 c, err := aiplatform.NewSessionClient(ctx) 279 if err != nil { 280 // TODO: Handle error. 281 } 282 defer c.Close() 283 284 req := &locationpb.GetLocationRequest{ 285 // TODO: Fill request struct fields. 286 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 287 } 288 resp, err := c.GetLocation(ctx, req) 289 if err != nil { 290 // TODO: Handle error. 291 } 292 // TODO: Use resp. 293 _ = resp 294 } 295 296 func ExampleSessionClient_ListLocations() { 297 ctx := context.Background() 298 // This snippet has been automatically generated and should be regarded as a code template only. 299 // It will require modifications to work: 300 // - It may require correct/in-range values for request initialization. 301 // - It may require specifying regional endpoints when creating the service client as shown in: 302 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 303 c, err := aiplatform.NewSessionClient(ctx) 304 if err != nil { 305 // TODO: Handle error. 306 } 307 defer c.Close() 308 309 req := &locationpb.ListLocationsRequest{ 310 // TODO: Fill request struct fields. 311 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 312 } 313 it := c.ListLocations(ctx, req) 314 for { 315 resp, err := it.Next() 316 if err == iterator.Done { 317 break 318 } 319 if err != nil { 320 // TODO: Handle error. 321 } 322 // TODO: Use resp. 323 _ = resp 324 325 // If you need to access the underlying RPC response, 326 // you can do so by casting the `Response` as below. 327 // Otherwise, remove this line. Only populated after 328 // first call to Next(). Not safe for concurrent access. 329 _ = it.Response.(*locationpb.ListLocationsResponse) 330 } 331 } 332 333 func ExampleSessionClient_GetIamPolicy() { 334 ctx := context.Background() 335 // This snippet has been automatically generated and should be regarded as a code template only. 336 // It will require modifications to work: 337 // - It may require correct/in-range values for request initialization. 338 // - It may require specifying regional endpoints when creating the service client as shown in: 339 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 340 c, err := aiplatform.NewSessionClient(ctx) 341 if err != nil { 342 // TODO: Handle error. 343 } 344 defer c.Close() 345 346 req := &iampb.GetIamPolicyRequest{ 347 // TODO: Fill request struct fields. 348 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 349 } 350 resp, err := c.GetIamPolicy(ctx, req) 351 if err != nil { 352 // TODO: Handle error. 353 } 354 // TODO: Use resp. 355 _ = resp 356 } 357 358 func ExampleSessionClient_SetIamPolicy() { 359 ctx := context.Background() 360 // This snippet has been automatically generated and should be regarded as a code template only. 361 // It will require modifications to work: 362 // - It may require correct/in-range values for request initialization. 363 // - It may require specifying regional endpoints when creating the service client as shown in: 364 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 365 c, err := aiplatform.NewSessionClient(ctx) 366 if err != nil { 367 // TODO: Handle error. 368 } 369 defer c.Close() 370 371 req := &iampb.SetIamPolicyRequest{ 372 // TODO: Fill request struct fields. 373 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 374 } 375 resp, err := c.SetIamPolicy(ctx, req) 376 if err != nil { 377 // TODO: Handle error. 378 } 379 // TODO: Use resp. 380 _ = resp 381 } 382 383 func ExampleSessionClient_TestIamPermissions() { 384 ctx := context.Background() 385 // This snippet has been automatically generated and should be regarded as a code template only. 386 // It will require modifications to work: 387 // - It may require correct/in-range values for request initialization. 388 // - It may require specifying regional endpoints when creating the service client as shown in: 389 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 390 c, err := aiplatform.NewSessionClient(ctx) 391 if err != nil { 392 // TODO: Handle error. 393 } 394 defer c.Close() 395 396 req := &iampb.TestIamPermissionsRequest{ 397 // TODO: Fill request struct fields. 398 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 399 } 400 resp, err := c.TestIamPermissions(ctx, req) 401 if err != nil { 402 // TODO: Handle error. 403 } 404 // TODO: Use resp. 405 _ = resp 406 } 407 408 func ExampleSessionClient_CancelOperation() { 409 ctx := context.Background() 410 // This snippet has been automatically generated and should be regarded as a code template only. 411 // It will require modifications to work: 412 // - It may require correct/in-range values for request initialization. 413 // - It may require specifying regional endpoints when creating the service client as shown in: 414 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 415 c, err := aiplatform.NewSessionClient(ctx) 416 if err != nil { 417 // TODO: Handle error. 418 } 419 defer c.Close() 420 421 req := &longrunningpb.CancelOperationRequest{ 422 // TODO: Fill request struct fields. 423 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 424 } 425 err = c.CancelOperation(ctx, req) 426 if err != nil { 427 // TODO: Handle error. 428 } 429 } 430 431 func ExampleSessionClient_DeleteOperation() { 432 ctx := context.Background() 433 // This snippet has been automatically generated and should be regarded as a code template only. 434 // It will require modifications to work: 435 // - It may require correct/in-range values for request initialization. 436 // - It may require specifying regional endpoints when creating the service client as shown in: 437 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 438 c, err := aiplatform.NewSessionClient(ctx) 439 if err != nil { 440 // TODO: Handle error. 441 } 442 defer c.Close() 443 444 req := &longrunningpb.DeleteOperationRequest{ 445 // TODO: Fill request struct fields. 446 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 447 } 448 err = c.DeleteOperation(ctx, req) 449 if err != nil { 450 // TODO: Handle error. 451 } 452 } 453 454 func ExampleSessionClient_GetOperation() { 455 ctx := context.Background() 456 // This snippet has been automatically generated and should be regarded as a code template only. 457 // It will require modifications to work: 458 // - It may require correct/in-range values for request initialization. 459 // - It may require specifying regional endpoints when creating the service client as shown in: 460 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 461 c, err := aiplatform.NewSessionClient(ctx) 462 if err != nil { 463 // TODO: Handle error. 464 } 465 defer c.Close() 466 467 req := &longrunningpb.GetOperationRequest{ 468 // TODO: Fill request struct fields. 469 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 470 } 471 resp, err := c.GetOperation(ctx, req) 472 if err != nil { 473 // TODO: Handle error. 474 } 475 // TODO: Use resp. 476 _ = resp 477 } 478 479 func ExampleSessionClient_ListOperations() { 480 ctx := context.Background() 481 // This snippet has been automatically generated and should be regarded as a code template only. 482 // It will require modifications to work: 483 // - It may require correct/in-range values for request initialization. 484 // - It may require specifying regional endpoints when creating the service client as shown in: 485 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 486 c, err := aiplatform.NewSessionClient(ctx) 487 if err != nil { 488 // TODO: Handle error. 489 } 490 defer c.Close() 491 492 req := &longrunningpb.ListOperationsRequest{ 493 // TODO: Fill request struct fields. 494 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 495 } 496 it := c.ListOperations(ctx, req) 497 for { 498 resp, err := it.Next() 499 if err == iterator.Done { 500 break 501 } 502 if err != nil { 503 // TODO: Handle error. 504 } 505 // TODO: Use resp. 506 _ = resp 507 508 // If you need to access the underlying RPC response, 509 // you can do so by casting the `Response` as below. 510 // Otherwise, remove this line. Only populated after 511 // first call to Next(). Not safe for concurrent access. 512 _ = it.Response.(*longrunningpb.ListOperationsResponse) 513 } 514 } 515 516 func ExampleSessionClient_WaitOperation() { 517 ctx := context.Background() 518 // This snippet has been automatically generated and should be regarded as a code template only. 519 // It will require modifications to work: 520 // - It may require correct/in-range values for request initialization. 521 // - It may require specifying regional endpoints when creating the service client as shown in: 522 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 523 c, err := aiplatform.NewSessionClient(ctx) 524 if err != nil { 525 // TODO: Handle error. 526 } 527 defer c.Close() 528 529 req := &longrunningpb.WaitOperationRequest{ 530 // TODO: Fill request struct fields. 531 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 532 } 533 resp, err := c.WaitOperation(ctx, req) 534 if err != nil { 535 // TODO: Handle error. 536 } 537 // TODO: Use resp. 538 _ = resp 539 }