cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/gen_ai_cache_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 ExampleNewGenAiCacheClient() { 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.NewGenAiCacheClient(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 ExampleNewGenAiCacheRESTClient() { 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.NewGenAiCacheRESTClient(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 ExampleGenAiCacheClient_CreateCachedContent() { 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.NewGenAiCacheClient(ctx) 72 if err != nil { 73 // TODO: Handle error. 74 } 75 defer c.Close() 76 77 req := &aiplatformpb.CreateCachedContentRequest{ 78 // TODO: Fill request struct fields. 79 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#CreateCachedContentRequest. 80 } 81 resp, err := c.CreateCachedContent(ctx, req) 82 if err != nil { 83 // TODO: Handle error. 84 } 85 // TODO: Use resp. 86 _ = resp 87 } 88 89 func ExampleGenAiCacheClient_DeleteCachedContent() { 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.NewGenAiCacheClient(ctx) 97 if err != nil { 98 // TODO: Handle error. 99 } 100 defer c.Close() 101 102 req := &aiplatformpb.DeleteCachedContentRequest{ 103 // TODO: Fill request struct fields. 104 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#DeleteCachedContentRequest. 105 } 106 err = c.DeleteCachedContent(ctx, req) 107 if err != nil { 108 // TODO: Handle error. 109 } 110 } 111 112 func ExampleGenAiCacheClient_GetCachedContent() { 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.NewGenAiCacheClient(ctx) 120 if err != nil { 121 // TODO: Handle error. 122 } 123 defer c.Close() 124 125 req := &aiplatformpb.GetCachedContentRequest{ 126 // TODO: Fill request struct fields. 127 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#GetCachedContentRequest. 128 } 129 resp, err := c.GetCachedContent(ctx, req) 130 if err != nil { 131 // TODO: Handle error. 132 } 133 // TODO: Use resp. 134 _ = resp 135 } 136 137 func ExampleGenAiCacheClient_ListCachedContents() { 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.NewGenAiCacheClient(ctx) 145 if err != nil { 146 // TODO: Handle error. 147 } 148 defer c.Close() 149 150 req := &aiplatformpb.ListCachedContentsRequest{ 151 // TODO: Fill request struct fields. 152 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#ListCachedContentsRequest. 153 } 154 it := c.ListCachedContents(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.ListCachedContentsResponse) 171 } 172 } 173 174 func ExampleGenAiCacheClient_UpdateCachedContent() { 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.NewGenAiCacheClient(ctx) 182 if err != nil { 183 // TODO: Handle error. 184 } 185 defer c.Close() 186 187 req := &aiplatformpb.UpdateCachedContentRequest{ 188 // TODO: Fill request struct fields. 189 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#UpdateCachedContentRequest. 190 } 191 resp, err := c.UpdateCachedContent(ctx, req) 192 if err != nil { 193 // TODO: Handle error. 194 } 195 // TODO: Use resp. 196 _ = resp 197 } 198 199 func ExampleGenAiCacheClient_GetLocation() { 200 ctx := context.Background() 201 // This snippet has been automatically generated and should be regarded as a code template only. 202 // It will require modifications to work: 203 // - It may require correct/in-range values for request initialization. 204 // - It may require specifying regional endpoints when creating the service client as shown in: 205 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 206 c, err := aiplatform.NewGenAiCacheClient(ctx) 207 if err != nil { 208 // TODO: Handle error. 209 } 210 defer c.Close() 211 212 req := &locationpb.GetLocationRequest{ 213 // TODO: Fill request struct fields. 214 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 215 } 216 resp, err := c.GetLocation(ctx, req) 217 if err != nil { 218 // TODO: Handle error. 219 } 220 // TODO: Use resp. 221 _ = resp 222 } 223 224 func ExampleGenAiCacheClient_ListLocations() { 225 ctx := context.Background() 226 // This snippet has been automatically generated and should be regarded as a code template only. 227 // It will require modifications to work: 228 // - It may require correct/in-range values for request initialization. 229 // - It may require specifying regional endpoints when creating the service client as shown in: 230 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 231 c, err := aiplatform.NewGenAiCacheClient(ctx) 232 if err != nil { 233 // TODO: Handle error. 234 } 235 defer c.Close() 236 237 req := &locationpb.ListLocationsRequest{ 238 // TODO: Fill request struct fields. 239 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 240 } 241 it := c.ListLocations(ctx, req) 242 for { 243 resp, err := it.Next() 244 if err == iterator.Done { 245 break 246 } 247 if err != nil { 248 // TODO: Handle error. 249 } 250 // TODO: Use resp. 251 _ = resp 252 253 // If you need to access the underlying RPC response, 254 // you can do so by casting the `Response` as below. 255 // Otherwise, remove this line. Only populated after 256 // first call to Next(). Not safe for concurrent access. 257 _ = it.Response.(*locationpb.ListLocationsResponse) 258 } 259 } 260 261 func ExampleGenAiCacheClient_GetIamPolicy() { 262 ctx := context.Background() 263 // This snippet has been automatically generated and should be regarded as a code template only. 264 // It will require modifications to work: 265 // - It may require correct/in-range values for request initialization. 266 // - It may require specifying regional endpoints when creating the service client as shown in: 267 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 268 c, err := aiplatform.NewGenAiCacheClient(ctx) 269 if err != nil { 270 // TODO: Handle error. 271 } 272 defer c.Close() 273 274 req := &iampb.GetIamPolicyRequest{ 275 // TODO: Fill request struct fields. 276 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 277 } 278 resp, err := c.GetIamPolicy(ctx, req) 279 if err != nil { 280 // TODO: Handle error. 281 } 282 // TODO: Use resp. 283 _ = resp 284 } 285 286 func ExampleGenAiCacheClient_SetIamPolicy() { 287 ctx := context.Background() 288 // This snippet has been automatically generated and should be regarded as a code template only. 289 // It will require modifications to work: 290 // - It may require correct/in-range values for request initialization. 291 // - It may require specifying regional endpoints when creating the service client as shown in: 292 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 293 c, err := aiplatform.NewGenAiCacheClient(ctx) 294 if err != nil { 295 // TODO: Handle error. 296 } 297 defer c.Close() 298 299 req := &iampb.SetIamPolicyRequest{ 300 // TODO: Fill request struct fields. 301 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 302 } 303 resp, err := c.SetIamPolicy(ctx, req) 304 if err != nil { 305 // TODO: Handle error. 306 } 307 // TODO: Use resp. 308 _ = resp 309 } 310 311 func ExampleGenAiCacheClient_TestIamPermissions() { 312 ctx := context.Background() 313 // This snippet has been automatically generated and should be regarded as a code template only. 314 // It will require modifications to work: 315 // - It may require correct/in-range values for request initialization. 316 // - It may require specifying regional endpoints when creating the service client as shown in: 317 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 318 c, err := aiplatform.NewGenAiCacheClient(ctx) 319 if err != nil { 320 // TODO: Handle error. 321 } 322 defer c.Close() 323 324 req := &iampb.TestIamPermissionsRequest{ 325 // TODO: Fill request struct fields. 326 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 327 } 328 resp, err := c.TestIamPermissions(ctx, req) 329 if err != nil { 330 // TODO: Handle error. 331 } 332 // TODO: Use resp. 333 _ = resp 334 } 335 336 func ExampleGenAiCacheClient_CancelOperation() { 337 ctx := context.Background() 338 // This snippet has been automatically generated and should be regarded as a code template only. 339 // It will require modifications to work: 340 // - It may require correct/in-range values for request initialization. 341 // - It may require specifying regional endpoints when creating the service client as shown in: 342 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 343 c, err := aiplatform.NewGenAiCacheClient(ctx) 344 if err != nil { 345 // TODO: Handle error. 346 } 347 defer c.Close() 348 349 req := &longrunningpb.CancelOperationRequest{ 350 // TODO: Fill request struct fields. 351 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 352 } 353 err = c.CancelOperation(ctx, req) 354 if err != nil { 355 // TODO: Handle error. 356 } 357 } 358 359 func ExampleGenAiCacheClient_DeleteOperation() { 360 ctx := context.Background() 361 // This snippet has been automatically generated and should be regarded as a code template only. 362 // It will require modifications to work: 363 // - It may require correct/in-range values for request initialization. 364 // - It may require specifying regional endpoints when creating the service client as shown in: 365 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 366 c, err := aiplatform.NewGenAiCacheClient(ctx) 367 if err != nil { 368 // TODO: Handle error. 369 } 370 defer c.Close() 371 372 req := &longrunningpb.DeleteOperationRequest{ 373 // TODO: Fill request struct fields. 374 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 375 } 376 err = c.DeleteOperation(ctx, req) 377 if err != nil { 378 // TODO: Handle error. 379 } 380 } 381 382 func ExampleGenAiCacheClient_GetOperation() { 383 ctx := context.Background() 384 // This snippet has been automatically generated and should be regarded as a code template only. 385 // It will require modifications to work: 386 // - It may require correct/in-range values for request initialization. 387 // - It may require specifying regional endpoints when creating the service client as shown in: 388 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 389 c, err := aiplatform.NewGenAiCacheClient(ctx) 390 if err != nil { 391 // TODO: Handle error. 392 } 393 defer c.Close() 394 395 req := &longrunningpb.GetOperationRequest{ 396 // TODO: Fill request struct fields. 397 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 398 } 399 resp, err := c.GetOperation(ctx, req) 400 if err != nil { 401 // TODO: Handle error. 402 } 403 // TODO: Use resp. 404 _ = resp 405 } 406 407 func ExampleGenAiCacheClient_ListOperations() { 408 ctx := context.Background() 409 // This snippet has been automatically generated and should be regarded as a code template only. 410 // It will require modifications to work: 411 // - It may require correct/in-range values for request initialization. 412 // - It may require specifying regional endpoints when creating the service client as shown in: 413 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 414 c, err := aiplatform.NewGenAiCacheClient(ctx) 415 if err != nil { 416 // TODO: Handle error. 417 } 418 defer c.Close() 419 420 req := &longrunningpb.ListOperationsRequest{ 421 // TODO: Fill request struct fields. 422 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 423 } 424 it := c.ListOperations(ctx, req) 425 for { 426 resp, err := it.Next() 427 if err == iterator.Done { 428 break 429 } 430 if err != nil { 431 // TODO: Handle error. 432 } 433 // TODO: Use resp. 434 _ = resp 435 436 // If you need to access the underlying RPC response, 437 // you can do so by casting the `Response` as below. 438 // Otherwise, remove this line. Only populated after 439 // first call to Next(). Not safe for concurrent access. 440 _ = it.Response.(*longrunningpb.ListOperationsResponse) 441 } 442 } 443 444 func ExampleGenAiCacheClient_WaitOperation() { 445 ctx := context.Background() 446 // This snippet has been automatically generated and should be regarded as a code template only. 447 // It will require modifications to work: 448 // - It may require correct/in-range values for request initialization. 449 // - It may require specifying regional endpoints when creating the service client as shown in: 450 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 451 c, err := aiplatform.NewGenAiCacheClient(ctx) 452 if err != nil { 453 // TODO: Handle error. 454 } 455 defer c.Close() 456 457 req := &longrunningpb.WaitOperationRequest{ 458 // TODO: Fill request struct fields. 459 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 460 } 461 resp, err := c.WaitOperation(ctx, req) 462 if err != nil { 463 // TODO: Handle error. 464 } 465 // TODO: Use resp. 466 _ = resp 467 }