cloud.google.com/go/aiplatform@v1.106.0/apiv1/llm_utility_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/apiv1" 23 aiplatformpb "cloud.google.com/go/aiplatform/apiv1/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 ExampleNewLlmUtilityClient() { 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.NewLlmUtilityClient(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 ExampleLlmUtilityClient_ComputeTokens() { 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.NewLlmUtilityClient(ctx) 55 if err != nil { 56 // TODO: Handle error. 57 } 58 defer c.Close() 59 60 req := &aiplatformpb.ComputeTokensRequest{ 61 // TODO: Fill request struct fields. 62 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#ComputeTokensRequest. 63 } 64 resp, err := c.ComputeTokens(ctx, req) 65 if err != nil { 66 // TODO: Handle error. 67 } 68 // TODO: Use resp. 69 _ = resp 70 } 71 72 func ExampleLlmUtilityClient_CountTokens() { 73 ctx := context.Background() 74 // This snippet has been automatically generated and should be regarded as a code template only. 75 // It will require modifications to work: 76 // - It may require correct/in-range values for request initialization. 77 // - It may require specifying regional endpoints when creating the service client as shown in: 78 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 79 c, err := aiplatform.NewLlmUtilityClient(ctx) 80 if err != nil { 81 // TODO: Handle error. 82 } 83 defer c.Close() 84 85 req := &aiplatformpb.CountTokensRequest{ 86 // TODO: Fill request struct fields. 87 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#CountTokensRequest. 88 } 89 resp, err := c.CountTokens(ctx, req) 90 if err != nil { 91 // TODO: Handle error. 92 } 93 // TODO: Use resp. 94 _ = resp 95 } 96 97 func ExampleLlmUtilityClient_GetLocation() { 98 ctx := context.Background() 99 // This snippet has been automatically generated and should be regarded as a code template only. 100 // It will require modifications to work: 101 // - It may require correct/in-range values for request initialization. 102 // - It may require specifying regional endpoints when creating the service client as shown in: 103 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 104 c, err := aiplatform.NewLlmUtilityClient(ctx) 105 if err != nil { 106 // TODO: Handle error. 107 } 108 defer c.Close() 109 110 req := &locationpb.GetLocationRequest{ 111 // TODO: Fill request struct fields. 112 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 113 } 114 resp, err := c.GetLocation(ctx, req) 115 if err != nil { 116 // TODO: Handle error. 117 } 118 // TODO: Use resp. 119 _ = resp 120 } 121 122 func ExampleLlmUtilityClient_ListLocations() { 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.NewLlmUtilityClient(ctx) 130 if err != nil { 131 // TODO: Handle error. 132 } 133 defer c.Close() 134 135 req := &locationpb.ListLocationsRequest{ 136 // TODO: Fill request struct fields. 137 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 138 } 139 it := c.ListLocations(ctx, req) 140 for { 141 resp, err := it.Next() 142 if err == iterator.Done { 143 break 144 } 145 if err != nil { 146 // TODO: Handle error. 147 } 148 // TODO: Use resp. 149 _ = resp 150 151 // If you need to access the underlying RPC response, 152 // you can do so by casting the `Response` as below. 153 // Otherwise, remove this line. Only populated after 154 // first call to Next(). Not safe for concurrent access. 155 _ = it.Response.(*locationpb.ListLocationsResponse) 156 } 157 } 158 159 func ExampleLlmUtilityClient_GetIamPolicy() { 160 ctx := context.Background() 161 // This snippet has been automatically generated and should be regarded as a code template only. 162 // It will require modifications to work: 163 // - It may require correct/in-range values for request initialization. 164 // - It may require specifying regional endpoints when creating the service client as shown in: 165 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 166 c, err := aiplatform.NewLlmUtilityClient(ctx) 167 if err != nil { 168 // TODO: Handle error. 169 } 170 defer c.Close() 171 172 req := &iampb.GetIamPolicyRequest{ 173 // TODO: Fill request struct fields. 174 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 175 } 176 resp, err := c.GetIamPolicy(ctx, req) 177 if err != nil { 178 // TODO: Handle error. 179 } 180 // TODO: Use resp. 181 _ = resp 182 } 183 184 func ExampleLlmUtilityClient_SetIamPolicy() { 185 ctx := context.Background() 186 // This snippet has been automatically generated and should be regarded as a code template only. 187 // It will require modifications to work: 188 // - It may require correct/in-range values for request initialization. 189 // - It may require specifying regional endpoints when creating the service client as shown in: 190 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 191 c, err := aiplatform.NewLlmUtilityClient(ctx) 192 if err != nil { 193 // TODO: Handle error. 194 } 195 defer c.Close() 196 197 req := &iampb.SetIamPolicyRequest{ 198 // TODO: Fill request struct fields. 199 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 200 } 201 resp, err := c.SetIamPolicy(ctx, req) 202 if err != nil { 203 // TODO: Handle error. 204 } 205 // TODO: Use resp. 206 _ = resp 207 } 208 209 func ExampleLlmUtilityClient_TestIamPermissions() { 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.NewLlmUtilityClient(ctx) 217 if err != nil { 218 // TODO: Handle error. 219 } 220 defer c.Close() 221 222 req := &iampb.TestIamPermissionsRequest{ 223 // TODO: Fill request struct fields. 224 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 225 } 226 resp, err := c.TestIamPermissions(ctx, req) 227 if err != nil { 228 // TODO: Handle error. 229 } 230 // TODO: Use resp. 231 _ = resp 232 } 233 234 func ExampleLlmUtilityClient_CancelOperation() { 235 ctx := context.Background() 236 // This snippet has been automatically generated and should be regarded as a code template only. 237 // It will require modifications to work: 238 // - It may require correct/in-range values for request initialization. 239 // - It may require specifying regional endpoints when creating the service client as shown in: 240 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 241 c, err := aiplatform.NewLlmUtilityClient(ctx) 242 if err != nil { 243 // TODO: Handle error. 244 } 245 defer c.Close() 246 247 req := &longrunningpb.CancelOperationRequest{ 248 // TODO: Fill request struct fields. 249 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 250 } 251 err = c.CancelOperation(ctx, req) 252 if err != nil { 253 // TODO: Handle error. 254 } 255 } 256 257 func ExampleLlmUtilityClient_DeleteOperation() { 258 ctx := context.Background() 259 // This snippet has been automatically generated and should be regarded as a code template only. 260 // It will require modifications to work: 261 // - It may require correct/in-range values for request initialization. 262 // - It may require specifying regional endpoints when creating the service client as shown in: 263 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 264 c, err := aiplatform.NewLlmUtilityClient(ctx) 265 if err != nil { 266 // TODO: Handle error. 267 } 268 defer c.Close() 269 270 req := &longrunningpb.DeleteOperationRequest{ 271 // TODO: Fill request struct fields. 272 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 273 } 274 err = c.DeleteOperation(ctx, req) 275 if err != nil { 276 // TODO: Handle error. 277 } 278 } 279 280 func ExampleLlmUtilityClient_GetOperation() { 281 ctx := context.Background() 282 // This snippet has been automatically generated and should be regarded as a code template only. 283 // It will require modifications to work: 284 // - It may require correct/in-range values for request initialization. 285 // - It may require specifying regional endpoints when creating the service client as shown in: 286 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 287 c, err := aiplatform.NewLlmUtilityClient(ctx) 288 if err != nil { 289 // TODO: Handle error. 290 } 291 defer c.Close() 292 293 req := &longrunningpb.GetOperationRequest{ 294 // TODO: Fill request struct fields. 295 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 296 } 297 resp, err := c.GetOperation(ctx, req) 298 if err != nil { 299 // TODO: Handle error. 300 } 301 // TODO: Use resp. 302 _ = resp 303 } 304 305 func ExampleLlmUtilityClient_ListOperations() { 306 ctx := context.Background() 307 // This snippet has been automatically generated and should be regarded as a code template only. 308 // It will require modifications to work: 309 // - It may require correct/in-range values for request initialization. 310 // - It may require specifying regional endpoints when creating the service client as shown in: 311 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 312 c, err := aiplatform.NewLlmUtilityClient(ctx) 313 if err != nil { 314 // TODO: Handle error. 315 } 316 defer c.Close() 317 318 req := &longrunningpb.ListOperationsRequest{ 319 // TODO: Fill request struct fields. 320 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 321 } 322 it := c.ListOperations(ctx, req) 323 for { 324 resp, err := it.Next() 325 if err == iterator.Done { 326 break 327 } 328 if err != nil { 329 // TODO: Handle error. 330 } 331 // TODO: Use resp. 332 _ = resp 333 334 // If you need to access the underlying RPC response, 335 // you can do so by casting the `Response` as below. 336 // Otherwise, remove this line. Only populated after 337 // first call to Next(). Not safe for concurrent access. 338 _ = it.Response.(*longrunningpb.ListOperationsResponse) 339 } 340 } 341 342 func ExampleLlmUtilityClient_WaitOperation() { 343 ctx := context.Background() 344 // This snippet has been automatically generated and should be regarded as a code template only. 345 // It will require modifications to work: 346 // - It may require correct/in-range values for request initialization. 347 // - It may require specifying regional endpoints when creating the service client as shown in: 348 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 349 c, err := aiplatform.NewLlmUtilityClient(ctx) 350 if err != nil { 351 // TODO: Handle error. 352 } 353 defer c.Close() 354 355 req := &longrunningpb.WaitOperationRequest{ 356 // TODO: Fill request struct fields. 357 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 358 } 359 resp, err := c.WaitOperation(ctx, req) 360 if err != nil { 361 // TODO: Handle error. 362 } 363 // TODO: Use resp. 364 _ = resp 365 }