cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/vertex_rag_data_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 "cloud.google.com/go/longrunning" 31 lroauto "cloud.google.com/go/longrunning/autogen" 32 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" 33 gax "github.com/googleapis/gax-go/v2" 34 "google.golang.org/api/iterator" 35 "google.golang.org/api/option" 36 "google.golang.org/api/option/internaloption" 37 gtransport "google.golang.org/api/transport/grpc" 38 httptransport "google.golang.org/api/transport/http" 39 locationpb "google.golang.org/genproto/googleapis/cloud/location" 40 "google.golang.org/grpc" 41 "google.golang.org/protobuf/encoding/protojson" 42 "google.golang.org/protobuf/proto" 43 ) 44 45 var newVertexRagDataClientHook clientHook 46 47 // VertexRagDataCallOptions contains the retry settings for each method of VertexRagDataClient. 48 type VertexRagDataCallOptions struct { 49 CreateRagCorpus []gax.CallOption 50 UpdateRagCorpus []gax.CallOption 51 GetRagCorpus []gax.CallOption 52 ListRagCorpora []gax.CallOption 53 DeleteRagCorpus []gax.CallOption 54 UploadRagFile []gax.CallOption 55 ImportRagFiles []gax.CallOption 56 GetRagFile []gax.CallOption 57 ListRagFiles []gax.CallOption 58 DeleteRagFile []gax.CallOption 59 UpdateRagEngineConfig []gax.CallOption 60 GetRagEngineConfig []gax.CallOption 61 GetLocation []gax.CallOption 62 ListLocations []gax.CallOption 63 GetIamPolicy []gax.CallOption 64 SetIamPolicy []gax.CallOption 65 TestIamPermissions []gax.CallOption 66 CancelOperation []gax.CallOption 67 DeleteOperation []gax.CallOption 68 GetOperation []gax.CallOption 69 ListOperations []gax.CallOption 70 WaitOperation []gax.CallOption 71 } 72 73 func defaultVertexRagDataGRPCClientOptions() []option.ClientOption { 74 return []option.ClientOption{ 75 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 76 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 77 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 78 internaloption.WithDefaultUniverseDomain("googleapis.com"), 79 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 80 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 81 internaloption.EnableJwtWithScope(), 82 internaloption.EnableNewAuthLibrary(), 83 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 84 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 85 } 86 } 87 88 func defaultVertexRagDataCallOptions() *VertexRagDataCallOptions { 89 return &VertexRagDataCallOptions{ 90 CreateRagCorpus: []gax.CallOption{}, 91 UpdateRagCorpus: []gax.CallOption{}, 92 GetRagCorpus: []gax.CallOption{}, 93 ListRagCorpora: []gax.CallOption{}, 94 DeleteRagCorpus: []gax.CallOption{}, 95 UploadRagFile: []gax.CallOption{}, 96 ImportRagFiles: []gax.CallOption{}, 97 GetRagFile: []gax.CallOption{}, 98 ListRagFiles: []gax.CallOption{}, 99 DeleteRagFile: []gax.CallOption{}, 100 UpdateRagEngineConfig: []gax.CallOption{}, 101 GetRagEngineConfig: []gax.CallOption{}, 102 GetLocation: []gax.CallOption{}, 103 ListLocations: []gax.CallOption{}, 104 GetIamPolicy: []gax.CallOption{}, 105 SetIamPolicy: []gax.CallOption{}, 106 TestIamPermissions: []gax.CallOption{}, 107 CancelOperation: []gax.CallOption{}, 108 DeleteOperation: []gax.CallOption{}, 109 GetOperation: []gax.CallOption{}, 110 ListOperations: []gax.CallOption{}, 111 WaitOperation: []gax.CallOption{}, 112 } 113 } 114 115 func defaultVertexRagDataRESTCallOptions() *VertexRagDataCallOptions { 116 return &VertexRagDataCallOptions{ 117 CreateRagCorpus: []gax.CallOption{}, 118 UpdateRagCorpus: []gax.CallOption{}, 119 GetRagCorpus: []gax.CallOption{}, 120 ListRagCorpora: []gax.CallOption{}, 121 DeleteRagCorpus: []gax.CallOption{}, 122 UploadRagFile: []gax.CallOption{}, 123 ImportRagFiles: []gax.CallOption{}, 124 GetRagFile: []gax.CallOption{}, 125 ListRagFiles: []gax.CallOption{}, 126 DeleteRagFile: []gax.CallOption{}, 127 UpdateRagEngineConfig: []gax.CallOption{}, 128 GetRagEngineConfig: []gax.CallOption{}, 129 GetLocation: []gax.CallOption{}, 130 ListLocations: []gax.CallOption{}, 131 GetIamPolicy: []gax.CallOption{}, 132 SetIamPolicy: []gax.CallOption{}, 133 TestIamPermissions: []gax.CallOption{}, 134 CancelOperation: []gax.CallOption{}, 135 DeleteOperation: []gax.CallOption{}, 136 GetOperation: []gax.CallOption{}, 137 ListOperations: []gax.CallOption{}, 138 WaitOperation: []gax.CallOption{}, 139 } 140 } 141 142 // internalVertexRagDataClient is an interface that defines the methods available from Vertex AI API. 143 type internalVertexRagDataClient interface { 144 Close() error 145 setGoogleClientInfo(...string) 146 Connection() *grpc.ClientConn 147 CreateRagCorpus(context.Context, *aiplatformpb.CreateRagCorpusRequest, ...gax.CallOption) (*CreateRagCorpusOperation, error) 148 CreateRagCorpusOperation(name string) *CreateRagCorpusOperation 149 UpdateRagCorpus(context.Context, *aiplatformpb.UpdateRagCorpusRequest, ...gax.CallOption) (*UpdateRagCorpusOperation, error) 150 UpdateRagCorpusOperation(name string) *UpdateRagCorpusOperation 151 GetRagCorpus(context.Context, *aiplatformpb.GetRagCorpusRequest, ...gax.CallOption) (*aiplatformpb.RagCorpus, error) 152 ListRagCorpora(context.Context, *aiplatformpb.ListRagCorporaRequest, ...gax.CallOption) *RagCorpusIterator 153 DeleteRagCorpus(context.Context, *aiplatformpb.DeleteRagCorpusRequest, ...gax.CallOption) (*DeleteRagCorpusOperation, error) 154 DeleteRagCorpusOperation(name string) *DeleteRagCorpusOperation 155 UploadRagFile(context.Context, *aiplatformpb.UploadRagFileRequest, ...gax.CallOption) (*aiplatformpb.UploadRagFileResponse, error) 156 ImportRagFiles(context.Context, *aiplatformpb.ImportRagFilesRequest, ...gax.CallOption) (*ImportRagFilesOperation, error) 157 ImportRagFilesOperation(name string) *ImportRagFilesOperation 158 GetRagFile(context.Context, *aiplatformpb.GetRagFileRequest, ...gax.CallOption) (*aiplatformpb.RagFile, error) 159 ListRagFiles(context.Context, *aiplatformpb.ListRagFilesRequest, ...gax.CallOption) *RagFileIterator 160 DeleteRagFile(context.Context, *aiplatformpb.DeleteRagFileRequest, ...gax.CallOption) (*DeleteRagFileOperation, error) 161 DeleteRagFileOperation(name string) *DeleteRagFileOperation 162 UpdateRagEngineConfig(context.Context, *aiplatformpb.UpdateRagEngineConfigRequest, ...gax.CallOption) (*UpdateRagEngineConfigOperation, error) 163 UpdateRagEngineConfigOperation(name string) *UpdateRagEngineConfigOperation 164 GetRagEngineConfig(context.Context, *aiplatformpb.GetRagEngineConfigRequest, ...gax.CallOption) (*aiplatformpb.RagEngineConfig, error) 165 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 166 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 167 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 168 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 169 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 170 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 171 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 172 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 173 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 174 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 175 } 176 177 // VertexRagDataClient is a client for interacting with Vertex AI API. 178 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 179 // 180 // A service for managing user data for RAG. 181 type VertexRagDataClient struct { 182 // The internal transport-dependent client. 183 internalClient internalVertexRagDataClient 184 185 // The call options for this service. 186 CallOptions *VertexRagDataCallOptions 187 188 // LROClient is used internally to handle long-running operations. 189 // It is exposed so that its CallOptions can be modified if required. 190 // Users should not Close this client. 191 LROClient *lroauto.OperationsClient 192 } 193 194 // Wrapper methods routed to the internal client. 195 196 // Close closes the connection to the API service. The user should invoke this when 197 // the client is no longer required. 198 func (c *VertexRagDataClient) Close() error { 199 return c.internalClient.Close() 200 } 201 202 // setGoogleClientInfo sets the name and version of the application in 203 // the `x-goog-api-client` header passed on each request. Intended for 204 // use by Google-written clients. 205 func (c *VertexRagDataClient) setGoogleClientInfo(keyval ...string) { 206 c.internalClient.setGoogleClientInfo(keyval...) 207 } 208 209 // Connection returns a connection to the API service. 210 // 211 // Deprecated: Connections are now pooled so this method does not always 212 // return the same resource. 213 func (c *VertexRagDataClient) Connection() *grpc.ClientConn { 214 return c.internalClient.Connection() 215 } 216 217 // CreateRagCorpus creates a RagCorpus. 218 func (c *VertexRagDataClient) CreateRagCorpus(ctx context.Context, req *aiplatformpb.CreateRagCorpusRequest, opts ...gax.CallOption) (*CreateRagCorpusOperation, error) { 219 return c.internalClient.CreateRagCorpus(ctx, req, opts...) 220 } 221 222 // CreateRagCorpusOperation returns a new CreateRagCorpusOperation from a given name. 223 // The name must be that of a previously created CreateRagCorpusOperation, possibly from a different process. 224 func (c *VertexRagDataClient) CreateRagCorpusOperation(name string) *CreateRagCorpusOperation { 225 return c.internalClient.CreateRagCorpusOperation(name) 226 } 227 228 // UpdateRagCorpus updates a RagCorpus. 229 func (c *VertexRagDataClient) UpdateRagCorpus(ctx context.Context, req *aiplatformpb.UpdateRagCorpusRequest, opts ...gax.CallOption) (*UpdateRagCorpusOperation, error) { 230 return c.internalClient.UpdateRagCorpus(ctx, req, opts...) 231 } 232 233 // UpdateRagCorpusOperation returns a new UpdateRagCorpusOperation from a given name. 234 // The name must be that of a previously created UpdateRagCorpusOperation, possibly from a different process. 235 func (c *VertexRagDataClient) UpdateRagCorpusOperation(name string) *UpdateRagCorpusOperation { 236 return c.internalClient.UpdateRagCorpusOperation(name) 237 } 238 239 // GetRagCorpus gets a RagCorpus. 240 func (c *VertexRagDataClient) GetRagCorpus(ctx context.Context, req *aiplatformpb.GetRagCorpusRequest, opts ...gax.CallOption) (*aiplatformpb.RagCorpus, error) { 241 return c.internalClient.GetRagCorpus(ctx, req, opts...) 242 } 243 244 // ListRagCorpora lists RagCorpora in a Location. 245 func (c *VertexRagDataClient) ListRagCorpora(ctx context.Context, req *aiplatformpb.ListRagCorporaRequest, opts ...gax.CallOption) *RagCorpusIterator { 246 return c.internalClient.ListRagCorpora(ctx, req, opts...) 247 } 248 249 // DeleteRagCorpus deletes a RagCorpus. 250 func (c *VertexRagDataClient) DeleteRagCorpus(ctx context.Context, req *aiplatformpb.DeleteRagCorpusRequest, opts ...gax.CallOption) (*DeleteRagCorpusOperation, error) { 251 return c.internalClient.DeleteRagCorpus(ctx, req, opts...) 252 } 253 254 // DeleteRagCorpusOperation returns a new DeleteRagCorpusOperation from a given name. 255 // The name must be that of a previously created DeleteRagCorpusOperation, possibly from a different process. 256 func (c *VertexRagDataClient) DeleteRagCorpusOperation(name string) *DeleteRagCorpusOperation { 257 return c.internalClient.DeleteRagCorpusOperation(name) 258 } 259 260 // UploadRagFile upload a file into a RagCorpus. 261 func (c *VertexRagDataClient) UploadRagFile(ctx context.Context, req *aiplatformpb.UploadRagFileRequest, opts ...gax.CallOption) (*aiplatformpb.UploadRagFileResponse, error) { 262 return c.internalClient.UploadRagFile(ctx, req, opts...) 263 } 264 265 // ImportRagFiles import files from Google Cloud Storage or Google Drive into a RagCorpus. 266 func (c *VertexRagDataClient) ImportRagFiles(ctx context.Context, req *aiplatformpb.ImportRagFilesRequest, opts ...gax.CallOption) (*ImportRagFilesOperation, error) { 267 return c.internalClient.ImportRagFiles(ctx, req, opts...) 268 } 269 270 // ImportRagFilesOperation returns a new ImportRagFilesOperation from a given name. 271 // The name must be that of a previously created ImportRagFilesOperation, possibly from a different process. 272 func (c *VertexRagDataClient) ImportRagFilesOperation(name string) *ImportRagFilesOperation { 273 return c.internalClient.ImportRagFilesOperation(name) 274 } 275 276 // GetRagFile gets a RagFile. 277 func (c *VertexRagDataClient) GetRagFile(ctx context.Context, req *aiplatformpb.GetRagFileRequest, opts ...gax.CallOption) (*aiplatformpb.RagFile, error) { 278 return c.internalClient.GetRagFile(ctx, req, opts...) 279 } 280 281 // ListRagFiles lists RagFiles in a RagCorpus. 282 func (c *VertexRagDataClient) ListRagFiles(ctx context.Context, req *aiplatformpb.ListRagFilesRequest, opts ...gax.CallOption) *RagFileIterator { 283 return c.internalClient.ListRagFiles(ctx, req, opts...) 284 } 285 286 // DeleteRagFile deletes a RagFile. 287 func (c *VertexRagDataClient) DeleteRagFile(ctx context.Context, req *aiplatformpb.DeleteRagFileRequest, opts ...gax.CallOption) (*DeleteRagFileOperation, error) { 288 return c.internalClient.DeleteRagFile(ctx, req, opts...) 289 } 290 291 // DeleteRagFileOperation returns a new DeleteRagFileOperation from a given name. 292 // The name must be that of a previously created DeleteRagFileOperation, possibly from a different process. 293 func (c *VertexRagDataClient) DeleteRagFileOperation(name string) *DeleteRagFileOperation { 294 return c.internalClient.DeleteRagFileOperation(name) 295 } 296 297 // UpdateRagEngineConfig updates a RagEngineConfig. 298 func (c *VertexRagDataClient) UpdateRagEngineConfig(ctx context.Context, req *aiplatformpb.UpdateRagEngineConfigRequest, opts ...gax.CallOption) (*UpdateRagEngineConfigOperation, error) { 299 return c.internalClient.UpdateRagEngineConfig(ctx, req, opts...) 300 } 301 302 // UpdateRagEngineConfigOperation returns a new UpdateRagEngineConfigOperation from a given name. 303 // The name must be that of a previously created UpdateRagEngineConfigOperation, possibly from a different process. 304 func (c *VertexRagDataClient) UpdateRagEngineConfigOperation(name string) *UpdateRagEngineConfigOperation { 305 return c.internalClient.UpdateRagEngineConfigOperation(name) 306 } 307 308 // GetRagEngineConfig gets a RagEngineConfig. 309 func (c *VertexRagDataClient) GetRagEngineConfig(ctx context.Context, req *aiplatformpb.GetRagEngineConfigRequest, opts ...gax.CallOption) (*aiplatformpb.RagEngineConfig, error) { 310 return c.internalClient.GetRagEngineConfig(ctx, req, opts...) 311 } 312 313 // GetLocation gets information about a location. 314 func (c *VertexRagDataClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 315 return c.internalClient.GetLocation(ctx, req, opts...) 316 } 317 318 // ListLocations lists information about the supported locations for this service. 319 func (c *VertexRagDataClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 320 return c.internalClient.ListLocations(ctx, req, opts...) 321 } 322 323 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 324 // if the resource exists and does not have a policy set. 325 func (c *VertexRagDataClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 326 return c.internalClient.GetIamPolicy(ctx, req, opts...) 327 } 328 329 // SetIamPolicy sets the access control policy on the specified resource. Replaces 330 // any existing policy. 331 // 332 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 333 // errors. 334 func (c *VertexRagDataClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 335 return c.internalClient.SetIamPolicy(ctx, req, opts...) 336 } 337 338 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 339 // resource does not exist, this will return an empty set of 340 // permissions, not a NOT_FOUND error. 341 // 342 // Note: This operation is designed to be used for building 343 // permission-aware UIs and command-line tools, not for authorization 344 // checking. This operation may “fail open” without warning. 345 func (c *VertexRagDataClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 346 return c.internalClient.TestIamPermissions(ctx, req, opts...) 347 } 348 349 // CancelOperation is a utility method from google.longrunning.Operations. 350 func (c *VertexRagDataClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 351 return c.internalClient.CancelOperation(ctx, req, opts...) 352 } 353 354 // DeleteOperation is a utility method from google.longrunning.Operations. 355 func (c *VertexRagDataClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 356 return c.internalClient.DeleteOperation(ctx, req, opts...) 357 } 358 359 // GetOperation is a utility method from google.longrunning.Operations. 360 func (c *VertexRagDataClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 361 return c.internalClient.GetOperation(ctx, req, opts...) 362 } 363 364 // ListOperations is a utility method from google.longrunning.Operations. 365 func (c *VertexRagDataClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 366 return c.internalClient.ListOperations(ctx, req, opts...) 367 } 368 369 // WaitOperation is a utility method from google.longrunning.Operations. 370 func (c *VertexRagDataClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 371 return c.internalClient.WaitOperation(ctx, req, opts...) 372 } 373 374 // vertexRagDataGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 375 // 376 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 377 type vertexRagDataGRPCClient struct { 378 // Connection pool of gRPC connections to the service. 379 connPool gtransport.ConnPool 380 381 // Points back to the CallOptions field of the containing VertexRagDataClient 382 CallOptions **VertexRagDataCallOptions 383 384 // The gRPC API client. 385 vertexRagDataClient aiplatformpb.VertexRagDataServiceClient 386 387 // LROClient is used internally to handle long-running operations. 388 // It is exposed so that its CallOptions can be modified if required. 389 // Users should not Close this client. 390 LROClient **lroauto.OperationsClient 391 392 operationsClient longrunningpb.OperationsClient 393 394 iamPolicyClient iampb.IAMPolicyClient 395 396 locationsClient locationpb.LocationsClient 397 398 // The x-goog-* metadata to be sent with each request. 399 xGoogHeaders []string 400 401 logger *slog.Logger 402 } 403 404 // NewVertexRagDataClient creates a new vertex rag data service client based on gRPC. 405 // The returned client must be Closed when it is done being used to clean up its underlying connections. 406 // 407 // A service for managing user data for RAG. 408 func NewVertexRagDataClient(ctx context.Context, opts ...option.ClientOption) (*VertexRagDataClient, error) { 409 clientOpts := defaultVertexRagDataGRPCClientOptions() 410 if newVertexRagDataClientHook != nil { 411 hookOpts, err := newVertexRagDataClientHook(ctx, clientHookParams{}) 412 if err != nil { 413 return nil, err 414 } 415 clientOpts = append(clientOpts, hookOpts...) 416 } 417 418 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 419 if err != nil { 420 return nil, err 421 } 422 client := VertexRagDataClient{CallOptions: defaultVertexRagDataCallOptions()} 423 424 c := &vertexRagDataGRPCClient{ 425 connPool: connPool, 426 vertexRagDataClient: aiplatformpb.NewVertexRagDataServiceClient(connPool), 427 CallOptions: &client.CallOptions, 428 logger: internaloption.GetLogger(opts), 429 operationsClient: longrunningpb.NewOperationsClient(connPool), 430 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 431 locationsClient: locationpb.NewLocationsClient(connPool), 432 } 433 c.setGoogleClientInfo() 434 435 client.internalClient = c 436 437 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 438 if err != nil { 439 // This error "should not happen", since we are just reusing old connection pool 440 // and never actually need to dial. 441 // If this does happen, we could leak connp. However, we cannot close conn: 442 // If the user invoked the constructor with option.WithGRPCConn, 443 // we would close a connection that's still in use. 444 // TODO: investigate error conditions. 445 return nil, err 446 } 447 c.LROClient = &client.LROClient 448 return &client, nil 449 } 450 451 // Connection returns a connection to the API service. 452 // 453 // Deprecated: Connections are now pooled so this method does not always 454 // return the same resource. 455 func (c *vertexRagDataGRPCClient) Connection() *grpc.ClientConn { 456 return c.connPool.Conn() 457 } 458 459 // setGoogleClientInfo sets the name and version of the application in 460 // the `x-goog-api-client` header passed on each request. Intended for 461 // use by Google-written clients. 462 func (c *vertexRagDataGRPCClient) setGoogleClientInfo(keyval ...string) { 463 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 464 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 465 c.xGoogHeaders = []string{ 466 "x-goog-api-client", gax.XGoogHeader(kv...), 467 } 468 } 469 470 // Close closes the connection to the API service. The user should invoke this when 471 // the client is no longer required. 472 func (c *vertexRagDataGRPCClient) Close() error { 473 return c.connPool.Close() 474 } 475 476 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 477 type vertexRagDataRESTClient struct { 478 // The http endpoint to connect to. 479 endpoint string 480 481 // The http client. 482 httpClient *http.Client 483 484 // LROClient is used internally to handle long-running operations. 485 // It is exposed so that its CallOptions can be modified if required. 486 // Users should not Close this client. 487 LROClient **lroauto.OperationsClient 488 489 // The x-goog-* headers to be sent with each request. 490 xGoogHeaders []string 491 492 // Points back to the CallOptions field of the containing VertexRagDataClient 493 CallOptions **VertexRagDataCallOptions 494 495 logger *slog.Logger 496 } 497 498 // NewVertexRagDataRESTClient creates a new vertex rag data service rest client. 499 // 500 // A service for managing user data for RAG. 501 func NewVertexRagDataRESTClient(ctx context.Context, opts ...option.ClientOption) (*VertexRagDataClient, error) { 502 clientOpts := append(defaultVertexRagDataRESTClientOptions(), opts...) 503 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) 504 if err != nil { 505 return nil, err 506 } 507 508 callOpts := defaultVertexRagDataRESTCallOptions() 509 c := &vertexRagDataRESTClient{ 510 endpoint: endpoint, 511 httpClient: httpClient, 512 CallOptions: &callOpts, 513 logger: internaloption.GetLogger(opts), 514 } 515 c.setGoogleClientInfo() 516 517 lroOpts := []option.ClientOption{ 518 option.WithHTTPClient(httpClient), 519 option.WithEndpoint(endpoint), 520 } 521 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...) 522 if err != nil { 523 return nil, err 524 } 525 c.LROClient = &opClient 526 527 return &VertexRagDataClient{internalClient: c, CallOptions: callOpts}, nil 528 } 529 530 func defaultVertexRagDataRESTClientOptions() []option.ClientOption { 531 return []option.ClientOption{ 532 internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"), 533 internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"), 534 internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"), 535 internaloption.WithDefaultUniverseDomain("googleapis.com"), 536 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 537 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 538 internaloption.EnableNewAuthLibrary(), 539 } 540 } 541 542 // setGoogleClientInfo sets the name and version of the application in 543 // the `x-goog-api-client` header passed on each request. Intended for 544 // use by Google-written clients. 545 func (c *vertexRagDataRESTClient) setGoogleClientInfo(keyval ...string) { 546 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 547 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) 548 c.xGoogHeaders = []string{ 549 "x-goog-api-client", gax.XGoogHeader(kv...), 550 } 551 } 552 553 // Close closes the connection to the API service. The user should invoke this when 554 // the client is no longer required. 555 func (c *vertexRagDataRESTClient) Close() error { 556 // Replace httpClient with nil to force cleanup. 557 c.httpClient = nil 558 return nil 559 } 560 561 // Connection returns a connection to the API service. 562 // 563 // Deprecated: This method always returns nil. 564 func (c *vertexRagDataRESTClient) Connection() *grpc.ClientConn { 565 return nil 566 } 567 func (c *vertexRagDataGRPCClient) CreateRagCorpus(ctx context.Context, req *aiplatformpb.CreateRagCorpusRequest, opts ...gax.CallOption) (*CreateRagCorpusOperation, error) { 568 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 569 570 hds = append(c.xGoogHeaders, hds...) 571 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 572 opts = append((*c.CallOptions).CreateRagCorpus[0:len((*c.CallOptions).CreateRagCorpus):len((*c.CallOptions).CreateRagCorpus)], opts...) 573 var resp *longrunningpb.Operation 574 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 575 var err error 576 resp, err = executeRPC(ctx, c.vertexRagDataClient.CreateRagCorpus, req, settings.GRPC, c.logger, "CreateRagCorpus") 577 return err 578 }, opts...) 579 if err != nil { 580 return nil, err 581 } 582 return &CreateRagCorpusOperation{ 583 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 584 }, nil 585 } 586 587 func (c *vertexRagDataGRPCClient) UpdateRagCorpus(ctx context.Context, req *aiplatformpb.UpdateRagCorpusRequest, opts ...gax.CallOption) (*UpdateRagCorpusOperation, error) { 588 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "rag_corpus.name", url.QueryEscape(req.GetRagCorpus().GetName()))} 589 590 hds = append(c.xGoogHeaders, hds...) 591 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 592 opts = append((*c.CallOptions).UpdateRagCorpus[0:len((*c.CallOptions).UpdateRagCorpus):len((*c.CallOptions).UpdateRagCorpus)], opts...) 593 var resp *longrunningpb.Operation 594 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 595 var err error 596 resp, err = executeRPC(ctx, c.vertexRagDataClient.UpdateRagCorpus, req, settings.GRPC, c.logger, "UpdateRagCorpus") 597 return err 598 }, opts...) 599 if err != nil { 600 return nil, err 601 } 602 return &UpdateRagCorpusOperation{ 603 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 604 }, nil 605 } 606 607 func (c *vertexRagDataGRPCClient) GetRagCorpus(ctx context.Context, req *aiplatformpb.GetRagCorpusRequest, opts ...gax.CallOption) (*aiplatformpb.RagCorpus, error) { 608 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 609 610 hds = append(c.xGoogHeaders, hds...) 611 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 612 opts = append((*c.CallOptions).GetRagCorpus[0:len((*c.CallOptions).GetRagCorpus):len((*c.CallOptions).GetRagCorpus)], opts...) 613 var resp *aiplatformpb.RagCorpus 614 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 615 var err error 616 resp, err = executeRPC(ctx, c.vertexRagDataClient.GetRagCorpus, req, settings.GRPC, c.logger, "GetRagCorpus") 617 return err 618 }, opts...) 619 if err != nil { 620 return nil, err 621 } 622 return resp, nil 623 } 624 625 func (c *vertexRagDataGRPCClient) ListRagCorpora(ctx context.Context, req *aiplatformpb.ListRagCorporaRequest, opts ...gax.CallOption) *RagCorpusIterator { 626 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 627 628 hds = append(c.xGoogHeaders, hds...) 629 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 630 opts = append((*c.CallOptions).ListRagCorpora[0:len((*c.CallOptions).ListRagCorpora):len((*c.CallOptions).ListRagCorpora)], opts...) 631 it := &RagCorpusIterator{} 632 req = proto.Clone(req).(*aiplatformpb.ListRagCorporaRequest) 633 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.RagCorpus, string, error) { 634 resp := &aiplatformpb.ListRagCorporaResponse{} 635 if pageToken != "" { 636 req.PageToken = pageToken 637 } 638 if pageSize > math.MaxInt32 { 639 req.PageSize = math.MaxInt32 640 } else if pageSize != 0 { 641 req.PageSize = int32(pageSize) 642 } 643 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 644 var err error 645 resp, err = executeRPC(ctx, c.vertexRagDataClient.ListRagCorpora, req, settings.GRPC, c.logger, "ListRagCorpora") 646 return err 647 }, opts...) 648 if err != nil { 649 return nil, "", err 650 } 651 652 it.Response = resp 653 return resp.GetRagCorpora(), resp.GetNextPageToken(), nil 654 } 655 fetch := func(pageSize int, pageToken string) (string, error) { 656 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 657 if err != nil { 658 return "", err 659 } 660 it.items = append(it.items, items...) 661 return nextPageToken, nil 662 } 663 664 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 665 it.pageInfo.MaxSize = int(req.GetPageSize()) 666 it.pageInfo.Token = req.GetPageToken() 667 668 return it 669 } 670 671 func (c *vertexRagDataGRPCClient) DeleteRagCorpus(ctx context.Context, req *aiplatformpb.DeleteRagCorpusRequest, opts ...gax.CallOption) (*DeleteRagCorpusOperation, error) { 672 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 673 674 hds = append(c.xGoogHeaders, hds...) 675 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 676 opts = append((*c.CallOptions).DeleteRagCorpus[0:len((*c.CallOptions).DeleteRagCorpus):len((*c.CallOptions).DeleteRagCorpus)], opts...) 677 var resp *longrunningpb.Operation 678 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 679 var err error 680 resp, err = executeRPC(ctx, c.vertexRagDataClient.DeleteRagCorpus, req, settings.GRPC, c.logger, "DeleteRagCorpus") 681 return err 682 }, opts...) 683 if err != nil { 684 return nil, err 685 } 686 return &DeleteRagCorpusOperation{ 687 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 688 }, nil 689 } 690 691 func (c *vertexRagDataGRPCClient) UploadRagFile(ctx context.Context, req *aiplatformpb.UploadRagFileRequest, opts ...gax.CallOption) (*aiplatformpb.UploadRagFileResponse, error) { 692 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 693 694 hds = append(c.xGoogHeaders, hds...) 695 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 696 opts = append((*c.CallOptions).UploadRagFile[0:len((*c.CallOptions).UploadRagFile):len((*c.CallOptions).UploadRagFile)], opts...) 697 var resp *aiplatformpb.UploadRagFileResponse 698 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 699 var err error 700 resp, err = executeRPC(ctx, c.vertexRagDataClient.UploadRagFile, req, settings.GRPC, c.logger, "UploadRagFile") 701 return err 702 }, opts...) 703 if err != nil { 704 return nil, err 705 } 706 return resp, nil 707 } 708 709 func (c *vertexRagDataGRPCClient) ImportRagFiles(ctx context.Context, req *aiplatformpb.ImportRagFilesRequest, opts ...gax.CallOption) (*ImportRagFilesOperation, error) { 710 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 711 712 hds = append(c.xGoogHeaders, hds...) 713 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 714 opts = append((*c.CallOptions).ImportRagFiles[0:len((*c.CallOptions).ImportRagFiles):len((*c.CallOptions).ImportRagFiles)], opts...) 715 var resp *longrunningpb.Operation 716 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 717 var err error 718 resp, err = executeRPC(ctx, c.vertexRagDataClient.ImportRagFiles, req, settings.GRPC, c.logger, "ImportRagFiles") 719 return err 720 }, opts...) 721 if err != nil { 722 return nil, err 723 } 724 return &ImportRagFilesOperation{ 725 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 726 }, nil 727 } 728 729 func (c *vertexRagDataGRPCClient) GetRagFile(ctx context.Context, req *aiplatformpb.GetRagFileRequest, opts ...gax.CallOption) (*aiplatformpb.RagFile, error) { 730 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 731 732 hds = append(c.xGoogHeaders, hds...) 733 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 734 opts = append((*c.CallOptions).GetRagFile[0:len((*c.CallOptions).GetRagFile):len((*c.CallOptions).GetRagFile)], opts...) 735 var resp *aiplatformpb.RagFile 736 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 737 var err error 738 resp, err = executeRPC(ctx, c.vertexRagDataClient.GetRagFile, req, settings.GRPC, c.logger, "GetRagFile") 739 return err 740 }, opts...) 741 if err != nil { 742 return nil, err 743 } 744 return resp, nil 745 } 746 747 func (c *vertexRagDataGRPCClient) ListRagFiles(ctx context.Context, req *aiplatformpb.ListRagFilesRequest, opts ...gax.CallOption) *RagFileIterator { 748 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 749 750 hds = append(c.xGoogHeaders, hds...) 751 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 752 opts = append((*c.CallOptions).ListRagFiles[0:len((*c.CallOptions).ListRagFiles):len((*c.CallOptions).ListRagFiles)], opts...) 753 it := &RagFileIterator{} 754 req = proto.Clone(req).(*aiplatformpb.ListRagFilesRequest) 755 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.RagFile, string, error) { 756 resp := &aiplatformpb.ListRagFilesResponse{} 757 if pageToken != "" { 758 req.PageToken = pageToken 759 } 760 if pageSize > math.MaxInt32 { 761 req.PageSize = math.MaxInt32 762 } else if pageSize != 0 { 763 req.PageSize = int32(pageSize) 764 } 765 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 766 var err error 767 resp, err = executeRPC(ctx, c.vertexRagDataClient.ListRagFiles, req, settings.GRPC, c.logger, "ListRagFiles") 768 return err 769 }, opts...) 770 if err != nil { 771 return nil, "", err 772 } 773 774 it.Response = resp 775 return resp.GetRagFiles(), resp.GetNextPageToken(), nil 776 } 777 fetch := func(pageSize int, pageToken string) (string, error) { 778 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 779 if err != nil { 780 return "", err 781 } 782 it.items = append(it.items, items...) 783 return nextPageToken, nil 784 } 785 786 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 787 it.pageInfo.MaxSize = int(req.GetPageSize()) 788 it.pageInfo.Token = req.GetPageToken() 789 790 return it 791 } 792 793 func (c *vertexRagDataGRPCClient) DeleteRagFile(ctx context.Context, req *aiplatformpb.DeleteRagFileRequest, opts ...gax.CallOption) (*DeleteRagFileOperation, error) { 794 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 795 796 hds = append(c.xGoogHeaders, hds...) 797 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 798 opts = append((*c.CallOptions).DeleteRagFile[0:len((*c.CallOptions).DeleteRagFile):len((*c.CallOptions).DeleteRagFile)], opts...) 799 var resp *longrunningpb.Operation 800 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 801 var err error 802 resp, err = executeRPC(ctx, c.vertexRagDataClient.DeleteRagFile, req, settings.GRPC, c.logger, "DeleteRagFile") 803 return err 804 }, opts...) 805 if err != nil { 806 return nil, err 807 } 808 return &DeleteRagFileOperation{ 809 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 810 }, nil 811 } 812 813 func (c *vertexRagDataGRPCClient) UpdateRagEngineConfig(ctx context.Context, req *aiplatformpb.UpdateRagEngineConfigRequest, opts ...gax.CallOption) (*UpdateRagEngineConfigOperation, error) { 814 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "rag_engine_config.name", url.QueryEscape(req.GetRagEngineConfig().GetName()))} 815 816 hds = append(c.xGoogHeaders, hds...) 817 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 818 opts = append((*c.CallOptions).UpdateRagEngineConfig[0:len((*c.CallOptions).UpdateRagEngineConfig):len((*c.CallOptions).UpdateRagEngineConfig)], opts...) 819 var resp *longrunningpb.Operation 820 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 821 var err error 822 resp, err = executeRPC(ctx, c.vertexRagDataClient.UpdateRagEngineConfig, req, settings.GRPC, c.logger, "UpdateRagEngineConfig") 823 return err 824 }, opts...) 825 if err != nil { 826 return nil, err 827 } 828 return &UpdateRagEngineConfigOperation{ 829 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 830 }, nil 831 } 832 833 func (c *vertexRagDataGRPCClient) GetRagEngineConfig(ctx context.Context, req *aiplatformpb.GetRagEngineConfigRequest, opts ...gax.CallOption) (*aiplatformpb.RagEngineConfig, error) { 834 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 835 836 hds = append(c.xGoogHeaders, hds...) 837 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 838 opts = append((*c.CallOptions).GetRagEngineConfig[0:len((*c.CallOptions).GetRagEngineConfig):len((*c.CallOptions).GetRagEngineConfig)], opts...) 839 var resp *aiplatformpb.RagEngineConfig 840 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 841 var err error 842 resp, err = executeRPC(ctx, c.vertexRagDataClient.GetRagEngineConfig, req, settings.GRPC, c.logger, "GetRagEngineConfig") 843 return err 844 }, opts...) 845 if err != nil { 846 return nil, err 847 } 848 return resp, nil 849 } 850 851 func (c *vertexRagDataGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 852 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 853 854 hds = append(c.xGoogHeaders, hds...) 855 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 856 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 857 var resp *locationpb.Location 858 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 859 var err error 860 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 861 return err 862 }, opts...) 863 if err != nil { 864 return nil, err 865 } 866 return resp, nil 867 } 868 869 func (c *vertexRagDataGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 870 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 871 872 hds = append(c.xGoogHeaders, hds...) 873 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 874 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 875 it := &LocationIterator{} 876 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 877 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 878 resp := &locationpb.ListLocationsResponse{} 879 if pageToken != "" { 880 req.PageToken = pageToken 881 } 882 if pageSize > math.MaxInt32 { 883 req.PageSize = math.MaxInt32 884 } else if pageSize != 0 { 885 req.PageSize = int32(pageSize) 886 } 887 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 888 var err error 889 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 890 return err 891 }, opts...) 892 if err != nil { 893 return nil, "", err 894 } 895 896 it.Response = resp 897 return resp.GetLocations(), resp.GetNextPageToken(), nil 898 } 899 fetch := func(pageSize int, pageToken string) (string, error) { 900 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 901 if err != nil { 902 return "", err 903 } 904 it.items = append(it.items, items...) 905 return nextPageToken, nil 906 } 907 908 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 909 it.pageInfo.MaxSize = int(req.GetPageSize()) 910 it.pageInfo.Token = req.GetPageToken() 911 912 return it 913 } 914 915 func (c *vertexRagDataGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 916 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 917 918 hds = append(c.xGoogHeaders, hds...) 919 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 920 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 921 var resp *iampb.Policy 922 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 923 var err error 924 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 925 return err 926 }, opts...) 927 if err != nil { 928 return nil, err 929 } 930 return resp, nil 931 } 932 933 func (c *vertexRagDataGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 934 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 935 936 hds = append(c.xGoogHeaders, hds...) 937 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 938 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 939 var resp *iampb.Policy 940 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 941 var err error 942 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 943 return err 944 }, opts...) 945 if err != nil { 946 return nil, err 947 } 948 return resp, nil 949 } 950 951 func (c *vertexRagDataGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 952 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 953 954 hds = append(c.xGoogHeaders, hds...) 955 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 956 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 957 var resp *iampb.TestIamPermissionsResponse 958 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 959 var err error 960 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 961 return err 962 }, opts...) 963 if err != nil { 964 return nil, err 965 } 966 return resp, nil 967 } 968 969 func (c *vertexRagDataGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 970 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 971 972 hds = append(c.xGoogHeaders, hds...) 973 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 974 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 975 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 976 var err error 977 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 978 return err 979 }, opts...) 980 return err 981 } 982 983 func (c *vertexRagDataGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 984 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 985 986 hds = append(c.xGoogHeaders, hds...) 987 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 988 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 989 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 990 var err error 991 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 992 return err 993 }, opts...) 994 return err 995 } 996 997 func (c *vertexRagDataGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 998 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 999 1000 hds = append(c.xGoogHeaders, hds...) 1001 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 1002 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 1003 var resp *longrunningpb.Operation 1004 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1005 var err error 1006 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 1007 return err 1008 }, opts...) 1009 if err != nil { 1010 return nil, err 1011 } 1012 return resp, nil 1013 } 1014 1015 func (c *vertexRagDataGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 1016 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1017 1018 hds = append(c.xGoogHeaders, hds...) 1019 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 1020 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 1021 it := &OperationIterator{} 1022 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 1023 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 1024 resp := &longrunningpb.ListOperationsResponse{} 1025 if pageToken != "" { 1026 req.PageToken = pageToken 1027 } 1028 if pageSize > math.MaxInt32 { 1029 req.PageSize = math.MaxInt32 1030 } else if pageSize != 0 { 1031 req.PageSize = int32(pageSize) 1032 } 1033 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1034 var err error 1035 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 1036 return err 1037 }, opts...) 1038 if err != nil { 1039 return nil, "", err 1040 } 1041 1042 it.Response = resp 1043 return resp.GetOperations(), resp.GetNextPageToken(), nil 1044 } 1045 fetch := func(pageSize int, pageToken string) (string, error) { 1046 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1047 if err != nil { 1048 return "", err 1049 } 1050 it.items = append(it.items, items...) 1051 return nextPageToken, nil 1052 } 1053 1054 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1055 it.pageInfo.MaxSize = int(req.GetPageSize()) 1056 it.pageInfo.Token = req.GetPageToken() 1057 1058 return it 1059 } 1060 1061 func (c *vertexRagDataGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1062 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1063 1064 hds = append(c.xGoogHeaders, hds...) 1065 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 1066 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 1067 var resp *longrunningpb.Operation 1068 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1069 var err error 1070 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 1071 return err 1072 }, opts...) 1073 if err != nil { 1074 return nil, err 1075 } 1076 return resp, nil 1077 } 1078 1079 // CreateRagCorpus creates a RagCorpus. 1080 func (c *vertexRagDataRESTClient) CreateRagCorpus(ctx context.Context, req *aiplatformpb.CreateRagCorpusRequest, opts ...gax.CallOption) (*CreateRagCorpusOperation, error) { 1081 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1082 body := req.GetRagCorpus() 1083 jsonReq, err := m.Marshal(body) 1084 if err != nil { 1085 return nil, err 1086 } 1087 1088 baseUrl, err := url.Parse(c.endpoint) 1089 if err != nil { 1090 return nil, err 1091 } 1092 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/ragCorpora", req.GetParent()) 1093 1094 params := url.Values{} 1095 params.Add("$alt", "json;enum-encoding=int") 1096 1097 baseUrl.RawQuery = params.Encode() 1098 1099 // Build HTTP headers from client and context metadata. 1100 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 1101 1102 hds = append(c.xGoogHeaders, hds...) 1103 hds = append(hds, "Content-Type", "application/json") 1104 headers := gax.BuildHeaders(ctx, hds...) 1105 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1106 resp := &longrunningpb.Operation{} 1107 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1108 if settings.Path != "" { 1109 baseUrl.Path = settings.Path 1110 } 1111 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1112 if err != nil { 1113 return err 1114 } 1115 httpReq = httpReq.WithContext(ctx) 1116 httpReq.Header = headers 1117 1118 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateRagCorpus") 1119 if err != nil { 1120 return err 1121 } 1122 if err := unm.Unmarshal(buf, resp); err != nil { 1123 return err 1124 } 1125 1126 return nil 1127 }, opts...) 1128 if e != nil { 1129 return nil, e 1130 } 1131 1132 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1133 return &CreateRagCorpusOperation{ 1134 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1135 pollPath: override, 1136 }, nil 1137 } 1138 1139 // UpdateRagCorpus updates a RagCorpus. 1140 func (c *vertexRagDataRESTClient) UpdateRagCorpus(ctx context.Context, req *aiplatformpb.UpdateRagCorpusRequest, opts ...gax.CallOption) (*UpdateRagCorpusOperation, error) { 1141 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1142 body := req.GetRagCorpus() 1143 jsonReq, err := m.Marshal(body) 1144 if err != nil { 1145 return nil, err 1146 } 1147 1148 baseUrl, err := url.Parse(c.endpoint) 1149 if err != nil { 1150 return nil, err 1151 } 1152 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetRagCorpus().GetName()) 1153 1154 params := url.Values{} 1155 params.Add("$alt", "json;enum-encoding=int") 1156 1157 baseUrl.RawQuery = params.Encode() 1158 1159 // Build HTTP headers from client and context metadata. 1160 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "rag_corpus.name", url.QueryEscape(req.GetRagCorpus().GetName()))} 1161 1162 hds = append(c.xGoogHeaders, hds...) 1163 hds = append(hds, "Content-Type", "application/json") 1164 headers := gax.BuildHeaders(ctx, hds...) 1165 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1166 resp := &longrunningpb.Operation{} 1167 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1168 if settings.Path != "" { 1169 baseUrl.Path = settings.Path 1170 } 1171 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) 1172 if err != nil { 1173 return err 1174 } 1175 httpReq = httpReq.WithContext(ctx) 1176 httpReq.Header = headers 1177 1178 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateRagCorpus") 1179 if err != nil { 1180 return err 1181 } 1182 if err := unm.Unmarshal(buf, resp); err != nil { 1183 return err 1184 } 1185 1186 return nil 1187 }, opts...) 1188 if e != nil { 1189 return nil, e 1190 } 1191 1192 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1193 return &UpdateRagCorpusOperation{ 1194 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1195 pollPath: override, 1196 }, nil 1197 } 1198 1199 // GetRagCorpus gets a RagCorpus. 1200 func (c *vertexRagDataRESTClient) GetRagCorpus(ctx context.Context, req *aiplatformpb.GetRagCorpusRequest, opts ...gax.CallOption) (*aiplatformpb.RagCorpus, error) { 1201 baseUrl, err := url.Parse(c.endpoint) 1202 if err != nil { 1203 return nil, err 1204 } 1205 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1206 1207 params := url.Values{} 1208 params.Add("$alt", "json;enum-encoding=int") 1209 1210 baseUrl.RawQuery = params.Encode() 1211 1212 // Build HTTP headers from client and context metadata. 1213 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1214 1215 hds = append(c.xGoogHeaders, hds...) 1216 hds = append(hds, "Content-Type", "application/json") 1217 headers := gax.BuildHeaders(ctx, hds...) 1218 opts = append((*c.CallOptions).GetRagCorpus[0:len((*c.CallOptions).GetRagCorpus):len((*c.CallOptions).GetRagCorpus)], opts...) 1219 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1220 resp := &aiplatformpb.RagCorpus{} 1221 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1222 if settings.Path != "" { 1223 baseUrl.Path = settings.Path 1224 } 1225 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1226 if err != nil { 1227 return err 1228 } 1229 httpReq = httpReq.WithContext(ctx) 1230 httpReq.Header = headers 1231 1232 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetRagCorpus") 1233 if err != nil { 1234 return err 1235 } 1236 1237 if err := unm.Unmarshal(buf, resp); err != nil { 1238 return err 1239 } 1240 1241 return nil 1242 }, opts...) 1243 if e != nil { 1244 return nil, e 1245 } 1246 return resp, nil 1247 } 1248 1249 // ListRagCorpora lists RagCorpora in a Location. 1250 func (c *vertexRagDataRESTClient) ListRagCorpora(ctx context.Context, req *aiplatformpb.ListRagCorporaRequest, opts ...gax.CallOption) *RagCorpusIterator { 1251 it := &RagCorpusIterator{} 1252 req = proto.Clone(req).(*aiplatformpb.ListRagCorporaRequest) 1253 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1254 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.RagCorpus, string, error) { 1255 resp := &aiplatformpb.ListRagCorporaResponse{} 1256 if pageToken != "" { 1257 req.PageToken = pageToken 1258 } 1259 if pageSize > math.MaxInt32 { 1260 req.PageSize = math.MaxInt32 1261 } else if pageSize != 0 { 1262 req.PageSize = int32(pageSize) 1263 } 1264 baseUrl, err := url.Parse(c.endpoint) 1265 if err != nil { 1266 return nil, "", err 1267 } 1268 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/ragCorpora", req.GetParent()) 1269 1270 params := url.Values{} 1271 params.Add("$alt", "json;enum-encoding=int") 1272 if req.GetPageSize() != 0 { 1273 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1274 } 1275 if req.GetPageToken() != "" { 1276 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1277 } 1278 1279 baseUrl.RawQuery = params.Encode() 1280 1281 // Build HTTP headers from client and context metadata. 1282 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1283 headers := gax.BuildHeaders(ctx, hds...) 1284 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1285 if settings.Path != "" { 1286 baseUrl.Path = settings.Path 1287 } 1288 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1289 if err != nil { 1290 return err 1291 } 1292 httpReq.Header = headers 1293 1294 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListRagCorpora") 1295 if err != nil { 1296 return err 1297 } 1298 if err := unm.Unmarshal(buf, resp); err != nil { 1299 return err 1300 } 1301 1302 return nil 1303 }, opts...) 1304 if e != nil { 1305 return nil, "", e 1306 } 1307 it.Response = resp 1308 return resp.GetRagCorpora(), resp.GetNextPageToken(), nil 1309 } 1310 1311 fetch := func(pageSize int, pageToken string) (string, error) { 1312 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1313 if err != nil { 1314 return "", err 1315 } 1316 it.items = append(it.items, items...) 1317 return nextPageToken, nil 1318 } 1319 1320 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1321 it.pageInfo.MaxSize = int(req.GetPageSize()) 1322 it.pageInfo.Token = req.GetPageToken() 1323 1324 return it 1325 } 1326 1327 // DeleteRagCorpus deletes a RagCorpus. 1328 func (c *vertexRagDataRESTClient) DeleteRagCorpus(ctx context.Context, req *aiplatformpb.DeleteRagCorpusRequest, opts ...gax.CallOption) (*DeleteRagCorpusOperation, error) { 1329 baseUrl, err := url.Parse(c.endpoint) 1330 if err != nil { 1331 return nil, err 1332 } 1333 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1334 1335 params := url.Values{} 1336 params.Add("$alt", "json;enum-encoding=int") 1337 if req.GetForce() { 1338 params.Add("force", fmt.Sprintf("%v", req.GetForce())) 1339 } 1340 1341 baseUrl.RawQuery = params.Encode() 1342 1343 // Build HTTP headers from client and context metadata. 1344 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1345 1346 hds = append(c.xGoogHeaders, hds...) 1347 hds = append(hds, "Content-Type", "application/json") 1348 headers := gax.BuildHeaders(ctx, hds...) 1349 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1350 resp := &longrunningpb.Operation{} 1351 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1352 if settings.Path != "" { 1353 baseUrl.Path = settings.Path 1354 } 1355 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1356 if err != nil { 1357 return err 1358 } 1359 httpReq = httpReq.WithContext(ctx) 1360 httpReq.Header = headers 1361 1362 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteRagCorpus") 1363 if err != nil { 1364 return err 1365 } 1366 if err := unm.Unmarshal(buf, resp); err != nil { 1367 return err 1368 } 1369 1370 return nil 1371 }, opts...) 1372 if e != nil { 1373 return nil, e 1374 } 1375 1376 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1377 return &DeleteRagCorpusOperation{ 1378 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1379 pollPath: override, 1380 }, nil 1381 } 1382 1383 // UploadRagFile upload a file into a RagCorpus. 1384 func (c *vertexRagDataRESTClient) UploadRagFile(ctx context.Context, req *aiplatformpb.UploadRagFileRequest, opts ...gax.CallOption) (*aiplatformpb.UploadRagFileResponse, error) { 1385 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1386 jsonReq, err := m.Marshal(req) 1387 if err != nil { 1388 return nil, err 1389 } 1390 1391 baseUrl, err := url.Parse(c.endpoint) 1392 if err != nil { 1393 return nil, err 1394 } 1395 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/ragFiles:upload", req.GetParent()) 1396 1397 params := url.Values{} 1398 params.Add("$alt", "json;enum-encoding=int") 1399 1400 baseUrl.RawQuery = params.Encode() 1401 1402 // Build HTTP headers from client and context metadata. 1403 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 1404 1405 hds = append(c.xGoogHeaders, hds...) 1406 hds = append(hds, "Content-Type", "application/json") 1407 headers := gax.BuildHeaders(ctx, hds...) 1408 opts = append((*c.CallOptions).UploadRagFile[0:len((*c.CallOptions).UploadRagFile):len((*c.CallOptions).UploadRagFile)], opts...) 1409 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1410 resp := &aiplatformpb.UploadRagFileResponse{} 1411 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1412 if settings.Path != "" { 1413 baseUrl.Path = settings.Path 1414 } 1415 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1416 if err != nil { 1417 return err 1418 } 1419 httpReq = httpReq.WithContext(ctx) 1420 httpReq.Header = headers 1421 1422 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UploadRagFile") 1423 if err != nil { 1424 return err 1425 } 1426 1427 if err := unm.Unmarshal(buf, resp); err != nil { 1428 return err 1429 } 1430 1431 return nil 1432 }, opts...) 1433 if e != nil { 1434 return nil, e 1435 } 1436 return resp, nil 1437 } 1438 1439 // ImportRagFiles import files from Google Cloud Storage or Google Drive into a RagCorpus. 1440 func (c *vertexRagDataRESTClient) ImportRagFiles(ctx context.Context, req *aiplatformpb.ImportRagFilesRequest, opts ...gax.CallOption) (*ImportRagFilesOperation, error) { 1441 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1442 jsonReq, err := m.Marshal(req) 1443 if err != nil { 1444 return nil, err 1445 } 1446 1447 baseUrl, err := url.Parse(c.endpoint) 1448 if err != nil { 1449 return nil, err 1450 } 1451 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/ragFiles:import", req.GetParent()) 1452 1453 params := url.Values{} 1454 params.Add("$alt", "json;enum-encoding=int") 1455 1456 baseUrl.RawQuery = params.Encode() 1457 1458 // Build HTTP headers from client and context metadata. 1459 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 1460 1461 hds = append(c.xGoogHeaders, hds...) 1462 hds = append(hds, "Content-Type", "application/json") 1463 headers := gax.BuildHeaders(ctx, hds...) 1464 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1465 resp := &longrunningpb.Operation{} 1466 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1467 if settings.Path != "" { 1468 baseUrl.Path = settings.Path 1469 } 1470 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1471 if err != nil { 1472 return err 1473 } 1474 httpReq = httpReq.WithContext(ctx) 1475 httpReq.Header = headers 1476 1477 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ImportRagFiles") 1478 if err != nil { 1479 return err 1480 } 1481 if err := unm.Unmarshal(buf, resp); err != nil { 1482 return err 1483 } 1484 1485 return nil 1486 }, opts...) 1487 if e != nil { 1488 return nil, e 1489 } 1490 1491 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1492 return &ImportRagFilesOperation{ 1493 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1494 pollPath: override, 1495 }, nil 1496 } 1497 1498 // GetRagFile gets a RagFile. 1499 func (c *vertexRagDataRESTClient) GetRagFile(ctx context.Context, req *aiplatformpb.GetRagFileRequest, opts ...gax.CallOption) (*aiplatformpb.RagFile, error) { 1500 baseUrl, err := url.Parse(c.endpoint) 1501 if err != nil { 1502 return nil, err 1503 } 1504 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1505 1506 params := url.Values{} 1507 params.Add("$alt", "json;enum-encoding=int") 1508 1509 baseUrl.RawQuery = params.Encode() 1510 1511 // Build HTTP headers from client and context metadata. 1512 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1513 1514 hds = append(c.xGoogHeaders, hds...) 1515 hds = append(hds, "Content-Type", "application/json") 1516 headers := gax.BuildHeaders(ctx, hds...) 1517 opts = append((*c.CallOptions).GetRagFile[0:len((*c.CallOptions).GetRagFile):len((*c.CallOptions).GetRagFile)], opts...) 1518 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1519 resp := &aiplatformpb.RagFile{} 1520 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1521 if settings.Path != "" { 1522 baseUrl.Path = settings.Path 1523 } 1524 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1525 if err != nil { 1526 return err 1527 } 1528 httpReq = httpReq.WithContext(ctx) 1529 httpReq.Header = headers 1530 1531 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetRagFile") 1532 if err != nil { 1533 return err 1534 } 1535 1536 if err := unm.Unmarshal(buf, resp); err != nil { 1537 return err 1538 } 1539 1540 return nil 1541 }, opts...) 1542 if e != nil { 1543 return nil, e 1544 } 1545 return resp, nil 1546 } 1547 1548 // ListRagFiles lists RagFiles in a RagCorpus. 1549 func (c *vertexRagDataRESTClient) ListRagFiles(ctx context.Context, req *aiplatformpb.ListRagFilesRequest, opts ...gax.CallOption) *RagFileIterator { 1550 it := &RagFileIterator{} 1551 req = proto.Clone(req).(*aiplatformpb.ListRagFilesRequest) 1552 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1553 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.RagFile, string, error) { 1554 resp := &aiplatformpb.ListRagFilesResponse{} 1555 if pageToken != "" { 1556 req.PageToken = pageToken 1557 } 1558 if pageSize > math.MaxInt32 { 1559 req.PageSize = math.MaxInt32 1560 } else if pageSize != 0 { 1561 req.PageSize = int32(pageSize) 1562 } 1563 baseUrl, err := url.Parse(c.endpoint) 1564 if err != nil { 1565 return nil, "", err 1566 } 1567 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/ragFiles", req.GetParent()) 1568 1569 params := url.Values{} 1570 params.Add("$alt", "json;enum-encoding=int") 1571 if req.GetPageSize() != 0 { 1572 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1573 } 1574 if req.GetPageToken() != "" { 1575 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1576 } 1577 1578 baseUrl.RawQuery = params.Encode() 1579 1580 // Build HTTP headers from client and context metadata. 1581 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1582 headers := gax.BuildHeaders(ctx, hds...) 1583 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1584 if settings.Path != "" { 1585 baseUrl.Path = settings.Path 1586 } 1587 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1588 if err != nil { 1589 return err 1590 } 1591 httpReq.Header = headers 1592 1593 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListRagFiles") 1594 if err != nil { 1595 return err 1596 } 1597 if err := unm.Unmarshal(buf, resp); err != nil { 1598 return err 1599 } 1600 1601 return nil 1602 }, opts...) 1603 if e != nil { 1604 return nil, "", e 1605 } 1606 it.Response = resp 1607 return resp.GetRagFiles(), resp.GetNextPageToken(), nil 1608 } 1609 1610 fetch := func(pageSize int, pageToken string) (string, error) { 1611 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1612 if err != nil { 1613 return "", err 1614 } 1615 it.items = append(it.items, items...) 1616 return nextPageToken, nil 1617 } 1618 1619 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1620 it.pageInfo.MaxSize = int(req.GetPageSize()) 1621 it.pageInfo.Token = req.GetPageToken() 1622 1623 return it 1624 } 1625 1626 // DeleteRagFile deletes a RagFile. 1627 func (c *vertexRagDataRESTClient) DeleteRagFile(ctx context.Context, req *aiplatformpb.DeleteRagFileRequest, opts ...gax.CallOption) (*DeleteRagFileOperation, error) { 1628 baseUrl, err := url.Parse(c.endpoint) 1629 if err != nil { 1630 return nil, err 1631 } 1632 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1633 1634 params := url.Values{} 1635 params.Add("$alt", "json;enum-encoding=int") 1636 if req.GetForceDelete() { 1637 params.Add("forceDelete", fmt.Sprintf("%v", req.GetForceDelete())) 1638 } 1639 1640 baseUrl.RawQuery = params.Encode() 1641 1642 // Build HTTP headers from client and context metadata. 1643 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1644 1645 hds = append(c.xGoogHeaders, hds...) 1646 hds = append(hds, "Content-Type", "application/json") 1647 headers := gax.BuildHeaders(ctx, hds...) 1648 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1649 resp := &longrunningpb.Operation{} 1650 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1651 if settings.Path != "" { 1652 baseUrl.Path = settings.Path 1653 } 1654 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1655 if err != nil { 1656 return err 1657 } 1658 httpReq = httpReq.WithContext(ctx) 1659 httpReq.Header = headers 1660 1661 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteRagFile") 1662 if err != nil { 1663 return err 1664 } 1665 if err := unm.Unmarshal(buf, resp); err != nil { 1666 return err 1667 } 1668 1669 return nil 1670 }, opts...) 1671 if e != nil { 1672 return nil, e 1673 } 1674 1675 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1676 return &DeleteRagFileOperation{ 1677 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1678 pollPath: override, 1679 }, nil 1680 } 1681 1682 // UpdateRagEngineConfig updates a RagEngineConfig. 1683 func (c *vertexRagDataRESTClient) UpdateRagEngineConfig(ctx context.Context, req *aiplatformpb.UpdateRagEngineConfigRequest, opts ...gax.CallOption) (*UpdateRagEngineConfigOperation, error) { 1684 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1685 body := req.GetRagEngineConfig() 1686 jsonReq, err := m.Marshal(body) 1687 if err != nil { 1688 return nil, err 1689 } 1690 1691 baseUrl, err := url.Parse(c.endpoint) 1692 if err != nil { 1693 return nil, err 1694 } 1695 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetRagEngineConfig().GetName()) 1696 1697 params := url.Values{} 1698 params.Add("$alt", "json;enum-encoding=int") 1699 1700 baseUrl.RawQuery = params.Encode() 1701 1702 // Build HTTP headers from client and context metadata. 1703 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "rag_engine_config.name", url.QueryEscape(req.GetRagEngineConfig().GetName()))} 1704 1705 hds = append(c.xGoogHeaders, hds...) 1706 hds = append(hds, "Content-Type", "application/json") 1707 headers := gax.BuildHeaders(ctx, hds...) 1708 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1709 resp := &longrunningpb.Operation{} 1710 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1711 if settings.Path != "" { 1712 baseUrl.Path = settings.Path 1713 } 1714 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) 1715 if err != nil { 1716 return err 1717 } 1718 httpReq = httpReq.WithContext(ctx) 1719 httpReq.Header = headers 1720 1721 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateRagEngineConfig") 1722 if err != nil { 1723 return err 1724 } 1725 if err := unm.Unmarshal(buf, resp); err != nil { 1726 return err 1727 } 1728 1729 return nil 1730 }, opts...) 1731 if e != nil { 1732 return nil, e 1733 } 1734 1735 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1736 return &UpdateRagEngineConfigOperation{ 1737 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1738 pollPath: override, 1739 }, nil 1740 } 1741 1742 // GetRagEngineConfig gets a RagEngineConfig. 1743 func (c *vertexRagDataRESTClient) GetRagEngineConfig(ctx context.Context, req *aiplatformpb.GetRagEngineConfigRequest, opts ...gax.CallOption) (*aiplatformpb.RagEngineConfig, error) { 1744 baseUrl, err := url.Parse(c.endpoint) 1745 if err != nil { 1746 return nil, err 1747 } 1748 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1749 1750 params := url.Values{} 1751 params.Add("$alt", "json;enum-encoding=int") 1752 1753 baseUrl.RawQuery = params.Encode() 1754 1755 // Build HTTP headers from client and context metadata. 1756 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1757 1758 hds = append(c.xGoogHeaders, hds...) 1759 hds = append(hds, "Content-Type", "application/json") 1760 headers := gax.BuildHeaders(ctx, hds...) 1761 opts = append((*c.CallOptions).GetRagEngineConfig[0:len((*c.CallOptions).GetRagEngineConfig):len((*c.CallOptions).GetRagEngineConfig)], opts...) 1762 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1763 resp := &aiplatformpb.RagEngineConfig{} 1764 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1765 if settings.Path != "" { 1766 baseUrl.Path = settings.Path 1767 } 1768 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1769 if err != nil { 1770 return err 1771 } 1772 httpReq = httpReq.WithContext(ctx) 1773 httpReq.Header = headers 1774 1775 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetRagEngineConfig") 1776 if err != nil { 1777 return err 1778 } 1779 1780 if err := unm.Unmarshal(buf, resp); err != nil { 1781 return err 1782 } 1783 1784 return nil 1785 }, opts...) 1786 if e != nil { 1787 return nil, e 1788 } 1789 return resp, nil 1790 } 1791 1792 // GetLocation gets information about a location. 1793 func (c *vertexRagDataRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 1794 baseUrl, err := url.Parse(c.endpoint) 1795 if err != nil { 1796 return nil, err 1797 } 1798 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1799 1800 params := url.Values{} 1801 params.Add("$alt", "json;enum-encoding=int") 1802 1803 baseUrl.RawQuery = params.Encode() 1804 1805 // Build HTTP headers from client and context metadata. 1806 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1807 1808 hds = append(c.xGoogHeaders, hds...) 1809 hds = append(hds, "Content-Type", "application/json") 1810 headers := gax.BuildHeaders(ctx, hds...) 1811 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 1812 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1813 resp := &locationpb.Location{} 1814 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1815 if settings.Path != "" { 1816 baseUrl.Path = settings.Path 1817 } 1818 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1819 if err != nil { 1820 return err 1821 } 1822 httpReq = httpReq.WithContext(ctx) 1823 httpReq.Header = headers 1824 1825 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") 1826 if err != nil { 1827 return err 1828 } 1829 1830 if err := unm.Unmarshal(buf, resp); err != nil { 1831 return err 1832 } 1833 1834 return nil 1835 }, opts...) 1836 if e != nil { 1837 return nil, e 1838 } 1839 return resp, nil 1840 } 1841 1842 // ListLocations lists information about the supported locations for this service. 1843 func (c *vertexRagDataRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 1844 it := &LocationIterator{} 1845 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 1846 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1847 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 1848 resp := &locationpb.ListLocationsResponse{} 1849 if pageToken != "" { 1850 req.PageToken = pageToken 1851 } 1852 if pageSize > math.MaxInt32 { 1853 req.PageSize = math.MaxInt32 1854 } else if pageSize != 0 { 1855 req.PageSize = int32(pageSize) 1856 } 1857 baseUrl, err := url.Parse(c.endpoint) 1858 if err != nil { 1859 return nil, "", err 1860 } 1861 baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName()) 1862 1863 params := url.Values{} 1864 params.Add("$alt", "json;enum-encoding=int") 1865 if req.GetFilter() != "" { 1866 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1867 } 1868 if req.GetPageSize() != 0 { 1869 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1870 } 1871 if req.GetPageToken() != "" { 1872 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1873 } 1874 1875 baseUrl.RawQuery = params.Encode() 1876 1877 // Build HTTP headers from client and context metadata. 1878 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1879 headers := gax.BuildHeaders(ctx, hds...) 1880 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1881 if settings.Path != "" { 1882 baseUrl.Path = settings.Path 1883 } 1884 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1885 if err != nil { 1886 return err 1887 } 1888 httpReq.Header = headers 1889 1890 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") 1891 if err != nil { 1892 return err 1893 } 1894 if err := unm.Unmarshal(buf, resp); err != nil { 1895 return err 1896 } 1897 1898 return nil 1899 }, opts...) 1900 if e != nil { 1901 return nil, "", e 1902 } 1903 it.Response = resp 1904 return resp.GetLocations(), resp.GetNextPageToken(), nil 1905 } 1906 1907 fetch := func(pageSize int, pageToken string) (string, error) { 1908 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1909 if err != nil { 1910 return "", err 1911 } 1912 it.items = append(it.items, items...) 1913 return nextPageToken, nil 1914 } 1915 1916 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1917 it.pageInfo.MaxSize = int(req.GetPageSize()) 1918 it.pageInfo.Token = req.GetPageToken() 1919 1920 return it 1921 } 1922 1923 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 1924 // if the resource exists and does not have a policy set. 1925 func (c *vertexRagDataRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1926 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1927 jsonReq, err := m.Marshal(req) 1928 if err != nil { 1929 return nil, err 1930 } 1931 1932 baseUrl, err := url.Parse(c.endpoint) 1933 if err != nil { 1934 return nil, err 1935 } 1936 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource()) 1937 1938 params := url.Values{} 1939 params.Add("$alt", "json;enum-encoding=int") 1940 1941 baseUrl.RawQuery = params.Encode() 1942 1943 // Build HTTP headers from client and context metadata. 1944 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1945 1946 hds = append(c.xGoogHeaders, hds...) 1947 hds = append(hds, "Content-Type", "application/json") 1948 headers := gax.BuildHeaders(ctx, hds...) 1949 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 1950 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1951 resp := &iampb.Policy{} 1952 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1953 if settings.Path != "" { 1954 baseUrl.Path = settings.Path 1955 } 1956 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1957 if err != nil { 1958 return err 1959 } 1960 httpReq = httpReq.WithContext(ctx) 1961 httpReq.Header = headers 1962 1963 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy") 1964 if err != nil { 1965 return err 1966 } 1967 1968 if err := unm.Unmarshal(buf, resp); err != nil { 1969 return err 1970 } 1971 1972 return nil 1973 }, opts...) 1974 if e != nil { 1975 return nil, e 1976 } 1977 return resp, nil 1978 } 1979 1980 // SetIamPolicy sets the access control policy on the specified resource. Replaces 1981 // any existing policy. 1982 // 1983 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 1984 // errors. 1985 func (c *vertexRagDataRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1986 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1987 jsonReq, err := m.Marshal(req) 1988 if err != nil { 1989 return nil, err 1990 } 1991 1992 baseUrl, err := url.Parse(c.endpoint) 1993 if err != nil { 1994 return nil, err 1995 } 1996 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource()) 1997 1998 params := url.Values{} 1999 params.Add("$alt", "json;enum-encoding=int") 2000 2001 baseUrl.RawQuery = params.Encode() 2002 2003 // Build HTTP headers from client and context metadata. 2004 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 2005 2006 hds = append(c.xGoogHeaders, hds...) 2007 hds = append(hds, "Content-Type", "application/json") 2008 headers := gax.BuildHeaders(ctx, hds...) 2009 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 2010 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2011 resp := &iampb.Policy{} 2012 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2013 if settings.Path != "" { 2014 baseUrl.Path = settings.Path 2015 } 2016 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 2017 if err != nil { 2018 return err 2019 } 2020 httpReq = httpReq.WithContext(ctx) 2021 httpReq.Header = headers 2022 2023 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy") 2024 if err != nil { 2025 return err 2026 } 2027 2028 if err := unm.Unmarshal(buf, resp); err != nil { 2029 return err 2030 } 2031 2032 return nil 2033 }, opts...) 2034 if e != nil { 2035 return nil, e 2036 } 2037 return resp, nil 2038 } 2039 2040 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 2041 // resource does not exist, this will return an empty set of 2042 // permissions, not a NOT_FOUND error. 2043 // 2044 // Note: This operation is designed to be used for building 2045 // permission-aware UIs and command-line tools, not for authorization 2046 // checking. This operation may “fail open” without warning. 2047 func (c *vertexRagDataRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 2048 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 2049 jsonReq, err := m.Marshal(req) 2050 if err != nil { 2051 return nil, err 2052 } 2053 2054 baseUrl, err := url.Parse(c.endpoint) 2055 if err != nil { 2056 return nil, err 2057 } 2058 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource()) 2059 2060 params := url.Values{} 2061 params.Add("$alt", "json;enum-encoding=int") 2062 2063 baseUrl.RawQuery = params.Encode() 2064 2065 // Build HTTP headers from client and context metadata. 2066 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 2067 2068 hds = append(c.xGoogHeaders, hds...) 2069 hds = append(hds, "Content-Type", "application/json") 2070 headers := gax.BuildHeaders(ctx, hds...) 2071 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 2072 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2073 resp := &iampb.TestIamPermissionsResponse{} 2074 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2075 if settings.Path != "" { 2076 baseUrl.Path = settings.Path 2077 } 2078 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 2079 if err != nil { 2080 return err 2081 } 2082 httpReq = httpReq.WithContext(ctx) 2083 httpReq.Header = headers 2084 2085 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions") 2086 if err != nil { 2087 return err 2088 } 2089 2090 if err := unm.Unmarshal(buf, resp); err != nil { 2091 return err 2092 } 2093 2094 return nil 2095 }, opts...) 2096 if e != nil { 2097 return nil, e 2098 } 2099 return resp, nil 2100 } 2101 2102 // CancelOperation is a utility method from google.longrunning.Operations. 2103 func (c *vertexRagDataRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 2104 baseUrl, err := url.Parse(c.endpoint) 2105 if err != nil { 2106 return err 2107 } 2108 baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName()) 2109 2110 params := url.Values{} 2111 params.Add("$alt", "json;enum-encoding=int") 2112 2113 baseUrl.RawQuery = params.Encode() 2114 2115 // Build HTTP headers from client and context metadata. 2116 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2117 2118 hds = append(c.xGoogHeaders, hds...) 2119 hds = append(hds, "Content-Type", "application/json") 2120 headers := gax.BuildHeaders(ctx, hds...) 2121 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2122 if settings.Path != "" { 2123 baseUrl.Path = settings.Path 2124 } 2125 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 2126 if err != nil { 2127 return err 2128 } 2129 httpReq = httpReq.WithContext(ctx) 2130 httpReq.Header = headers 2131 2132 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation") 2133 return err 2134 }, opts...) 2135 } 2136 2137 // DeleteOperation is a utility method from google.longrunning.Operations. 2138 func (c *vertexRagDataRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 2139 baseUrl, err := url.Parse(c.endpoint) 2140 if err != nil { 2141 return err 2142 } 2143 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 2144 2145 params := url.Values{} 2146 params.Add("$alt", "json;enum-encoding=int") 2147 2148 baseUrl.RawQuery = params.Encode() 2149 2150 // Build HTTP headers from client and context metadata. 2151 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2152 2153 hds = append(c.xGoogHeaders, hds...) 2154 hds = append(hds, "Content-Type", "application/json") 2155 headers := gax.BuildHeaders(ctx, hds...) 2156 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2157 if settings.Path != "" { 2158 baseUrl.Path = settings.Path 2159 } 2160 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 2161 if err != nil { 2162 return err 2163 } 2164 httpReq = httpReq.WithContext(ctx) 2165 httpReq.Header = headers 2166 2167 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") 2168 return err 2169 }, opts...) 2170 } 2171 2172 // GetOperation is a utility method from google.longrunning.Operations. 2173 func (c *vertexRagDataRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 2174 baseUrl, err := url.Parse(c.endpoint) 2175 if err != nil { 2176 return nil, err 2177 } 2178 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 2179 2180 params := url.Values{} 2181 params.Add("$alt", "json;enum-encoding=int") 2182 2183 baseUrl.RawQuery = params.Encode() 2184 2185 // Build HTTP headers from client and context metadata. 2186 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2187 2188 hds = append(c.xGoogHeaders, hds...) 2189 hds = append(hds, "Content-Type", "application/json") 2190 headers := gax.BuildHeaders(ctx, hds...) 2191 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 2192 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2193 resp := &longrunningpb.Operation{} 2194 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2195 if settings.Path != "" { 2196 baseUrl.Path = settings.Path 2197 } 2198 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 2199 if err != nil { 2200 return err 2201 } 2202 httpReq = httpReq.WithContext(ctx) 2203 httpReq.Header = headers 2204 2205 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") 2206 if err != nil { 2207 return err 2208 } 2209 2210 if err := unm.Unmarshal(buf, resp); err != nil { 2211 return err 2212 } 2213 2214 return nil 2215 }, opts...) 2216 if e != nil { 2217 return nil, e 2218 } 2219 return resp, nil 2220 } 2221 2222 // ListOperations is a utility method from google.longrunning.Operations. 2223 func (c *vertexRagDataRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 2224 it := &OperationIterator{} 2225 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 2226 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2227 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 2228 resp := &longrunningpb.ListOperationsResponse{} 2229 if pageToken != "" { 2230 req.PageToken = pageToken 2231 } 2232 if pageSize > math.MaxInt32 { 2233 req.PageSize = math.MaxInt32 2234 } else if pageSize != 0 { 2235 req.PageSize = int32(pageSize) 2236 } 2237 baseUrl, err := url.Parse(c.endpoint) 2238 if err != nil { 2239 return nil, "", err 2240 } 2241 baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName()) 2242 2243 params := url.Values{} 2244 params.Add("$alt", "json;enum-encoding=int") 2245 if req.GetFilter() != "" { 2246 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 2247 } 2248 if req.GetPageSize() != 0 { 2249 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 2250 } 2251 if req.GetPageToken() != "" { 2252 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 2253 } 2254 2255 baseUrl.RawQuery = params.Encode() 2256 2257 // Build HTTP headers from client and context metadata. 2258 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 2259 headers := gax.BuildHeaders(ctx, hds...) 2260 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2261 if settings.Path != "" { 2262 baseUrl.Path = settings.Path 2263 } 2264 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 2265 if err != nil { 2266 return err 2267 } 2268 httpReq.Header = headers 2269 2270 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") 2271 if err != nil { 2272 return err 2273 } 2274 if err := unm.Unmarshal(buf, resp); err != nil { 2275 return err 2276 } 2277 2278 return nil 2279 }, opts...) 2280 if e != nil { 2281 return nil, "", e 2282 } 2283 it.Response = resp 2284 return resp.GetOperations(), resp.GetNextPageToken(), nil 2285 } 2286 2287 fetch := func(pageSize int, pageToken string) (string, error) { 2288 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 2289 if err != nil { 2290 return "", err 2291 } 2292 it.items = append(it.items, items...) 2293 return nextPageToken, nil 2294 } 2295 2296 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 2297 it.pageInfo.MaxSize = int(req.GetPageSize()) 2298 it.pageInfo.Token = req.GetPageToken() 2299 2300 return it 2301 } 2302 2303 // WaitOperation is a utility method from google.longrunning.Operations. 2304 func (c *vertexRagDataRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 2305 baseUrl, err := url.Parse(c.endpoint) 2306 if err != nil { 2307 return nil, err 2308 } 2309 baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName()) 2310 2311 params := url.Values{} 2312 params.Add("$alt", "json;enum-encoding=int") 2313 if req.GetTimeout() != nil { 2314 field, err := protojson.Marshal(req.GetTimeout()) 2315 if err != nil { 2316 return nil, err 2317 } 2318 params.Add("timeout", string(field[1:len(field)-1])) 2319 } 2320 2321 baseUrl.RawQuery = params.Encode() 2322 2323 // Build HTTP headers from client and context metadata. 2324 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 2325 2326 hds = append(c.xGoogHeaders, hds...) 2327 hds = append(hds, "Content-Type", "application/json") 2328 headers := gax.BuildHeaders(ctx, hds...) 2329 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 2330 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 2331 resp := &longrunningpb.Operation{} 2332 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 2333 if settings.Path != "" { 2334 baseUrl.Path = settings.Path 2335 } 2336 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 2337 if err != nil { 2338 return err 2339 } 2340 httpReq = httpReq.WithContext(ctx) 2341 httpReq.Header = headers 2342 2343 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation") 2344 if err != nil { 2345 return err 2346 } 2347 2348 if err := unm.Unmarshal(buf, resp); err != nil { 2349 return err 2350 } 2351 2352 return nil 2353 }, opts...) 2354 if e != nil { 2355 return nil, e 2356 } 2357 return resp, nil 2358 } 2359 2360 // CreateRagCorpusOperation returns a new CreateRagCorpusOperation from a given name. 2361 // The name must be that of a previously created CreateRagCorpusOperation, possibly from a different process. 2362 func (c *vertexRagDataGRPCClient) CreateRagCorpusOperation(name string) *CreateRagCorpusOperation { 2363 return &CreateRagCorpusOperation{ 2364 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2365 } 2366 } 2367 2368 // CreateRagCorpusOperation returns a new CreateRagCorpusOperation from a given name. 2369 // The name must be that of a previously created CreateRagCorpusOperation, possibly from a different process. 2370 func (c *vertexRagDataRESTClient) CreateRagCorpusOperation(name string) *CreateRagCorpusOperation { 2371 override := fmt.Sprintf("/ui/%s", name) 2372 return &CreateRagCorpusOperation{ 2373 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2374 pollPath: override, 2375 } 2376 } 2377 2378 // DeleteRagCorpusOperation returns a new DeleteRagCorpusOperation from a given name. 2379 // The name must be that of a previously created DeleteRagCorpusOperation, possibly from a different process. 2380 func (c *vertexRagDataGRPCClient) DeleteRagCorpusOperation(name string) *DeleteRagCorpusOperation { 2381 return &DeleteRagCorpusOperation{ 2382 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2383 } 2384 } 2385 2386 // DeleteRagCorpusOperation returns a new DeleteRagCorpusOperation from a given name. 2387 // The name must be that of a previously created DeleteRagCorpusOperation, possibly from a different process. 2388 func (c *vertexRagDataRESTClient) DeleteRagCorpusOperation(name string) *DeleteRagCorpusOperation { 2389 override := fmt.Sprintf("/ui/%s", name) 2390 return &DeleteRagCorpusOperation{ 2391 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2392 pollPath: override, 2393 } 2394 } 2395 2396 // DeleteRagFileOperation returns a new DeleteRagFileOperation from a given name. 2397 // The name must be that of a previously created DeleteRagFileOperation, possibly from a different process. 2398 func (c *vertexRagDataGRPCClient) DeleteRagFileOperation(name string) *DeleteRagFileOperation { 2399 return &DeleteRagFileOperation{ 2400 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2401 } 2402 } 2403 2404 // DeleteRagFileOperation returns a new DeleteRagFileOperation from a given name. 2405 // The name must be that of a previously created DeleteRagFileOperation, possibly from a different process. 2406 func (c *vertexRagDataRESTClient) DeleteRagFileOperation(name string) *DeleteRagFileOperation { 2407 override := fmt.Sprintf("/ui/%s", name) 2408 return &DeleteRagFileOperation{ 2409 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2410 pollPath: override, 2411 } 2412 } 2413 2414 // ImportRagFilesOperation returns a new ImportRagFilesOperation from a given name. 2415 // The name must be that of a previously created ImportRagFilesOperation, possibly from a different process. 2416 func (c *vertexRagDataGRPCClient) ImportRagFilesOperation(name string) *ImportRagFilesOperation { 2417 return &ImportRagFilesOperation{ 2418 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2419 } 2420 } 2421 2422 // ImportRagFilesOperation returns a new ImportRagFilesOperation from a given name. 2423 // The name must be that of a previously created ImportRagFilesOperation, possibly from a different process. 2424 func (c *vertexRagDataRESTClient) ImportRagFilesOperation(name string) *ImportRagFilesOperation { 2425 override := fmt.Sprintf("/ui/%s", name) 2426 return &ImportRagFilesOperation{ 2427 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2428 pollPath: override, 2429 } 2430 } 2431 2432 // UpdateRagCorpusOperation returns a new UpdateRagCorpusOperation from a given name. 2433 // The name must be that of a previously created UpdateRagCorpusOperation, possibly from a different process. 2434 func (c *vertexRagDataGRPCClient) UpdateRagCorpusOperation(name string) *UpdateRagCorpusOperation { 2435 return &UpdateRagCorpusOperation{ 2436 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2437 } 2438 } 2439 2440 // UpdateRagCorpusOperation returns a new UpdateRagCorpusOperation from a given name. 2441 // The name must be that of a previously created UpdateRagCorpusOperation, possibly from a different process. 2442 func (c *vertexRagDataRESTClient) UpdateRagCorpusOperation(name string) *UpdateRagCorpusOperation { 2443 override := fmt.Sprintf("/ui/%s", name) 2444 return &UpdateRagCorpusOperation{ 2445 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2446 pollPath: override, 2447 } 2448 } 2449 2450 // UpdateRagEngineConfigOperation returns a new UpdateRagEngineConfigOperation from a given name. 2451 // The name must be that of a previously created UpdateRagEngineConfigOperation, possibly from a different process. 2452 func (c *vertexRagDataGRPCClient) UpdateRagEngineConfigOperation(name string) *UpdateRagEngineConfigOperation { 2453 return &UpdateRagEngineConfigOperation{ 2454 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2455 } 2456 } 2457 2458 // UpdateRagEngineConfigOperation returns a new UpdateRagEngineConfigOperation from a given name. 2459 // The name must be that of a previously created UpdateRagEngineConfigOperation, possibly from a different process. 2460 func (c *vertexRagDataRESTClient) UpdateRagEngineConfigOperation(name string) *UpdateRagEngineConfigOperation { 2461 override := fmt.Sprintf("/ui/%s", name) 2462 return &UpdateRagEngineConfigOperation{ 2463 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 2464 pollPath: override, 2465 } 2466 }