cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/vertex_rag_client.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
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"fmt"
    23  	"log/slog"
    24  	"math"
    25  	"net/http"
    26  	"net/url"
    27  
    28  	aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb"
    29  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    30  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    31  	gax "github.com/googleapis/gax-go/v2"
    32  	"google.golang.org/api/iterator"
    33  	"google.golang.org/api/option"
    34  	"google.golang.org/api/option/internaloption"
    35  	gtransport "google.golang.org/api/transport/grpc"
    36  	httptransport "google.golang.org/api/transport/http"
    37  	locationpb "google.golang.org/genproto/googleapis/cloud/location"
    38  	"google.golang.org/grpc"
    39  	"google.golang.org/protobuf/encoding/protojson"
    40  	"google.golang.org/protobuf/proto"
    41  )
    42  
    43  var newVertexRagClientHook clientHook
    44  
    45  // VertexRagCallOptions contains the retry settings for each method of VertexRagClient.
    46  type VertexRagCallOptions struct {
    47  	RetrieveContexts   []gax.CallOption
    48  	AugmentPrompt      []gax.CallOption
    49  	CorroborateContent []gax.CallOption
    50  	GetLocation        []gax.CallOption
    51  	ListLocations      []gax.CallOption
    52  	GetIamPolicy       []gax.CallOption
    53  	SetIamPolicy       []gax.CallOption
    54  	TestIamPermissions []gax.CallOption
    55  	CancelOperation    []gax.CallOption
    56  	DeleteOperation    []gax.CallOption
    57  	GetOperation       []gax.CallOption
    58  	ListOperations     []gax.CallOption
    59  	WaitOperation      []gax.CallOption
    60  }
    61  
    62  func defaultVertexRagGRPCClientOptions() []option.ClientOption {
    63  	return []option.ClientOption{
    64  		internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"),
    65  		internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"),
    66  		internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"),
    67  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    68  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
    69  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    70  		internaloption.EnableJwtWithScope(),
    71  		internaloption.EnableNewAuthLibrary(),
    72  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    73  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    74  	}
    75  }
    76  
    77  func defaultVertexRagCallOptions() *VertexRagCallOptions {
    78  	return &VertexRagCallOptions{
    79  		RetrieveContexts:   []gax.CallOption{},
    80  		AugmentPrompt:      []gax.CallOption{},
    81  		CorroborateContent: []gax.CallOption{},
    82  		GetLocation:        []gax.CallOption{},
    83  		ListLocations:      []gax.CallOption{},
    84  		GetIamPolicy:       []gax.CallOption{},
    85  		SetIamPolicy:       []gax.CallOption{},
    86  		TestIamPermissions: []gax.CallOption{},
    87  		CancelOperation:    []gax.CallOption{},
    88  		DeleteOperation:    []gax.CallOption{},
    89  		GetOperation:       []gax.CallOption{},
    90  		ListOperations:     []gax.CallOption{},
    91  		WaitOperation:      []gax.CallOption{},
    92  	}
    93  }
    94  
    95  func defaultVertexRagRESTCallOptions() *VertexRagCallOptions {
    96  	return &VertexRagCallOptions{
    97  		RetrieveContexts:   []gax.CallOption{},
    98  		AugmentPrompt:      []gax.CallOption{},
    99  		CorroborateContent: []gax.CallOption{},
   100  		GetLocation:        []gax.CallOption{},
   101  		ListLocations:      []gax.CallOption{},
   102  		GetIamPolicy:       []gax.CallOption{},
   103  		SetIamPolicy:       []gax.CallOption{},
   104  		TestIamPermissions: []gax.CallOption{},
   105  		CancelOperation:    []gax.CallOption{},
   106  		DeleteOperation:    []gax.CallOption{},
   107  		GetOperation:       []gax.CallOption{},
   108  		ListOperations:     []gax.CallOption{},
   109  		WaitOperation:      []gax.CallOption{},
   110  	}
   111  }
   112  
   113  // internalVertexRagClient is an interface that defines the methods available from Vertex AI API.
   114  type internalVertexRagClient interface {
   115  	Close() error
   116  	setGoogleClientInfo(...string)
   117  	Connection() *grpc.ClientConn
   118  	RetrieveContexts(context.Context, *aiplatformpb.RetrieveContextsRequest, ...gax.CallOption) (*aiplatformpb.RetrieveContextsResponse, error)
   119  	AugmentPrompt(context.Context, *aiplatformpb.AugmentPromptRequest, ...gax.CallOption) (*aiplatformpb.AugmentPromptResponse, error)
   120  	CorroborateContent(context.Context, *aiplatformpb.CorroborateContentRequest, ...gax.CallOption) (*aiplatformpb.CorroborateContentResponse, error)
   121  	GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
   122  	ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
   123  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   124  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   125  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   126  	CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
   127  	DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
   128  	GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   129  	ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
   130  	WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   131  }
   132  
   133  // VertexRagClient is a client for interacting with Vertex AI API.
   134  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   135  //
   136  // A service for retrieving relevant contexts.
   137  type VertexRagClient struct {
   138  	// The internal transport-dependent client.
   139  	internalClient internalVertexRagClient
   140  
   141  	// The call options for this service.
   142  	CallOptions *VertexRagCallOptions
   143  }
   144  
   145  // Wrapper methods routed to the internal client.
   146  
   147  // Close closes the connection to the API service. The user should invoke this when
   148  // the client is no longer required.
   149  func (c *VertexRagClient) Close() error {
   150  	return c.internalClient.Close()
   151  }
   152  
   153  // setGoogleClientInfo sets the name and version of the application in
   154  // the `x-goog-api-client` header passed on each request. Intended for
   155  // use by Google-written clients.
   156  func (c *VertexRagClient) setGoogleClientInfo(keyval ...string) {
   157  	c.internalClient.setGoogleClientInfo(keyval...)
   158  }
   159  
   160  // Connection returns a connection to the API service.
   161  //
   162  // Deprecated: Connections are now pooled so this method does not always
   163  // return the same resource.
   164  func (c *VertexRagClient) Connection() *grpc.ClientConn {
   165  	return c.internalClient.Connection()
   166  }
   167  
   168  // RetrieveContexts retrieves relevant contexts for a query.
   169  func (c *VertexRagClient) RetrieveContexts(ctx context.Context, req *aiplatformpb.RetrieveContextsRequest, opts ...gax.CallOption) (*aiplatformpb.RetrieveContextsResponse, error) {
   170  	return c.internalClient.RetrieveContexts(ctx, req, opts...)
   171  }
   172  
   173  // AugmentPrompt given an input prompt, it returns augmented prompt from vertex rag store
   174  // to guide LLM towards generating grounded responses.
   175  func (c *VertexRagClient) AugmentPrompt(ctx context.Context, req *aiplatformpb.AugmentPromptRequest, opts ...gax.CallOption) (*aiplatformpb.AugmentPromptResponse, error) {
   176  	return c.internalClient.AugmentPrompt(ctx, req, opts...)
   177  }
   178  
   179  // CorroborateContent given an input text, it returns a score that evaluates the factuality of
   180  // the text. It also extracts and returns claims from the text and provides
   181  // supporting facts.
   182  func (c *VertexRagClient) CorroborateContent(ctx context.Context, req *aiplatformpb.CorroborateContentRequest, opts ...gax.CallOption) (*aiplatformpb.CorroborateContentResponse, error) {
   183  	return c.internalClient.CorroborateContent(ctx, req, opts...)
   184  }
   185  
   186  // GetLocation gets information about a location.
   187  func (c *VertexRagClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   188  	return c.internalClient.GetLocation(ctx, req, opts...)
   189  }
   190  
   191  // ListLocations lists information about the supported locations for this service.
   192  func (c *VertexRagClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   193  	return c.internalClient.ListLocations(ctx, req, opts...)
   194  }
   195  
   196  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   197  // if the resource exists and does not have a policy set.
   198  func (c *VertexRagClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   199  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   200  }
   201  
   202  // SetIamPolicy sets the access control policy on the specified resource. Replaces
   203  // any existing policy.
   204  //
   205  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
   206  // errors.
   207  func (c *VertexRagClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   208  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   209  }
   210  
   211  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
   212  // resource does not exist, this will return an empty set of
   213  // permissions, not a NOT_FOUND error.
   214  //
   215  // Note: This operation is designed to be used for building
   216  // permission-aware UIs and command-line tools, not for authorization
   217  // checking. This operation may “fail open” without warning.
   218  func (c *VertexRagClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   219  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   220  }
   221  
   222  // CancelOperation is a utility method from google.longrunning.Operations.
   223  func (c *VertexRagClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   224  	return c.internalClient.CancelOperation(ctx, req, opts...)
   225  }
   226  
   227  // DeleteOperation is a utility method from google.longrunning.Operations.
   228  func (c *VertexRagClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   229  	return c.internalClient.DeleteOperation(ctx, req, opts...)
   230  }
   231  
   232  // GetOperation is a utility method from google.longrunning.Operations.
   233  func (c *VertexRagClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   234  	return c.internalClient.GetOperation(ctx, req, opts...)
   235  }
   236  
   237  // ListOperations is a utility method from google.longrunning.Operations.
   238  func (c *VertexRagClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   239  	return c.internalClient.ListOperations(ctx, req, opts...)
   240  }
   241  
   242  // WaitOperation is a utility method from google.longrunning.Operations.
   243  func (c *VertexRagClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   244  	return c.internalClient.WaitOperation(ctx, req, opts...)
   245  }
   246  
   247  // vertexRagGRPCClient is a client for interacting with Vertex AI API over gRPC transport.
   248  //
   249  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   250  type vertexRagGRPCClient struct {
   251  	// Connection pool of gRPC connections to the service.
   252  	connPool gtransport.ConnPool
   253  
   254  	// Points back to the CallOptions field of the containing VertexRagClient
   255  	CallOptions **VertexRagCallOptions
   256  
   257  	// The gRPC API client.
   258  	vertexRagClient aiplatformpb.VertexRagServiceClient
   259  
   260  	operationsClient longrunningpb.OperationsClient
   261  
   262  	iamPolicyClient iampb.IAMPolicyClient
   263  
   264  	locationsClient locationpb.LocationsClient
   265  
   266  	// The x-goog-* metadata to be sent with each request.
   267  	xGoogHeaders []string
   268  
   269  	logger *slog.Logger
   270  }
   271  
   272  // NewVertexRagClient creates a new vertex rag service client based on gRPC.
   273  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   274  //
   275  // A service for retrieving relevant contexts.
   276  func NewVertexRagClient(ctx context.Context, opts ...option.ClientOption) (*VertexRagClient, error) {
   277  	clientOpts := defaultVertexRagGRPCClientOptions()
   278  	if newVertexRagClientHook != nil {
   279  		hookOpts, err := newVertexRagClientHook(ctx, clientHookParams{})
   280  		if err != nil {
   281  			return nil, err
   282  		}
   283  		clientOpts = append(clientOpts, hookOpts...)
   284  	}
   285  
   286  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   287  	if err != nil {
   288  		return nil, err
   289  	}
   290  	client := VertexRagClient{CallOptions: defaultVertexRagCallOptions()}
   291  
   292  	c := &vertexRagGRPCClient{
   293  		connPool:         connPool,
   294  		vertexRagClient:  aiplatformpb.NewVertexRagServiceClient(connPool),
   295  		CallOptions:      &client.CallOptions,
   296  		logger:           internaloption.GetLogger(opts),
   297  		operationsClient: longrunningpb.NewOperationsClient(connPool),
   298  		iamPolicyClient:  iampb.NewIAMPolicyClient(connPool),
   299  		locationsClient:  locationpb.NewLocationsClient(connPool),
   300  	}
   301  	c.setGoogleClientInfo()
   302  
   303  	client.internalClient = c
   304  
   305  	return &client, nil
   306  }
   307  
   308  // Connection returns a connection to the API service.
   309  //
   310  // Deprecated: Connections are now pooled so this method does not always
   311  // return the same resource.
   312  func (c *vertexRagGRPCClient) Connection() *grpc.ClientConn {
   313  	return c.connPool.Conn()
   314  }
   315  
   316  // setGoogleClientInfo sets the name and version of the application in
   317  // the `x-goog-api-client` header passed on each request. Intended for
   318  // use by Google-written clients.
   319  func (c *vertexRagGRPCClient) setGoogleClientInfo(keyval ...string) {
   320  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   321  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
   322  	c.xGoogHeaders = []string{
   323  		"x-goog-api-client", gax.XGoogHeader(kv...),
   324  	}
   325  }
   326  
   327  // Close closes the connection to the API service. The user should invoke this when
   328  // the client is no longer required.
   329  func (c *vertexRagGRPCClient) Close() error {
   330  	return c.connPool.Close()
   331  }
   332  
   333  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   334  type vertexRagRESTClient struct {
   335  	// The http endpoint to connect to.
   336  	endpoint string
   337  
   338  	// The http client.
   339  	httpClient *http.Client
   340  
   341  	// The x-goog-* headers to be sent with each request.
   342  	xGoogHeaders []string
   343  
   344  	// Points back to the CallOptions field of the containing VertexRagClient
   345  	CallOptions **VertexRagCallOptions
   346  
   347  	logger *slog.Logger
   348  }
   349  
   350  // NewVertexRagRESTClient creates a new vertex rag service rest client.
   351  //
   352  // A service for retrieving relevant contexts.
   353  func NewVertexRagRESTClient(ctx context.Context, opts ...option.ClientOption) (*VertexRagClient, error) {
   354  	clientOpts := append(defaultVertexRagRESTClientOptions(), opts...)
   355  	httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
   356  	if err != nil {
   357  		return nil, err
   358  	}
   359  
   360  	callOpts := defaultVertexRagRESTCallOptions()
   361  	c := &vertexRagRESTClient{
   362  		endpoint:    endpoint,
   363  		httpClient:  httpClient,
   364  		CallOptions: &callOpts,
   365  		logger:      internaloption.GetLogger(opts),
   366  	}
   367  	c.setGoogleClientInfo()
   368  
   369  	return &VertexRagClient{internalClient: c, CallOptions: callOpts}, nil
   370  }
   371  
   372  func defaultVertexRagRESTClientOptions() []option.ClientOption {
   373  	return []option.ClientOption{
   374  		internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"),
   375  		internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"),
   376  		internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"),
   377  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
   378  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
   379  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
   380  		internaloption.EnableNewAuthLibrary(),
   381  	}
   382  }
   383  
   384  // setGoogleClientInfo sets the name and version of the application in
   385  // the `x-goog-api-client` header passed on each request. Intended for
   386  // use by Google-written clients.
   387  func (c *vertexRagRESTClient) setGoogleClientInfo(keyval ...string) {
   388  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   389  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
   390  	c.xGoogHeaders = []string{
   391  		"x-goog-api-client", gax.XGoogHeader(kv...),
   392  	}
   393  }
   394  
   395  // Close closes the connection to the API service. The user should invoke this when
   396  // the client is no longer required.
   397  func (c *vertexRagRESTClient) Close() error {
   398  	// Replace httpClient with nil to force cleanup.
   399  	c.httpClient = nil
   400  	return nil
   401  }
   402  
   403  // Connection returns a connection to the API service.
   404  //
   405  // Deprecated: This method always returns nil.
   406  func (c *vertexRagRESTClient) Connection() *grpc.ClientConn {
   407  	return nil
   408  }
   409  func (c *vertexRagGRPCClient) RetrieveContexts(ctx context.Context, req *aiplatformpb.RetrieveContextsRequest, opts ...gax.CallOption) (*aiplatformpb.RetrieveContextsResponse, error) {
   410  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   411  
   412  	hds = append(c.xGoogHeaders, hds...)
   413  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   414  	opts = append((*c.CallOptions).RetrieveContexts[0:len((*c.CallOptions).RetrieveContexts):len((*c.CallOptions).RetrieveContexts)], opts...)
   415  	var resp *aiplatformpb.RetrieveContextsResponse
   416  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   417  		var err error
   418  		resp, err = executeRPC(ctx, c.vertexRagClient.RetrieveContexts, req, settings.GRPC, c.logger, "RetrieveContexts")
   419  		return err
   420  	}, opts...)
   421  	if err != nil {
   422  		return nil, err
   423  	}
   424  	return resp, nil
   425  }
   426  
   427  func (c *vertexRagGRPCClient) AugmentPrompt(ctx context.Context, req *aiplatformpb.AugmentPromptRequest, opts ...gax.CallOption) (*aiplatformpb.AugmentPromptResponse, error) {
   428  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   429  
   430  	hds = append(c.xGoogHeaders, hds...)
   431  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   432  	opts = append((*c.CallOptions).AugmentPrompt[0:len((*c.CallOptions).AugmentPrompt):len((*c.CallOptions).AugmentPrompt)], opts...)
   433  	var resp *aiplatformpb.AugmentPromptResponse
   434  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   435  		var err error
   436  		resp, err = executeRPC(ctx, c.vertexRagClient.AugmentPrompt, req, settings.GRPC, c.logger, "AugmentPrompt")
   437  		return err
   438  	}, opts...)
   439  	if err != nil {
   440  		return nil, err
   441  	}
   442  	return resp, nil
   443  }
   444  
   445  func (c *vertexRagGRPCClient) CorroborateContent(ctx context.Context, req *aiplatformpb.CorroborateContentRequest, opts ...gax.CallOption) (*aiplatformpb.CorroborateContentResponse, error) {
   446  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   447  
   448  	hds = append(c.xGoogHeaders, hds...)
   449  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   450  	opts = append((*c.CallOptions).CorroborateContent[0:len((*c.CallOptions).CorroborateContent):len((*c.CallOptions).CorroborateContent)], opts...)
   451  	var resp *aiplatformpb.CorroborateContentResponse
   452  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   453  		var err error
   454  		resp, err = executeRPC(ctx, c.vertexRagClient.CorroborateContent, req, settings.GRPC, c.logger, "CorroborateContent")
   455  		return err
   456  	}, opts...)
   457  	if err != nil {
   458  		return nil, err
   459  	}
   460  	return resp, nil
   461  }
   462  
   463  func (c *vertexRagGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   464  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   465  
   466  	hds = append(c.xGoogHeaders, hds...)
   467  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   468  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   469  	var resp *locationpb.Location
   470  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   471  		var err error
   472  		resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
   473  		return err
   474  	}, opts...)
   475  	if err != nil {
   476  		return nil, err
   477  	}
   478  	return resp, nil
   479  }
   480  
   481  func (c *vertexRagGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   482  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   483  
   484  	hds = append(c.xGoogHeaders, hds...)
   485  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   486  	opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
   487  	it := &LocationIterator{}
   488  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   489  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   490  		resp := &locationpb.ListLocationsResponse{}
   491  		if pageToken != "" {
   492  			req.PageToken = pageToken
   493  		}
   494  		if pageSize > math.MaxInt32 {
   495  			req.PageSize = math.MaxInt32
   496  		} else if pageSize != 0 {
   497  			req.PageSize = int32(pageSize)
   498  		}
   499  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   500  			var err error
   501  			resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
   502  			return err
   503  		}, opts...)
   504  		if err != nil {
   505  			return nil, "", err
   506  		}
   507  
   508  		it.Response = resp
   509  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   510  	}
   511  	fetch := func(pageSize int, pageToken string) (string, error) {
   512  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   513  		if err != nil {
   514  			return "", err
   515  		}
   516  		it.items = append(it.items, items...)
   517  		return nextPageToken, nil
   518  	}
   519  
   520  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   521  	it.pageInfo.MaxSize = int(req.GetPageSize())
   522  	it.pageInfo.Token = req.GetPageToken()
   523  
   524  	return it
   525  }
   526  
   527  func (c *vertexRagGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   528  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   529  
   530  	hds = append(c.xGoogHeaders, hds...)
   531  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   532  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   533  	var resp *iampb.Policy
   534  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   535  		var err error
   536  		resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
   537  		return err
   538  	}, opts...)
   539  	if err != nil {
   540  		return nil, err
   541  	}
   542  	return resp, nil
   543  }
   544  
   545  func (c *vertexRagGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   546  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   547  
   548  	hds = append(c.xGoogHeaders, hds...)
   549  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   550  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   551  	var resp *iampb.Policy
   552  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   553  		var err error
   554  		resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
   555  		return err
   556  	}, opts...)
   557  	if err != nil {
   558  		return nil, err
   559  	}
   560  	return resp, nil
   561  }
   562  
   563  func (c *vertexRagGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   564  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   565  
   566  	hds = append(c.xGoogHeaders, hds...)
   567  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   568  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   569  	var resp *iampb.TestIamPermissionsResponse
   570  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   571  		var err error
   572  		resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
   573  		return err
   574  	}, opts...)
   575  	if err != nil {
   576  		return nil, err
   577  	}
   578  	return resp, nil
   579  }
   580  
   581  func (c *vertexRagGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   582  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   583  
   584  	hds = append(c.xGoogHeaders, hds...)
   585  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   586  	opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
   587  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   588  		var err error
   589  		_, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
   590  		return err
   591  	}, opts...)
   592  	return err
   593  }
   594  
   595  func (c *vertexRagGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   596  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   597  
   598  	hds = append(c.xGoogHeaders, hds...)
   599  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   600  	opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
   601  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   602  		var err error
   603  		_, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
   604  		return err
   605  	}, opts...)
   606  	return err
   607  }
   608  
   609  func (c *vertexRagGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   610  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   611  
   612  	hds = append(c.xGoogHeaders, hds...)
   613  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   614  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
   615  	var resp *longrunningpb.Operation
   616  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   617  		var err error
   618  		resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
   619  		return err
   620  	}, opts...)
   621  	if err != nil {
   622  		return nil, err
   623  	}
   624  	return resp, nil
   625  }
   626  
   627  func (c *vertexRagGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   628  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   629  
   630  	hds = append(c.xGoogHeaders, hds...)
   631  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   632  	opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
   633  	it := &OperationIterator{}
   634  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
   635  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
   636  		resp := &longrunningpb.ListOperationsResponse{}
   637  		if pageToken != "" {
   638  			req.PageToken = pageToken
   639  		}
   640  		if pageSize > math.MaxInt32 {
   641  			req.PageSize = math.MaxInt32
   642  		} else if pageSize != 0 {
   643  			req.PageSize = int32(pageSize)
   644  		}
   645  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   646  			var err error
   647  			resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
   648  			return err
   649  		}, opts...)
   650  		if err != nil {
   651  			return nil, "", err
   652  		}
   653  
   654  		it.Response = resp
   655  		return resp.GetOperations(), resp.GetNextPageToken(), nil
   656  	}
   657  	fetch := func(pageSize int, pageToken string) (string, error) {
   658  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   659  		if err != nil {
   660  			return "", err
   661  		}
   662  		it.items = append(it.items, items...)
   663  		return nextPageToken, nil
   664  	}
   665  
   666  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   667  	it.pageInfo.MaxSize = int(req.GetPageSize())
   668  	it.pageInfo.Token = req.GetPageToken()
   669  
   670  	return it
   671  }
   672  
   673  func (c *vertexRagGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   674  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   675  
   676  	hds = append(c.xGoogHeaders, hds...)
   677  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   678  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
   679  	var resp *longrunningpb.Operation
   680  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   681  		var err error
   682  		resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation")
   683  		return err
   684  	}, opts...)
   685  	if err != nil {
   686  		return nil, err
   687  	}
   688  	return resp, nil
   689  }
   690  
   691  // RetrieveContexts retrieves relevant contexts for a query.
   692  func (c *vertexRagRESTClient) RetrieveContexts(ctx context.Context, req *aiplatformpb.RetrieveContextsRequest, opts ...gax.CallOption) (*aiplatformpb.RetrieveContextsResponse, error) {
   693  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   694  	jsonReq, err := m.Marshal(req)
   695  	if err != nil {
   696  		return nil, err
   697  	}
   698  
   699  	baseUrl, err := url.Parse(c.endpoint)
   700  	if err != nil {
   701  		return nil, err
   702  	}
   703  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:retrieveContexts", req.GetParent())
   704  
   705  	params := url.Values{}
   706  	params.Add("$alt", "json;enum-encoding=int")
   707  
   708  	baseUrl.RawQuery = params.Encode()
   709  
   710  	// Build HTTP headers from client and context metadata.
   711  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   712  
   713  	hds = append(c.xGoogHeaders, hds...)
   714  	hds = append(hds, "Content-Type", "application/json")
   715  	headers := gax.BuildHeaders(ctx, hds...)
   716  	opts = append((*c.CallOptions).RetrieveContexts[0:len((*c.CallOptions).RetrieveContexts):len((*c.CallOptions).RetrieveContexts)], opts...)
   717  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   718  	resp := &aiplatformpb.RetrieveContextsResponse{}
   719  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   720  		if settings.Path != "" {
   721  			baseUrl.Path = settings.Path
   722  		}
   723  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   724  		if err != nil {
   725  			return err
   726  		}
   727  		httpReq = httpReq.WithContext(ctx)
   728  		httpReq.Header = headers
   729  
   730  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RetrieveContexts")
   731  		if err != nil {
   732  			return err
   733  		}
   734  
   735  		if err := unm.Unmarshal(buf, resp); err != nil {
   736  			return err
   737  		}
   738  
   739  		return nil
   740  	}, opts...)
   741  	if e != nil {
   742  		return nil, e
   743  	}
   744  	return resp, nil
   745  }
   746  
   747  // AugmentPrompt given an input prompt, it returns augmented prompt from vertex rag store
   748  // to guide LLM towards generating grounded responses.
   749  func (c *vertexRagRESTClient) AugmentPrompt(ctx context.Context, req *aiplatformpb.AugmentPromptRequest, opts ...gax.CallOption) (*aiplatformpb.AugmentPromptResponse, error) {
   750  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   751  	jsonReq, err := m.Marshal(req)
   752  	if err != nil {
   753  		return nil, err
   754  	}
   755  
   756  	baseUrl, err := url.Parse(c.endpoint)
   757  	if err != nil {
   758  		return nil, err
   759  	}
   760  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:augmentPrompt", req.GetParent())
   761  
   762  	params := url.Values{}
   763  	params.Add("$alt", "json;enum-encoding=int")
   764  
   765  	baseUrl.RawQuery = params.Encode()
   766  
   767  	// Build HTTP headers from client and context metadata.
   768  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   769  
   770  	hds = append(c.xGoogHeaders, hds...)
   771  	hds = append(hds, "Content-Type", "application/json")
   772  	headers := gax.BuildHeaders(ctx, hds...)
   773  	opts = append((*c.CallOptions).AugmentPrompt[0:len((*c.CallOptions).AugmentPrompt):len((*c.CallOptions).AugmentPrompt)], opts...)
   774  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   775  	resp := &aiplatformpb.AugmentPromptResponse{}
   776  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   777  		if settings.Path != "" {
   778  			baseUrl.Path = settings.Path
   779  		}
   780  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   781  		if err != nil {
   782  			return err
   783  		}
   784  		httpReq = httpReq.WithContext(ctx)
   785  		httpReq.Header = headers
   786  
   787  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "AugmentPrompt")
   788  		if err != nil {
   789  			return err
   790  		}
   791  
   792  		if err := unm.Unmarshal(buf, resp); err != nil {
   793  			return err
   794  		}
   795  
   796  		return nil
   797  	}, opts...)
   798  	if e != nil {
   799  		return nil, e
   800  	}
   801  	return resp, nil
   802  }
   803  
   804  // CorroborateContent given an input text, it returns a score that evaluates the factuality of
   805  // the text. It also extracts and returns claims from the text and provides
   806  // supporting facts.
   807  func (c *vertexRagRESTClient) CorroborateContent(ctx context.Context, req *aiplatformpb.CorroborateContentRequest, opts ...gax.CallOption) (*aiplatformpb.CorroborateContentResponse, error) {
   808  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   809  	jsonReq, err := m.Marshal(req)
   810  	if err != nil {
   811  		return nil, err
   812  	}
   813  
   814  	baseUrl, err := url.Parse(c.endpoint)
   815  	if err != nil {
   816  		return nil, err
   817  	}
   818  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:corroborateContent", req.GetParent())
   819  
   820  	params := url.Values{}
   821  	params.Add("$alt", "json;enum-encoding=int")
   822  
   823  	baseUrl.RawQuery = params.Encode()
   824  
   825  	// Build HTTP headers from client and context metadata.
   826  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   827  
   828  	hds = append(c.xGoogHeaders, hds...)
   829  	hds = append(hds, "Content-Type", "application/json")
   830  	headers := gax.BuildHeaders(ctx, hds...)
   831  	opts = append((*c.CallOptions).CorroborateContent[0:len((*c.CallOptions).CorroborateContent):len((*c.CallOptions).CorroborateContent)], opts...)
   832  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   833  	resp := &aiplatformpb.CorroborateContentResponse{}
   834  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   835  		if settings.Path != "" {
   836  			baseUrl.Path = settings.Path
   837  		}
   838  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
   839  		if err != nil {
   840  			return err
   841  		}
   842  		httpReq = httpReq.WithContext(ctx)
   843  		httpReq.Header = headers
   844  
   845  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CorroborateContent")
   846  		if err != nil {
   847  			return err
   848  		}
   849  
   850  		if err := unm.Unmarshal(buf, resp); err != nil {
   851  			return err
   852  		}
   853  
   854  		return nil
   855  	}, opts...)
   856  	if e != nil {
   857  		return nil, e
   858  	}
   859  	return resp, nil
   860  }
   861  
   862  // GetLocation gets information about a location.
   863  func (c *vertexRagRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   864  	baseUrl, err := url.Parse(c.endpoint)
   865  	if err != nil {
   866  		return nil, err
   867  	}
   868  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
   869  
   870  	params := url.Values{}
   871  	params.Add("$alt", "json;enum-encoding=int")
   872  
   873  	baseUrl.RawQuery = params.Encode()
   874  
   875  	// Build HTTP headers from client and context metadata.
   876  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   877  
   878  	hds = append(c.xGoogHeaders, hds...)
   879  	hds = append(hds, "Content-Type", "application/json")
   880  	headers := gax.BuildHeaders(ctx, hds...)
   881  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   882  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   883  	resp := &locationpb.Location{}
   884  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   885  		if settings.Path != "" {
   886  			baseUrl.Path = settings.Path
   887  		}
   888  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   889  		if err != nil {
   890  			return err
   891  		}
   892  		httpReq = httpReq.WithContext(ctx)
   893  		httpReq.Header = headers
   894  
   895  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
   896  		if err != nil {
   897  			return err
   898  		}
   899  
   900  		if err := unm.Unmarshal(buf, resp); err != nil {
   901  			return err
   902  		}
   903  
   904  		return nil
   905  	}, opts...)
   906  	if e != nil {
   907  		return nil, e
   908  	}
   909  	return resp, nil
   910  }
   911  
   912  // ListLocations lists information about the supported locations for this service.
   913  func (c *vertexRagRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   914  	it := &LocationIterator{}
   915  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   916  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
   917  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   918  		resp := &locationpb.ListLocationsResponse{}
   919  		if pageToken != "" {
   920  			req.PageToken = pageToken
   921  		}
   922  		if pageSize > math.MaxInt32 {
   923  			req.PageSize = math.MaxInt32
   924  		} else if pageSize != 0 {
   925  			req.PageSize = int32(pageSize)
   926  		}
   927  		baseUrl, err := url.Parse(c.endpoint)
   928  		if err != nil {
   929  			return nil, "", err
   930  		}
   931  		baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName())
   932  
   933  		params := url.Values{}
   934  		params.Add("$alt", "json;enum-encoding=int")
   935  		if req.GetFilter() != "" {
   936  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
   937  		}
   938  		if req.GetPageSize() != 0 {
   939  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
   940  		}
   941  		if req.GetPageToken() != "" {
   942  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
   943  		}
   944  
   945  		baseUrl.RawQuery = params.Encode()
   946  
   947  		// Build HTTP headers from client and context metadata.
   948  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
   949  		headers := gax.BuildHeaders(ctx, hds...)
   950  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   951  			if settings.Path != "" {
   952  				baseUrl.Path = settings.Path
   953  			}
   954  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
   955  			if err != nil {
   956  				return err
   957  			}
   958  			httpReq.Header = headers
   959  
   960  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
   961  			if err != nil {
   962  				return err
   963  			}
   964  			if err := unm.Unmarshal(buf, resp); err != nil {
   965  				return err
   966  			}
   967  
   968  			return nil
   969  		}, opts...)
   970  		if e != nil {
   971  			return nil, "", e
   972  		}
   973  		it.Response = resp
   974  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   975  	}
   976  
   977  	fetch := func(pageSize int, pageToken string) (string, error) {
   978  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   979  		if err != nil {
   980  			return "", err
   981  		}
   982  		it.items = append(it.items, items...)
   983  		return nextPageToken, nil
   984  	}
   985  
   986  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   987  	it.pageInfo.MaxSize = int(req.GetPageSize())
   988  	it.pageInfo.Token = req.GetPageToken()
   989  
   990  	return it
   991  }
   992  
   993  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   994  // if the resource exists and does not have a policy set.
   995  func (c *vertexRagRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   996  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
   997  	jsonReq, err := m.Marshal(req)
   998  	if err != nil {
   999  		return nil, err
  1000  	}
  1001  
  1002  	baseUrl, err := url.Parse(c.endpoint)
  1003  	if err != nil {
  1004  		return nil, err
  1005  	}
  1006  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource())
  1007  
  1008  	params := url.Values{}
  1009  	params.Add("$alt", "json;enum-encoding=int")
  1010  
  1011  	baseUrl.RawQuery = params.Encode()
  1012  
  1013  	// Build HTTP headers from client and context metadata.
  1014  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1015  
  1016  	hds = append(c.xGoogHeaders, hds...)
  1017  	hds = append(hds, "Content-Type", "application/json")
  1018  	headers := gax.BuildHeaders(ctx, hds...)
  1019  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
  1020  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1021  	resp := &iampb.Policy{}
  1022  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1023  		if settings.Path != "" {
  1024  			baseUrl.Path = settings.Path
  1025  		}
  1026  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1027  		if err != nil {
  1028  			return err
  1029  		}
  1030  		httpReq = httpReq.WithContext(ctx)
  1031  		httpReq.Header = headers
  1032  
  1033  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy")
  1034  		if err != nil {
  1035  			return err
  1036  		}
  1037  
  1038  		if err := unm.Unmarshal(buf, resp); err != nil {
  1039  			return err
  1040  		}
  1041  
  1042  		return nil
  1043  	}, opts...)
  1044  	if e != nil {
  1045  		return nil, e
  1046  	}
  1047  	return resp, nil
  1048  }
  1049  
  1050  // SetIamPolicy sets the access control policy on the specified resource. Replaces
  1051  // any existing policy.
  1052  //
  1053  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
  1054  // errors.
  1055  func (c *vertexRagRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1056  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1057  	jsonReq, err := m.Marshal(req)
  1058  	if err != nil {
  1059  		return nil, err
  1060  	}
  1061  
  1062  	baseUrl, err := url.Parse(c.endpoint)
  1063  	if err != nil {
  1064  		return nil, err
  1065  	}
  1066  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource())
  1067  
  1068  	params := url.Values{}
  1069  	params.Add("$alt", "json;enum-encoding=int")
  1070  
  1071  	baseUrl.RawQuery = params.Encode()
  1072  
  1073  	// Build HTTP headers from client and context metadata.
  1074  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1075  
  1076  	hds = append(c.xGoogHeaders, hds...)
  1077  	hds = append(hds, "Content-Type", "application/json")
  1078  	headers := gax.BuildHeaders(ctx, hds...)
  1079  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
  1080  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1081  	resp := &iampb.Policy{}
  1082  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1083  		if settings.Path != "" {
  1084  			baseUrl.Path = settings.Path
  1085  		}
  1086  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1087  		if err != nil {
  1088  			return err
  1089  		}
  1090  		httpReq = httpReq.WithContext(ctx)
  1091  		httpReq.Header = headers
  1092  
  1093  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
  1094  		if err != nil {
  1095  			return err
  1096  		}
  1097  
  1098  		if err := unm.Unmarshal(buf, resp); err != nil {
  1099  			return err
  1100  		}
  1101  
  1102  		return nil
  1103  	}, opts...)
  1104  	if e != nil {
  1105  		return nil, e
  1106  	}
  1107  	return resp, nil
  1108  }
  1109  
  1110  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
  1111  // resource does not exist, this will return an empty set of
  1112  // permissions, not a NOT_FOUND error.
  1113  //
  1114  // Note: This operation is designed to be used for building
  1115  // permission-aware UIs and command-line tools, not for authorization
  1116  // checking. This operation may “fail open” without warning.
  1117  func (c *vertexRagRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  1118  	m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
  1119  	jsonReq, err := m.Marshal(req)
  1120  	if err != nil {
  1121  		return nil, err
  1122  	}
  1123  
  1124  	baseUrl, err := url.Parse(c.endpoint)
  1125  	if err != nil {
  1126  		return nil, err
  1127  	}
  1128  	baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource())
  1129  
  1130  	params := url.Values{}
  1131  	params.Add("$alt", "json;enum-encoding=int")
  1132  
  1133  	baseUrl.RawQuery = params.Encode()
  1134  
  1135  	// Build HTTP headers from client and context metadata.
  1136  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
  1137  
  1138  	hds = append(c.xGoogHeaders, hds...)
  1139  	hds = append(hds, "Content-Type", "application/json")
  1140  	headers := gax.BuildHeaders(ctx, hds...)
  1141  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
  1142  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1143  	resp := &iampb.TestIamPermissionsResponse{}
  1144  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1145  		if settings.Path != "" {
  1146  			baseUrl.Path = settings.Path
  1147  		}
  1148  		httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
  1149  		if err != nil {
  1150  			return err
  1151  		}
  1152  		httpReq = httpReq.WithContext(ctx)
  1153  		httpReq.Header = headers
  1154  
  1155  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
  1156  		if err != nil {
  1157  			return err
  1158  		}
  1159  
  1160  		if err := unm.Unmarshal(buf, resp); err != nil {
  1161  			return err
  1162  		}
  1163  
  1164  		return nil
  1165  	}, opts...)
  1166  	if e != nil {
  1167  		return nil, e
  1168  	}
  1169  	return resp, nil
  1170  }
  1171  
  1172  // CancelOperation is a utility method from google.longrunning.Operations.
  1173  func (c *vertexRagRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
  1174  	baseUrl, err := url.Parse(c.endpoint)
  1175  	if err != nil {
  1176  		return err
  1177  	}
  1178  	baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName())
  1179  
  1180  	params := url.Values{}
  1181  	params.Add("$alt", "json;enum-encoding=int")
  1182  
  1183  	baseUrl.RawQuery = params.Encode()
  1184  
  1185  	// Build HTTP headers from client and context metadata.
  1186  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1187  
  1188  	hds = append(c.xGoogHeaders, hds...)
  1189  	hds = append(hds, "Content-Type", "application/json")
  1190  	headers := gax.BuildHeaders(ctx, hds...)
  1191  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1192  		if settings.Path != "" {
  1193  			baseUrl.Path = settings.Path
  1194  		}
  1195  		httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
  1196  		if err != nil {
  1197  			return err
  1198  		}
  1199  		httpReq = httpReq.WithContext(ctx)
  1200  		httpReq.Header = headers
  1201  
  1202  		_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation")
  1203  		return err
  1204  	}, opts...)
  1205  }
  1206  
  1207  // DeleteOperation is a utility method from google.longrunning.Operations.
  1208  func (c *vertexRagRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
  1209  	baseUrl, err := url.Parse(c.endpoint)
  1210  	if err != nil {
  1211  		return err
  1212  	}
  1213  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  1214  
  1215  	params := url.Values{}
  1216  	params.Add("$alt", "json;enum-encoding=int")
  1217  
  1218  	baseUrl.RawQuery = params.Encode()
  1219  
  1220  	// Build HTTP headers from client and context metadata.
  1221  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1222  
  1223  	hds = append(c.xGoogHeaders, hds...)
  1224  	hds = append(hds, "Content-Type", "application/json")
  1225  	headers := gax.BuildHeaders(ctx, hds...)
  1226  	return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1227  		if settings.Path != "" {
  1228  			baseUrl.Path = settings.Path
  1229  		}
  1230  		httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
  1231  		if err != nil {
  1232  			return err
  1233  		}
  1234  		httpReq = httpReq.WithContext(ctx)
  1235  		httpReq.Header = headers
  1236  
  1237  		_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
  1238  		return err
  1239  	}, opts...)
  1240  }
  1241  
  1242  // GetOperation is a utility method from google.longrunning.Operations.
  1243  func (c *vertexRagRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1244  	baseUrl, err := url.Parse(c.endpoint)
  1245  	if err != nil {
  1246  		return nil, err
  1247  	}
  1248  	baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName())
  1249  
  1250  	params := url.Values{}
  1251  	params.Add("$alt", "json;enum-encoding=int")
  1252  
  1253  	baseUrl.RawQuery = params.Encode()
  1254  
  1255  	// Build HTTP headers from client and context metadata.
  1256  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1257  
  1258  	hds = append(c.xGoogHeaders, hds...)
  1259  	hds = append(hds, "Content-Type", "application/json")
  1260  	headers := gax.BuildHeaders(ctx, hds...)
  1261  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
  1262  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1263  	resp := &longrunningpb.Operation{}
  1264  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1265  		if settings.Path != "" {
  1266  			baseUrl.Path = settings.Path
  1267  		}
  1268  		httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1269  		if err != nil {
  1270  			return err
  1271  		}
  1272  		httpReq = httpReq.WithContext(ctx)
  1273  		httpReq.Header = headers
  1274  
  1275  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
  1276  		if err != nil {
  1277  			return err
  1278  		}
  1279  
  1280  		if err := unm.Unmarshal(buf, resp); err != nil {
  1281  			return err
  1282  		}
  1283  
  1284  		return nil
  1285  	}, opts...)
  1286  	if e != nil {
  1287  		return nil, e
  1288  	}
  1289  	return resp, nil
  1290  }
  1291  
  1292  // ListOperations is a utility method from google.longrunning.Operations.
  1293  func (c *vertexRagRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
  1294  	it := &OperationIterator{}
  1295  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
  1296  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1297  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
  1298  		resp := &longrunningpb.ListOperationsResponse{}
  1299  		if pageToken != "" {
  1300  			req.PageToken = pageToken
  1301  		}
  1302  		if pageSize > math.MaxInt32 {
  1303  			req.PageSize = math.MaxInt32
  1304  		} else if pageSize != 0 {
  1305  			req.PageSize = int32(pageSize)
  1306  		}
  1307  		baseUrl, err := url.Parse(c.endpoint)
  1308  		if err != nil {
  1309  			return nil, "", err
  1310  		}
  1311  		baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName())
  1312  
  1313  		params := url.Values{}
  1314  		params.Add("$alt", "json;enum-encoding=int")
  1315  		if req.GetFilter() != "" {
  1316  			params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
  1317  		}
  1318  		if req.GetPageSize() != 0 {
  1319  			params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
  1320  		}
  1321  		if req.GetPageToken() != "" {
  1322  			params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
  1323  		}
  1324  
  1325  		baseUrl.RawQuery = params.Encode()
  1326  
  1327  		// Build HTTP headers from client and context metadata.
  1328  		hds := append(c.xGoogHeaders, "Content-Type", "application/json")
  1329  		headers := gax.BuildHeaders(ctx, hds...)
  1330  		e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1331  			if settings.Path != "" {
  1332  				baseUrl.Path = settings.Path
  1333  			}
  1334  			httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
  1335  			if err != nil {
  1336  				return err
  1337  			}
  1338  			httpReq.Header = headers
  1339  
  1340  			buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
  1341  			if err != nil {
  1342  				return err
  1343  			}
  1344  			if err := unm.Unmarshal(buf, resp); err != nil {
  1345  				return err
  1346  			}
  1347  
  1348  			return nil
  1349  		}, opts...)
  1350  		if e != nil {
  1351  			return nil, "", e
  1352  		}
  1353  		it.Response = resp
  1354  		return resp.GetOperations(), resp.GetNextPageToken(), nil
  1355  	}
  1356  
  1357  	fetch := func(pageSize int, pageToken string) (string, error) {
  1358  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1359  		if err != nil {
  1360  			return "", err
  1361  		}
  1362  		it.items = append(it.items, items...)
  1363  		return nextPageToken, nil
  1364  	}
  1365  
  1366  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1367  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1368  	it.pageInfo.Token = req.GetPageToken()
  1369  
  1370  	return it
  1371  }
  1372  
  1373  // WaitOperation is a utility method from google.longrunning.Operations.
  1374  func (c *vertexRagRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  1375  	baseUrl, err := url.Parse(c.endpoint)
  1376  	if err != nil {
  1377  		return nil, err
  1378  	}
  1379  	baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName())
  1380  
  1381  	params := url.Values{}
  1382  	params.Add("$alt", "json;enum-encoding=int")
  1383  	if req.GetTimeout() != nil {
  1384  		field, err := protojson.Marshal(req.GetTimeout())
  1385  		if err != nil {
  1386  			return nil, err
  1387  		}
  1388  		params.Add("timeout", string(field[1:len(field)-1]))
  1389  	}
  1390  
  1391  	baseUrl.RawQuery = params.Encode()
  1392  
  1393  	// Build HTTP headers from client and context metadata.
  1394  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  1395  
  1396  	hds = append(c.xGoogHeaders, hds...)
  1397  	hds = append(hds, "Content-Type", "application/json")
  1398  	headers := gax.BuildHeaders(ctx, hds...)
  1399  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
  1400  	unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
  1401  	resp := &longrunningpb.Operation{}
  1402  	e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1403  		if settings.Path != "" {
  1404  			baseUrl.Path = settings.Path
  1405  		}
  1406  		httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
  1407  		if err != nil {
  1408  			return err
  1409  		}
  1410  		httpReq = httpReq.WithContext(ctx)
  1411  		httpReq.Header = headers
  1412  
  1413  		buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation")
  1414  		if err != nil {
  1415  			return err
  1416  		}
  1417  
  1418  		if err := unm.Unmarshal(buf, resp); err != nil {
  1419  			return err
  1420  		}
  1421  
  1422  		return nil
  1423  	}, opts...)
  1424  	if e != nil {
  1425  		return nil, e
  1426  	}
  1427  	return resp, nil
  1428  }