cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/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/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 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 ExampleNewVertexRagRESTClient() {
    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.NewVertexRagRESTClient(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 ExampleVertexRagClient_AugmentPrompt() {
    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.NewVertexRagClient(ctx)
    72  	if err != nil {
    73  		// TODO: Handle error.
    74  	}
    75  	defer c.Close()
    76  
    77  	req := &aiplatformpb.AugmentPromptRequest{
    78  		// TODO: Fill request struct fields.
    79  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#AugmentPromptRequest.
    80  	}
    81  	resp, err := c.AugmentPrompt(ctx, req)
    82  	if err != nil {
    83  		// TODO: Handle error.
    84  	}
    85  	// TODO: Use resp.
    86  	_ = resp
    87  }
    88  
    89  func ExampleVertexRagClient_CorroborateContent() {
    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.NewVertexRagClient(ctx)
    97  	if err != nil {
    98  		// TODO: Handle error.
    99  	}
   100  	defer c.Close()
   101  
   102  	req := &aiplatformpb.CorroborateContentRequest{
   103  		// TODO: Fill request struct fields.
   104  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#CorroborateContentRequest.
   105  	}
   106  	resp, err := c.CorroborateContent(ctx, req)
   107  	if err != nil {
   108  		// TODO: Handle error.
   109  	}
   110  	// TODO: Use resp.
   111  	_ = resp
   112  }
   113  
   114  func ExampleVertexRagClient_RetrieveContexts() {
   115  	ctx := context.Background()
   116  	// This snippet has been automatically generated and should be regarded as a code template only.
   117  	// It will require modifications to work:
   118  	// - It may require correct/in-range values for request initialization.
   119  	// - It may require specifying regional endpoints when creating the service client as shown in:
   120  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   121  	c, err := aiplatform.NewVertexRagClient(ctx)
   122  	if err != nil {
   123  		// TODO: Handle error.
   124  	}
   125  	defer c.Close()
   126  
   127  	req := &aiplatformpb.RetrieveContextsRequest{
   128  		// TODO: Fill request struct fields.
   129  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb#RetrieveContextsRequest.
   130  	}
   131  	resp, err := c.RetrieveContexts(ctx, req)
   132  	if err != nil {
   133  		// TODO: Handle error.
   134  	}
   135  	// TODO: Use resp.
   136  	_ = resp
   137  }
   138  
   139  func ExampleVertexRagClient_GetLocation() {
   140  	ctx := context.Background()
   141  	// This snippet has been automatically generated and should be regarded as a code template only.
   142  	// It will require modifications to work:
   143  	// - It may require correct/in-range values for request initialization.
   144  	// - It may require specifying regional endpoints when creating the service client as shown in:
   145  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   146  	c, err := aiplatform.NewVertexRagClient(ctx)
   147  	if err != nil {
   148  		// TODO: Handle error.
   149  	}
   150  	defer c.Close()
   151  
   152  	req := &locationpb.GetLocationRequest{
   153  		// TODO: Fill request struct fields.
   154  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
   155  	}
   156  	resp, err := c.GetLocation(ctx, req)
   157  	if err != nil {
   158  		// TODO: Handle error.
   159  	}
   160  	// TODO: Use resp.
   161  	_ = resp
   162  }
   163  
   164  func ExampleVertexRagClient_ListLocations() {
   165  	ctx := context.Background()
   166  	// This snippet has been automatically generated and should be regarded as a code template only.
   167  	// It will require modifications to work:
   168  	// - It may require correct/in-range values for request initialization.
   169  	// - It may require specifying regional endpoints when creating the service client as shown in:
   170  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   171  	c, err := aiplatform.NewVertexRagClient(ctx)
   172  	if err != nil {
   173  		// TODO: Handle error.
   174  	}
   175  	defer c.Close()
   176  
   177  	req := &locationpb.ListLocationsRequest{
   178  		// TODO: Fill request struct fields.
   179  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
   180  	}
   181  	it := c.ListLocations(ctx, req)
   182  	for {
   183  		resp, err := it.Next()
   184  		if err == iterator.Done {
   185  			break
   186  		}
   187  		if err != nil {
   188  			// TODO: Handle error.
   189  		}
   190  		// TODO: Use resp.
   191  		_ = resp
   192  
   193  		// If you need to access the underlying RPC response,
   194  		// you can do so by casting the `Response` as below.
   195  		// Otherwise, remove this line. Only populated after
   196  		// first call to Next(). Not safe for concurrent access.
   197  		_ = it.Response.(*locationpb.ListLocationsResponse)
   198  	}
   199  }
   200  
   201  func ExampleVertexRagClient_GetIamPolicy() {
   202  	ctx := context.Background()
   203  	// This snippet has been automatically generated and should be regarded as a code template only.
   204  	// It will require modifications to work:
   205  	// - It may require correct/in-range values for request initialization.
   206  	// - It may require specifying regional endpoints when creating the service client as shown in:
   207  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   208  	c, err := aiplatform.NewVertexRagClient(ctx)
   209  	if err != nil {
   210  		// TODO: Handle error.
   211  	}
   212  	defer c.Close()
   213  
   214  	req := &iampb.GetIamPolicyRequest{
   215  		// TODO: Fill request struct fields.
   216  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
   217  	}
   218  	resp, err := c.GetIamPolicy(ctx, req)
   219  	if err != nil {
   220  		// TODO: Handle error.
   221  	}
   222  	// TODO: Use resp.
   223  	_ = resp
   224  }
   225  
   226  func ExampleVertexRagClient_SetIamPolicy() {
   227  	ctx := context.Background()
   228  	// This snippet has been automatically generated and should be regarded as a code template only.
   229  	// It will require modifications to work:
   230  	// - It may require correct/in-range values for request initialization.
   231  	// - It may require specifying regional endpoints when creating the service client as shown in:
   232  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   233  	c, err := aiplatform.NewVertexRagClient(ctx)
   234  	if err != nil {
   235  		// TODO: Handle error.
   236  	}
   237  	defer c.Close()
   238  
   239  	req := &iampb.SetIamPolicyRequest{
   240  		// TODO: Fill request struct fields.
   241  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
   242  	}
   243  	resp, err := c.SetIamPolicy(ctx, req)
   244  	if err != nil {
   245  		// TODO: Handle error.
   246  	}
   247  	// TODO: Use resp.
   248  	_ = resp
   249  }
   250  
   251  func ExampleVertexRagClient_TestIamPermissions() {
   252  	ctx := context.Background()
   253  	// This snippet has been automatically generated and should be regarded as a code template only.
   254  	// It will require modifications to work:
   255  	// - It may require correct/in-range values for request initialization.
   256  	// - It may require specifying regional endpoints when creating the service client as shown in:
   257  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   258  	c, err := aiplatform.NewVertexRagClient(ctx)
   259  	if err != nil {
   260  		// TODO: Handle error.
   261  	}
   262  	defer c.Close()
   263  
   264  	req := &iampb.TestIamPermissionsRequest{
   265  		// TODO: Fill request struct fields.
   266  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
   267  	}
   268  	resp, err := c.TestIamPermissions(ctx, req)
   269  	if err != nil {
   270  		// TODO: Handle error.
   271  	}
   272  	// TODO: Use resp.
   273  	_ = resp
   274  }
   275  
   276  func ExampleVertexRagClient_CancelOperation() {
   277  	ctx := context.Background()
   278  	// This snippet has been automatically generated and should be regarded as a code template only.
   279  	// It will require modifications to work:
   280  	// - It may require correct/in-range values for request initialization.
   281  	// - It may require specifying regional endpoints when creating the service client as shown in:
   282  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   283  	c, err := aiplatform.NewVertexRagClient(ctx)
   284  	if err != nil {
   285  		// TODO: Handle error.
   286  	}
   287  	defer c.Close()
   288  
   289  	req := &longrunningpb.CancelOperationRequest{
   290  		// TODO: Fill request struct fields.
   291  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
   292  	}
   293  	err = c.CancelOperation(ctx, req)
   294  	if err != nil {
   295  		// TODO: Handle error.
   296  	}
   297  }
   298  
   299  func ExampleVertexRagClient_DeleteOperation() {
   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.NewVertexRagClient(ctx)
   307  	if err != nil {
   308  		// TODO: Handle error.
   309  	}
   310  	defer c.Close()
   311  
   312  	req := &longrunningpb.DeleteOperationRequest{
   313  		// TODO: Fill request struct fields.
   314  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
   315  	}
   316  	err = c.DeleteOperation(ctx, req)
   317  	if err != nil {
   318  		// TODO: Handle error.
   319  	}
   320  }
   321  
   322  func ExampleVertexRagClient_GetOperation() {
   323  	ctx := context.Background()
   324  	// This snippet has been automatically generated and should be regarded as a code template only.
   325  	// It will require modifications to work:
   326  	// - It may require correct/in-range values for request initialization.
   327  	// - It may require specifying regional endpoints when creating the service client as shown in:
   328  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   329  	c, err := aiplatform.NewVertexRagClient(ctx)
   330  	if err != nil {
   331  		// TODO: Handle error.
   332  	}
   333  	defer c.Close()
   334  
   335  	req := &longrunningpb.GetOperationRequest{
   336  		// TODO: Fill request struct fields.
   337  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
   338  	}
   339  	resp, err := c.GetOperation(ctx, req)
   340  	if err != nil {
   341  		// TODO: Handle error.
   342  	}
   343  	// TODO: Use resp.
   344  	_ = resp
   345  }
   346  
   347  func ExampleVertexRagClient_ListOperations() {
   348  	ctx := context.Background()
   349  	// This snippet has been automatically generated and should be regarded as a code template only.
   350  	// It will require modifications to work:
   351  	// - It may require correct/in-range values for request initialization.
   352  	// - It may require specifying regional endpoints when creating the service client as shown in:
   353  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   354  	c, err := aiplatform.NewVertexRagClient(ctx)
   355  	if err != nil {
   356  		// TODO: Handle error.
   357  	}
   358  	defer c.Close()
   359  
   360  	req := &longrunningpb.ListOperationsRequest{
   361  		// TODO: Fill request struct fields.
   362  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
   363  	}
   364  	it := c.ListOperations(ctx, req)
   365  	for {
   366  		resp, err := it.Next()
   367  		if err == iterator.Done {
   368  			break
   369  		}
   370  		if err != nil {
   371  			// TODO: Handle error.
   372  		}
   373  		// TODO: Use resp.
   374  		_ = resp
   375  
   376  		// If you need to access the underlying RPC response,
   377  		// you can do so by casting the `Response` as below.
   378  		// Otherwise, remove this line. Only populated after
   379  		// first call to Next(). Not safe for concurrent access.
   380  		_ = it.Response.(*longrunningpb.ListOperationsResponse)
   381  	}
   382  }
   383  
   384  func ExampleVertexRagClient_WaitOperation() {
   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.NewVertexRagClient(ctx)
   392  	if err != nil {
   393  		// TODO: Handle error.
   394  	}
   395  	defer c.Close()
   396  
   397  	req := &longrunningpb.WaitOperationRequest{
   398  		// TODO: Fill request struct fields.
   399  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest.
   400  	}
   401  	resp, err := c.WaitOperation(ctx, req)
   402  	if err != nil {
   403  		// TODO: Handle error.
   404  	}
   405  	// TODO: Use resp.
   406  	_ = resp
   407  }