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