cloud.google.com/go/aiplatform@v1.106.0/apiv1/llm_utility_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  	"context"
    21  	"fmt"
    22  	"log/slog"
    23  	"math"
    24  	"net/url"
    25  
    26  	aiplatformpb "cloud.google.com/go/aiplatform/apiv1/aiplatformpb"
    27  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    28  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    29  	gax "github.com/googleapis/gax-go/v2"
    30  	"google.golang.org/api/iterator"
    31  	"google.golang.org/api/option"
    32  	"google.golang.org/api/option/internaloption"
    33  	gtransport "google.golang.org/api/transport/grpc"
    34  	locationpb "google.golang.org/genproto/googleapis/cloud/location"
    35  	"google.golang.org/grpc"
    36  	"google.golang.org/protobuf/proto"
    37  )
    38  
    39  var newLlmUtilityClientHook clientHook
    40  
    41  // LlmUtilityCallOptions contains the retry settings for each method of LlmUtilityClient.
    42  type LlmUtilityCallOptions struct {
    43  	CountTokens        []gax.CallOption
    44  	ComputeTokens      []gax.CallOption
    45  	GetLocation        []gax.CallOption
    46  	ListLocations      []gax.CallOption
    47  	GetIamPolicy       []gax.CallOption
    48  	SetIamPolicy       []gax.CallOption
    49  	TestIamPermissions []gax.CallOption
    50  	CancelOperation    []gax.CallOption
    51  	DeleteOperation    []gax.CallOption
    52  	GetOperation       []gax.CallOption
    53  	ListOperations     []gax.CallOption
    54  	WaitOperation      []gax.CallOption
    55  }
    56  
    57  func defaultLlmUtilityGRPCClientOptions() []option.ClientOption {
    58  	return []option.ClientOption{
    59  		internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"),
    60  		internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"),
    61  		internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"),
    62  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    63  		internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"),
    64  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    65  		internaloption.EnableJwtWithScope(),
    66  		internaloption.EnableNewAuthLibrary(),
    67  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    68  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    69  	}
    70  }
    71  
    72  func defaultLlmUtilityCallOptions() *LlmUtilityCallOptions {
    73  	return &LlmUtilityCallOptions{
    74  		CountTokens:        []gax.CallOption{},
    75  		ComputeTokens:      []gax.CallOption{},
    76  		GetLocation:        []gax.CallOption{},
    77  		ListLocations:      []gax.CallOption{},
    78  		GetIamPolicy:       []gax.CallOption{},
    79  		SetIamPolicy:       []gax.CallOption{},
    80  		TestIamPermissions: []gax.CallOption{},
    81  		CancelOperation:    []gax.CallOption{},
    82  		DeleteOperation:    []gax.CallOption{},
    83  		GetOperation:       []gax.CallOption{},
    84  		ListOperations:     []gax.CallOption{},
    85  		WaitOperation:      []gax.CallOption{},
    86  	}
    87  }
    88  
    89  // internalLlmUtilityClient is an interface that defines the methods available from Vertex AI API.
    90  type internalLlmUtilityClient interface {
    91  	Close() error
    92  	setGoogleClientInfo(...string)
    93  	Connection() *grpc.ClientConn
    94  	CountTokens(context.Context, *aiplatformpb.CountTokensRequest, ...gax.CallOption) (*aiplatformpb.CountTokensResponse, error)
    95  	ComputeTokens(context.Context, *aiplatformpb.ComputeTokensRequest, ...gax.CallOption) (*aiplatformpb.ComputeTokensResponse, error)
    96  	GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
    97  	ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
    98  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
    99  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   100  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   101  	CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
   102  	DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
   103  	GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   104  	ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
   105  	WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
   106  }
   107  
   108  // LlmUtilityClient is a client for interacting with Vertex AI API.
   109  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   110  //
   111  // Service for LLM related utility functions.
   112  type LlmUtilityClient struct {
   113  	// The internal transport-dependent client.
   114  	internalClient internalLlmUtilityClient
   115  
   116  	// The call options for this service.
   117  	CallOptions *LlmUtilityCallOptions
   118  }
   119  
   120  // Wrapper methods routed to the internal client.
   121  
   122  // Close closes the connection to the API service. The user should invoke this when
   123  // the client is no longer required.
   124  func (c *LlmUtilityClient) Close() error {
   125  	return c.internalClient.Close()
   126  }
   127  
   128  // setGoogleClientInfo sets the name and version of the application in
   129  // the `x-goog-api-client` header passed on each request. Intended for
   130  // use by Google-written clients.
   131  func (c *LlmUtilityClient) setGoogleClientInfo(keyval ...string) {
   132  	c.internalClient.setGoogleClientInfo(keyval...)
   133  }
   134  
   135  // Connection returns a connection to the API service.
   136  //
   137  // Deprecated: Connections are now pooled so this method does not always
   138  // return the same resource.
   139  func (c *LlmUtilityClient) Connection() *grpc.ClientConn {
   140  	return c.internalClient.Connection()
   141  }
   142  
   143  // CountTokens perform a token counting.
   144  func (c *LlmUtilityClient) CountTokens(ctx context.Context, req *aiplatformpb.CountTokensRequest, opts ...gax.CallOption) (*aiplatformpb.CountTokensResponse, error) {
   145  	return c.internalClient.CountTokens(ctx, req, opts...)
   146  }
   147  
   148  // ComputeTokens return a list of tokens based on the input text.
   149  func (c *LlmUtilityClient) ComputeTokens(ctx context.Context, req *aiplatformpb.ComputeTokensRequest, opts ...gax.CallOption) (*aiplatformpb.ComputeTokensResponse, error) {
   150  	return c.internalClient.ComputeTokens(ctx, req, opts...)
   151  }
   152  
   153  // GetLocation gets information about a location.
   154  func (c *LlmUtilityClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   155  	return c.internalClient.GetLocation(ctx, req, opts...)
   156  }
   157  
   158  // ListLocations lists information about the supported locations for this service.
   159  func (c *LlmUtilityClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   160  	return c.internalClient.ListLocations(ctx, req, opts...)
   161  }
   162  
   163  // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
   164  // if the resource exists and does not have a policy set.
   165  func (c *LlmUtilityClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   166  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   167  }
   168  
   169  // SetIamPolicy sets the access control policy on the specified resource. Replaces
   170  // any existing policy.
   171  //
   172  // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
   173  // errors.
   174  func (c *LlmUtilityClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   175  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   176  }
   177  
   178  // TestIamPermissions returns permissions that a caller has on the specified resource. If the
   179  // resource does not exist, this will return an empty set of
   180  // permissions, not a NOT_FOUND error.
   181  //
   182  // Note: This operation is designed to be used for building
   183  // permission-aware UIs and command-line tools, not for authorization
   184  // checking. This operation may “fail open” without warning.
   185  func (c *LlmUtilityClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   186  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   187  }
   188  
   189  // CancelOperation is a utility method from google.longrunning.Operations.
   190  func (c *LlmUtilityClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   191  	return c.internalClient.CancelOperation(ctx, req, opts...)
   192  }
   193  
   194  // DeleteOperation is a utility method from google.longrunning.Operations.
   195  func (c *LlmUtilityClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   196  	return c.internalClient.DeleteOperation(ctx, req, opts...)
   197  }
   198  
   199  // GetOperation is a utility method from google.longrunning.Operations.
   200  func (c *LlmUtilityClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   201  	return c.internalClient.GetOperation(ctx, req, opts...)
   202  }
   203  
   204  // ListOperations is a utility method from google.longrunning.Operations.
   205  func (c *LlmUtilityClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   206  	return c.internalClient.ListOperations(ctx, req, opts...)
   207  }
   208  
   209  // WaitOperation is a utility method from google.longrunning.Operations.
   210  func (c *LlmUtilityClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   211  	return c.internalClient.WaitOperation(ctx, req, opts...)
   212  }
   213  
   214  // llmUtilityGRPCClient is a client for interacting with Vertex AI API over gRPC transport.
   215  //
   216  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   217  type llmUtilityGRPCClient struct {
   218  	// Connection pool of gRPC connections to the service.
   219  	connPool gtransport.ConnPool
   220  
   221  	// Points back to the CallOptions field of the containing LlmUtilityClient
   222  	CallOptions **LlmUtilityCallOptions
   223  
   224  	// The gRPC API client.
   225  	llmUtilityClient aiplatformpb.LlmUtilityServiceClient
   226  
   227  	operationsClient longrunningpb.OperationsClient
   228  
   229  	iamPolicyClient iampb.IAMPolicyClient
   230  
   231  	locationsClient locationpb.LocationsClient
   232  
   233  	// The x-goog-* metadata to be sent with each request.
   234  	xGoogHeaders []string
   235  
   236  	logger *slog.Logger
   237  }
   238  
   239  // NewLlmUtilityClient creates a new llm utility service client based on gRPC.
   240  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   241  //
   242  // Service for LLM related utility functions.
   243  func NewLlmUtilityClient(ctx context.Context, opts ...option.ClientOption) (*LlmUtilityClient, error) {
   244  	clientOpts := defaultLlmUtilityGRPCClientOptions()
   245  	if newLlmUtilityClientHook != nil {
   246  		hookOpts, err := newLlmUtilityClientHook(ctx, clientHookParams{})
   247  		if err != nil {
   248  			return nil, err
   249  		}
   250  		clientOpts = append(clientOpts, hookOpts...)
   251  	}
   252  
   253  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   254  	if err != nil {
   255  		return nil, err
   256  	}
   257  	client := LlmUtilityClient{CallOptions: defaultLlmUtilityCallOptions()}
   258  
   259  	c := &llmUtilityGRPCClient{
   260  		connPool:         connPool,
   261  		llmUtilityClient: aiplatformpb.NewLlmUtilityServiceClient(connPool),
   262  		CallOptions:      &client.CallOptions,
   263  		logger:           internaloption.GetLogger(opts),
   264  		operationsClient: longrunningpb.NewOperationsClient(connPool),
   265  		iamPolicyClient:  iampb.NewIAMPolicyClient(connPool),
   266  		locationsClient:  locationpb.NewLocationsClient(connPool),
   267  	}
   268  	c.setGoogleClientInfo()
   269  
   270  	client.internalClient = c
   271  
   272  	return &client, nil
   273  }
   274  
   275  // Connection returns a connection to the API service.
   276  //
   277  // Deprecated: Connections are now pooled so this method does not always
   278  // return the same resource.
   279  func (c *llmUtilityGRPCClient) Connection() *grpc.ClientConn {
   280  	return c.connPool.Conn()
   281  }
   282  
   283  // setGoogleClientInfo sets the name and version of the application in
   284  // the `x-goog-api-client` header passed on each request. Intended for
   285  // use by Google-written clients.
   286  func (c *llmUtilityGRPCClient) setGoogleClientInfo(keyval ...string) {
   287  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   288  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
   289  	c.xGoogHeaders = []string{
   290  		"x-goog-api-client", gax.XGoogHeader(kv...),
   291  	}
   292  }
   293  
   294  // Close closes the connection to the API service. The user should invoke this when
   295  // the client is no longer required.
   296  func (c *llmUtilityGRPCClient) Close() error {
   297  	return c.connPool.Close()
   298  }
   299  
   300  func (c *llmUtilityGRPCClient) CountTokens(ctx context.Context, req *aiplatformpb.CountTokensRequest, opts ...gax.CallOption) (*aiplatformpb.CountTokensResponse, error) {
   301  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint", url.QueryEscape(req.GetEndpoint()))}
   302  
   303  	hds = append(c.xGoogHeaders, hds...)
   304  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   305  	opts = append((*c.CallOptions).CountTokens[0:len((*c.CallOptions).CountTokens):len((*c.CallOptions).CountTokens)], opts...)
   306  	var resp *aiplatformpb.CountTokensResponse
   307  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   308  		var err error
   309  		resp, err = executeRPC(ctx, c.llmUtilityClient.CountTokens, req, settings.GRPC, c.logger, "CountTokens")
   310  		return err
   311  	}, opts...)
   312  	if err != nil {
   313  		return nil, err
   314  	}
   315  	return resp, nil
   316  }
   317  
   318  func (c *llmUtilityGRPCClient) ComputeTokens(ctx context.Context, req *aiplatformpb.ComputeTokensRequest, opts ...gax.CallOption) (*aiplatformpb.ComputeTokensResponse, error) {
   319  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "endpoint", url.QueryEscape(req.GetEndpoint()))}
   320  
   321  	hds = append(c.xGoogHeaders, hds...)
   322  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   323  	opts = append((*c.CallOptions).ComputeTokens[0:len((*c.CallOptions).ComputeTokens):len((*c.CallOptions).ComputeTokens)], opts...)
   324  	var resp *aiplatformpb.ComputeTokensResponse
   325  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   326  		var err error
   327  		resp, err = executeRPC(ctx, c.llmUtilityClient.ComputeTokens, req, settings.GRPC, c.logger, "ComputeTokens")
   328  		return err
   329  	}, opts...)
   330  	if err != nil {
   331  		return nil, err
   332  	}
   333  	return resp, nil
   334  }
   335  
   336  func (c *llmUtilityGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
   337  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   338  
   339  	hds = append(c.xGoogHeaders, hds...)
   340  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   341  	opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
   342  	var resp *locationpb.Location
   343  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   344  		var err error
   345  		resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
   346  		return err
   347  	}, opts...)
   348  	if err != nil {
   349  		return nil, err
   350  	}
   351  	return resp, nil
   352  }
   353  
   354  func (c *llmUtilityGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
   355  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   356  
   357  	hds = append(c.xGoogHeaders, hds...)
   358  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   359  	opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
   360  	it := &LocationIterator{}
   361  	req = proto.Clone(req).(*locationpb.ListLocationsRequest)
   362  	it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
   363  		resp := &locationpb.ListLocationsResponse{}
   364  		if pageToken != "" {
   365  			req.PageToken = pageToken
   366  		}
   367  		if pageSize > math.MaxInt32 {
   368  			req.PageSize = math.MaxInt32
   369  		} else if pageSize != 0 {
   370  			req.PageSize = int32(pageSize)
   371  		}
   372  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   373  			var err error
   374  			resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
   375  			return err
   376  		}, opts...)
   377  		if err != nil {
   378  			return nil, "", err
   379  		}
   380  
   381  		it.Response = resp
   382  		return resp.GetLocations(), resp.GetNextPageToken(), nil
   383  	}
   384  	fetch := func(pageSize int, pageToken string) (string, error) {
   385  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   386  		if err != nil {
   387  			return "", err
   388  		}
   389  		it.items = append(it.items, items...)
   390  		return nextPageToken, nil
   391  	}
   392  
   393  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   394  	it.pageInfo.MaxSize = int(req.GetPageSize())
   395  	it.pageInfo.Token = req.GetPageToken()
   396  
   397  	return it
   398  }
   399  
   400  func (c *llmUtilityGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   401  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   402  
   403  	hds = append(c.xGoogHeaders, hds...)
   404  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   405  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
   406  	var resp *iampb.Policy
   407  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   408  		var err error
   409  		resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
   410  		return err
   411  	}, opts...)
   412  	if err != nil {
   413  		return nil, err
   414  	}
   415  	return resp, nil
   416  }
   417  
   418  func (c *llmUtilityGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   419  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   420  
   421  	hds = append(c.xGoogHeaders, hds...)
   422  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   423  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
   424  	var resp *iampb.Policy
   425  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   426  		var err error
   427  		resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
   428  		return err
   429  	}, opts...)
   430  	if err != nil {
   431  		return nil, err
   432  	}
   433  	return resp, nil
   434  }
   435  
   436  func (c *llmUtilityGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   437  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
   438  
   439  	hds = append(c.xGoogHeaders, hds...)
   440  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   441  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
   442  	var resp *iampb.TestIamPermissionsResponse
   443  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   444  		var err error
   445  		resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
   446  		return err
   447  	}, opts...)
   448  	if err != nil {
   449  		return nil, err
   450  	}
   451  	return resp, nil
   452  }
   453  
   454  func (c *llmUtilityGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
   455  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   456  
   457  	hds = append(c.xGoogHeaders, hds...)
   458  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   459  	opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
   460  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   461  		var err error
   462  		_, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
   463  		return err
   464  	}, opts...)
   465  	return err
   466  }
   467  
   468  func (c *llmUtilityGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
   469  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   470  
   471  	hds = append(c.xGoogHeaders, hds...)
   472  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   473  	opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
   474  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   475  		var err error
   476  		_, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
   477  		return err
   478  	}, opts...)
   479  	return err
   480  }
   481  
   482  func (c *llmUtilityGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   483  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   484  
   485  	hds = append(c.xGoogHeaders, hds...)
   486  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   487  	opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
   488  	var resp *longrunningpb.Operation
   489  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   490  		var err error
   491  		resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
   492  		return err
   493  	}, opts...)
   494  	if err != nil {
   495  		return nil, err
   496  	}
   497  	return resp, nil
   498  }
   499  
   500  func (c *llmUtilityGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
   501  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   502  
   503  	hds = append(c.xGoogHeaders, hds...)
   504  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   505  	opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
   506  	it := &OperationIterator{}
   507  	req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
   508  	it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
   509  		resp := &longrunningpb.ListOperationsResponse{}
   510  		if pageToken != "" {
   511  			req.PageToken = pageToken
   512  		}
   513  		if pageSize > math.MaxInt32 {
   514  			req.PageSize = math.MaxInt32
   515  		} else if pageSize != 0 {
   516  			req.PageSize = int32(pageSize)
   517  		}
   518  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   519  			var err error
   520  			resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
   521  			return err
   522  		}, opts...)
   523  		if err != nil {
   524  			return nil, "", err
   525  		}
   526  
   527  		it.Response = resp
   528  		return resp.GetOperations(), resp.GetNextPageToken(), nil
   529  	}
   530  	fetch := func(pageSize int, pageToken string) (string, error) {
   531  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   532  		if err != nil {
   533  			return "", err
   534  		}
   535  		it.items = append(it.items, items...)
   536  		return nextPageToken, nil
   537  	}
   538  
   539  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   540  	it.pageInfo.MaxSize = int(req.GetPageSize())
   541  	it.pageInfo.Token = req.GetPageToken()
   542  
   543  	return it
   544  }
   545  
   546  func (c *llmUtilityGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
   547  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   548  
   549  	hds = append(c.xGoogHeaders, hds...)
   550  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   551  	opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
   552  	var resp *longrunningpb.Operation
   553  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   554  		var err error
   555  		resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation")
   556  		return err
   557  	}, opts...)
   558  	if err != nil {
   559  		return nil, err
   560  	}
   561  	return resp, nil
   562  }