cloud.google.com/go/aiplatform@v1.106.0/apiv1/vertex_rag_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 ExampleNewVertexRagClient() { 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.NewVertexRagClient(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 ExampleVertexRagClient_AugmentPrompt() { 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.NewVertexRagClient(ctx) 55 if err != nil { 56 // TODO: Handle error. 57 } 58 defer c.Close() 59 60 req := &aiplatformpb.AugmentPromptRequest{ 61 // TODO: Fill request struct fields. 62 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#AugmentPromptRequest. 63 } 64 resp, err := c.AugmentPrompt(ctx, req) 65 if err != nil { 66 // TODO: Handle error. 67 } 68 // TODO: Use resp. 69 _ = resp 70 } 71 72 func ExampleVertexRagClient_CorroborateContent() { 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.NewVertexRagClient(ctx) 80 if err != nil { 81 // TODO: Handle error. 82 } 83 defer c.Close() 84 85 req := &aiplatformpb.CorroborateContentRequest{ 86 // TODO: Fill request struct fields. 87 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#CorroborateContentRequest. 88 } 89 resp, err := c.CorroborateContent(ctx, req) 90 if err != nil { 91 // TODO: Handle error. 92 } 93 // TODO: Use resp. 94 _ = resp 95 } 96 97 func ExampleVertexRagClient_RetrieveContexts() { 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.NewVertexRagClient(ctx) 105 if err != nil { 106 // TODO: Handle error. 107 } 108 defer c.Close() 109 110 req := &aiplatformpb.RetrieveContextsRequest{ 111 // TODO: Fill request struct fields. 112 // See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#RetrieveContextsRequest. 113 } 114 resp, err := c.RetrieveContexts(ctx, req) 115 if err != nil { 116 // TODO: Handle error. 117 } 118 // TODO: Use resp. 119 _ = resp 120 } 121 122 func ExampleVertexRagClient_GetLocation() { 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.NewVertexRagClient(ctx) 130 if err != nil { 131 // TODO: Handle error. 132 } 133 defer c.Close() 134 135 req := &locationpb.GetLocationRequest{ 136 // TODO: Fill request struct fields. 137 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 138 } 139 resp, err := c.GetLocation(ctx, req) 140 if err != nil { 141 // TODO: Handle error. 142 } 143 // TODO: Use resp. 144 _ = resp 145 } 146 147 func ExampleVertexRagClient_ListLocations() { 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.NewVertexRagClient(ctx) 155 if err != nil { 156 // TODO: Handle error. 157 } 158 defer c.Close() 159 160 req := &locationpb.ListLocationsRequest{ 161 // TODO: Fill request struct fields. 162 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 163 } 164 it := c.ListLocations(ctx, req) 165 for { 166 resp, err := it.Next() 167 if err == iterator.Done { 168 break 169 } 170 if err != nil { 171 // TODO: Handle error. 172 } 173 // TODO: Use resp. 174 _ = resp 175 176 // If you need to access the underlying RPC response, 177 // you can do so by casting the `Response` as below. 178 // Otherwise, remove this line. Only populated after 179 // first call to Next(). Not safe for concurrent access. 180 _ = it.Response.(*locationpb.ListLocationsResponse) 181 } 182 } 183 184 func ExampleVertexRagClient_GetIamPolicy() { 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.NewVertexRagClient(ctx) 192 if err != nil { 193 // TODO: Handle error. 194 } 195 defer c.Close() 196 197 req := &iampb.GetIamPolicyRequest{ 198 // TODO: Fill request struct fields. 199 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 200 } 201 resp, err := c.GetIamPolicy(ctx, req) 202 if err != nil { 203 // TODO: Handle error. 204 } 205 // TODO: Use resp. 206 _ = resp 207 } 208 209 func ExampleVertexRagClient_SetIamPolicy() { 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.NewVertexRagClient(ctx) 217 if err != nil { 218 // TODO: Handle error. 219 } 220 defer c.Close() 221 222 req := &iampb.SetIamPolicyRequest{ 223 // TODO: Fill request struct fields. 224 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 225 } 226 resp, err := c.SetIamPolicy(ctx, req) 227 if err != nil { 228 // TODO: Handle error. 229 } 230 // TODO: Use resp. 231 _ = resp 232 } 233 234 func ExampleVertexRagClient_TestIamPermissions() { 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.NewVertexRagClient(ctx) 242 if err != nil { 243 // TODO: Handle error. 244 } 245 defer c.Close() 246 247 req := &iampb.TestIamPermissionsRequest{ 248 // TODO: Fill request struct fields. 249 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 250 } 251 resp, err := c.TestIamPermissions(ctx, req) 252 if err != nil { 253 // TODO: Handle error. 254 } 255 // TODO: Use resp. 256 _ = resp 257 } 258 259 func ExampleVertexRagClient_CancelOperation() { 260 ctx := context.Background() 261 // This snippet has been automatically generated and should be regarded as a code template only. 262 // It will require modifications to work: 263 // - It may require correct/in-range values for request initialization. 264 // - It may require specifying regional endpoints when creating the service client as shown in: 265 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 266 c, err := aiplatform.NewVertexRagClient(ctx) 267 if err != nil { 268 // TODO: Handle error. 269 } 270 defer c.Close() 271 272 req := &longrunningpb.CancelOperationRequest{ 273 // TODO: Fill request struct fields. 274 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest. 275 } 276 err = c.CancelOperation(ctx, req) 277 if err != nil { 278 // TODO: Handle error. 279 } 280 } 281 282 func ExampleVertexRagClient_DeleteOperation() { 283 ctx := context.Background() 284 // This snippet has been automatically generated and should be regarded as a code template only. 285 // It will require modifications to work: 286 // - It may require correct/in-range values for request initialization. 287 // - It may require specifying regional endpoints when creating the service client as shown in: 288 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 289 c, err := aiplatform.NewVertexRagClient(ctx) 290 if err != nil { 291 // TODO: Handle error. 292 } 293 defer c.Close() 294 295 req := &longrunningpb.DeleteOperationRequest{ 296 // TODO: Fill request struct fields. 297 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest. 298 } 299 err = c.DeleteOperation(ctx, req) 300 if err != nil { 301 // TODO: Handle error. 302 } 303 } 304 305 func ExampleVertexRagClient_GetOperation() { 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.NewVertexRagClient(ctx) 313 if err != nil { 314 // TODO: Handle error. 315 } 316 defer c.Close() 317 318 req := &longrunningpb.GetOperationRequest{ 319 // TODO: Fill request struct fields. 320 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest. 321 } 322 resp, err := c.GetOperation(ctx, req) 323 if err != nil { 324 // TODO: Handle error. 325 } 326 // TODO: Use resp. 327 _ = resp 328 } 329 330 func ExampleVertexRagClient_ListOperations() { 331 ctx := context.Background() 332 // This snippet has been automatically generated and should be regarded as a code template only. 333 // It will require modifications to work: 334 // - It may require correct/in-range values for request initialization. 335 // - It may require specifying regional endpoints when creating the service client as shown in: 336 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 337 c, err := aiplatform.NewVertexRagClient(ctx) 338 if err != nil { 339 // TODO: Handle error. 340 } 341 defer c.Close() 342 343 req := &longrunningpb.ListOperationsRequest{ 344 // TODO: Fill request struct fields. 345 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest. 346 } 347 it := c.ListOperations(ctx, req) 348 for { 349 resp, err := it.Next() 350 if err == iterator.Done { 351 break 352 } 353 if err != nil { 354 // TODO: Handle error. 355 } 356 // TODO: Use resp. 357 _ = resp 358 359 // If you need to access the underlying RPC response, 360 // you can do so by casting the `Response` as below. 361 // Otherwise, remove this line. Only populated after 362 // first call to Next(). Not safe for concurrent access. 363 _ = it.Response.(*longrunningpb.ListOperationsResponse) 364 } 365 } 366 367 func ExampleVertexRagClient_WaitOperation() { 368 ctx := context.Background() 369 // This snippet has been automatically generated and should be regarded as a code template only. 370 // It will require modifications to work: 371 // - It may require correct/in-range values for request initialization. 372 // - It may require specifying regional endpoints when creating the service client as shown in: 373 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 374 c, err := aiplatform.NewVertexRagClient(ctx) 375 if err != nil { 376 // TODO: Handle error. 377 } 378 defer c.Close() 379 380 req := &longrunningpb.WaitOperationRequest{ 381 // TODO: Fill request struct fields. 382 // See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest. 383 } 384 resp, err := c.WaitOperation(ctx, req) 385 if err != nil { 386 // TODO: Handle error. 387 } 388 // TODO: Use resp. 389 _ = resp 390 }