cloud.google.com/go/aiplatform@v1.106.0/apiv1/gen_ai_tuning_client_example_test.go (about)

     1  // Copyright 2025 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
    16  
    17  package aiplatform_test
    18  
    19  import (
    20  	"context"
    21  
    22  	aiplatform "cloud.google.com/go/aiplatform/apiv1"
    23  	aiplatformpb "cloud.google.com/go/aiplatform/apiv1/aiplatformpb"
    24  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    25  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    26  	"google.golang.org/api/iterator"
    27  	locationpb "google.golang.org/genproto/googleapis/cloud/location"
    28  )
    29  
    30  func ExampleNewGenAiTuningClient() {
    31  	ctx := context.Background()
    32  	// This snippet has been automatically generated and should be regarded as a code template only.
    33  	// It will require modifications to work:
    34  	// - It may require correct/in-range values for request initialization.
    35  	// - It may require specifying regional endpoints when creating the service client as shown in:
    36  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    37  	c, err := aiplatform.NewGenAiTuningClient(ctx)
    38  	if err != nil {
    39  		// TODO: Handle error.
    40  	}
    41  	defer c.Close()
    42  
    43  	// TODO: Use client.
    44  	_ = c
    45  }
    46  
    47  func ExampleGenAiTuningClient_CancelTuningJob() {
    48  	ctx := context.Background()
    49  	// This snippet has been automatically generated and should be regarded as a code template only.
    50  	// It will require modifications to work:
    51  	// - It may require correct/in-range values for request initialization.
    52  	// - It may require specifying regional endpoints when creating the service client as shown in:
    53  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    54  	c, err := aiplatform.NewGenAiTuningClient(ctx)
    55  	if err != nil {
    56  		// TODO: Handle error.
    57  	}
    58  	defer c.Close()
    59  
    60  	req := &aiplatformpb.CancelTuningJobRequest{
    61  		// TODO: Fill request struct fields.
    62  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#CancelTuningJobRequest.
    63  	}
    64  	err = c.CancelTuningJob(ctx, req)
    65  	if err != nil {
    66  		// TODO: Handle error.
    67  	}
    68  }
    69  
    70  func ExampleGenAiTuningClient_CreateTuningJob() {
    71  	ctx := context.Background()
    72  	// This snippet has been automatically generated and should be regarded as a code template only.
    73  	// It will require modifications to work:
    74  	// - It may require correct/in-range values for request initialization.
    75  	// - It may require specifying regional endpoints when creating the service client as shown in:
    76  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    77  	c, err := aiplatform.NewGenAiTuningClient(ctx)
    78  	if err != nil {
    79  		// TODO: Handle error.
    80  	}
    81  	defer c.Close()
    82  
    83  	req := &aiplatformpb.CreateTuningJobRequest{
    84  		// TODO: Fill request struct fields.
    85  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#CreateTuningJobRequest.
    86  	}
    87  	resp, err := c.CreateTuningJob(ctx, req)
    88  	if err != nil {
    89  		// TODO: Handle error.
    90  	}
    91  	// TODO: Use resp.
    92  	_ = resp
    93  }
    94  
    95  func ExampleGenAiTuningClient_GetTuningJob() {
    96  	ctx := context.Background()
    97  	// This snippet has been automatically generated and should be regarded as a code template only.
    98  	// It will require modifications to work:
    99  	// - It may require correct/in-range values for request initialization.
   100  	// - It may require specifying regional endpoints when creating the service client as shown in:
   101  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   102  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   103  	if err != nil {
   104  		// TODO: Handle error.
   105  	}
   106  	defer c.Close()
   107  
   108  	req := &aiplatformpb.GetTuningJobRequest{
   109  		// TODO: Fill request struct fields.
   110  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#GetTuningJobRequest.
   111  	}
   112  	resp, err := c.GetTuningJob(ctx, req)
   113  	if err != nil {
   114  		// TODO: Handle error.
   115  	}
   116  	// TODO: Use resp.
   117  	_ = resp
   118  }
   119  
   120  func ExampleGenAiTuningClient_ListTuningJobs() {
   121  	ctx := context.Background()
   122  	// This snippet has been automatically generated and should be regarded as a code template only.
   123  	// It will require modifications to work:
   124  	// - It may require correct/in-range values for request initialization.
   125  	// - It may require specifying regional endpoints when creating the service client as shown in:
   126  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   127  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   128  	if err != nil {
   129  		// TODO: Handle error.
   130  	}
   131  	defer c.Close()
   132  
   133  	req := &aiplatformpb.ListTuningJobsRequest{
   134  		// TODO: Fill request struct fields.
   135  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#ListTuningJobsRequest.
   136  	}
   137  	it := c.ListTuningJobs(ctx, req)
   138  	for {
   139  		resp, err := it.Next()
   140  		if err == iterator.Done {
   141  			break
   142  		}
   143  		if err != nil {
   144  			// TODO: Handle error.
   145  		}
   146  		// TODO: Use resp.
   147  		_ = resp
   148  
   149  		// If you need to access the underlying RPC response,
   150  		// you can do so by casting the `Response` as below.
   151  		// Otherwise, remove this line. Only populated after
   152  		// first call to Next(). Not safe for concurrent access.
   153  		_ = it.Response.(*aiplatformpb.ListTuningJobsResponse)
   154  	}
   155  }
   156  
   157  func ExampleGenAiTuningClient_RebaseTunedModel() {
   158  	ctx := context.Background()
   159  	// This snippet has been automatically generated and should be regarded as a code template only.
   160  	// It will require modifications to work:
   161  	// - It may require correct/in-range values for request initialization.
   162  	// - It may require specifying regional endpoints when creating the service client as shown in:
   163  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   164  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   165  	if err != nil {
   166  		// TODO: Handle error.
   167  	}
   168  	defer c.Close()
   169  
   170  	req := &aiplatformpb.RebaseTunedModelRequest{
   171  		// TODO: Fill request struct fields.
   172  		// See https://pkg.go.dev/cloud.google.com/go/aiplatform/apiv1/aiplatformpb#RebaseTunedModelRequest.
   173  	}
   174  	op, err := c.RebaseTunedModel(ctx, req)
   175  	if err != nil {
   176  		// TODO: Handle error.
   177  	}
   178  
   179  	resp, err := op.Wait(ctx)
   180  	if err != nil {
   181  		// TODO: Handle error.
   182  	}
   183  	// TODO: Use resp.
   184  	_ = resp
   185  }
   186  
   187  func ExampleGenAiTuningClient_GetLocation() {
   188  	ctx := context.Background()
   189  	// This snippet has been automatically generated and should be regarded as a code template only.
   190  	// It will require modifications to work:
   191  	// - It may require correct/in-range values for request initialization.
   192  	// - It may require specifying regional endpoints when creating the service client as shown in:
   193  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   194  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   195  	if err != nil {
   196  		// TODO: Handle error.
   197  	}
   198  	defer c.Close()
   199  
   200  	req := &locationpb.GetLocationRequest{
   201  		// TODO: Fill request struct fields.
   202  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
   203  	}
   204  	resp, err := c.GetLocation(ctx, req)
   205  	if err != nil {
   206  		// TODO: Handle error.
   207  	}
   208  	// TODO: Use resp.
   209  	_ = resp
   210  }
   211  
   212  func ExampleGenAiTuningClient_ListLocations() {
   213  	ctx := context.Background()
   214  	// This snippet has been automatically generated and should be regarded as a code template only.
   215  	// It will require modifications to work:
   216  	// - It may require correct/in-range values for request initialization.
   217  	// - It may require specifying regional endpoints when creating the service client as shown in:
   218  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   219  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   220  	if err != nil {
   221  		// TODO: Handle error.
   222  	}
   223  	defer c.Close()
   224  
   225  	req := &locationpb.ListLocationsRequest{
   226  		// TODO: Fill request struct fields.
   227  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
   228  	}
   229  	it := c.ListLocations(ctx, req)
   230  	for {
   231  		resp, err := it.Next()
   232  		if err == iterator.Done {
   233  			break
   234  		}
   235  		if err != nil {
   236  			// TODO: Handle error.
   237  		}
   238  		// TODO: Use resp.
   239  		_ = resp
   240  
   241  		// If you need to access the underlying RPC response,
   242  		// you can do so by casting the `Response` as below.
   243  		// Otherwise, remove this line. Only populated after
   244  		// first call to Next(). Not safe for concurrent access.
   245  		_ = it.Response.(*locationpb.ListLocationsResponse)
   246  	}
   247  }
   248  
   249  func ExampleGenAiTuningClient_GetIamPolicy() {
   250  	ctx := context.Background()
   251  	// This snippet has been automatically generated and should be regarded as a code template only.
   252  	// It will require modifications to work:
   253  	// - It may require correct/in-range values for request initialization.
   254  	// - It may require specifying regional endpoints when creating the service client as shown in:
   255  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   256  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   257  	if err != nil {
   258  		// TODO: Handle error.
   259  	}
   260  	defer c.Close()
   261  
   262  	req := &iampb.GetIamPolicyRequest{
   263  		// TODO: Fill request struct fields.
   264  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
   265  	}
   266  	resp, err := c.GetIamPolicy(ctx, req)
   267  	if err != nil {
   268  		// TODO: Handle error.
   269  	}
   270  	// TODO: Use resp.
   271  	_ = resp
   272  }
   273  
   274  func ExampleGenAiTuningClient_SetIamPolicy() {
   275  	ctx := context.Background()
   276  	// This snippet has been automatically generated and should be regarded as a code template only.
   277  	// It will require modifications to work:
   278  	// - It may require correct/in-range values for request initialization.
   279  	// - It may require specifying regional endpoints when creating the service client as shown in:
   280  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   281  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   282  	if err != nil {
   283  		// TODO: Handle error.
   284  	}
   285  	defer c.Close()
   286  
   287  	req := &iampb.SetIamPolicyRequest{
   288  		// TODO: Fill request struct fields.
   289  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
   290  	}
   291  	resp, err := c.SetIamPolicy(ctx, req)
   292  	if err != nil {
   293  		// TODO: Handle error.
   294  	}
   295  	// TODO: Use resp.
   296  	_ = resp
   297  }
   298  
   299  func ExampleGenAiTuningClient_TestIamPermissions() {
   300  	ctx := context.Background()
   301  	// This snippet has been automatically generated and should be regarded as a code template only.
   302  	// It will require modifications to work:
   303  	// - It may require correct/in-range values for request initialization.
   304  	// - It may require specifying regional endpoints when creating the service client as shown in:
   305  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   306  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   307  	if err != nil {
   308  		// TODO: Handle error.
   309  	}
   310  	defer c.Close()
   311  
   312  	req := &iampb.TestIamPermissionsRequest{
   313  		// TODO: Fill request struct fields.
   314  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
   315  	}
   316  	resp, err := c.TestIamPermissions(ctx, req)
   317  	if err != nil {
   318  		// TODO: Handle error.
   319  	}
   320  	// TODO: Use resp.
   321  	_ = resp
   322  }
   323  
   324  func ExampleGenAiTuningClient_CancelOperation() {
   325  	ctx := context.Background()
   326  	// This snippet has been automatically generated and should be regarded as a code template only.
   327  	// It will require modifications to work:
   328  	// - It may require correct/in-range values for request initialization.
   329  	// - It may require specifying regional endpoints when creating the service client as shown in:
   330  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   331  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   332  	if err != nil {
   333  		// TODO: Handle error.
   334  	}
   335  	defer c.Close()
   336  
   337  	req := &longrunningpb.CancelOperationRequest{
   338  		// TODO: Fill request struct fields.
   339  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
   340  	}
   341  	err = c.CancelOperation(ctx, req)
   342  	if err != nil {
   343  		// TODO: Handle error.
   344  	}
   345  }
   346  
   347  func ExampleGenAiTuningClient_DeleteOperation() {
   348  	ctx := context.Background()
   349  	// This snippet has been automatically generated and should be regarded as a code template only.
   350  	// It will require modifications to work:
   351  	// - It may require correct/in-range values for request initialization.
   352  	// - It may require specifying regional endpoints when creating the service client as shown in:
   353  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   354  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   355  	if err != nil {
   356  		// TODO: Handle error.
   357  	}
   358  	defer c.Close()
   359  
   360  	req := &longrunningpb.DeleteOperationRequest{
   361  		// TODO: Fill request struct fields.
   362  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
   363  	}
   364  	err = c.DeleteOperation(ctx, req)
   365  	if err != nil {
   366  		// TODO: Handle error.
   367  	}
   368  }
   369  
   370  func ExampleGenAiTuningClient_GetOperation() {
   371  	ctx := context.Background()
   372  	// This snippet has been automatically generated and should be regarded as a code template only.
   373  	// It will require modifications to work:
   374  	// - It may require correct/in-range values for request initialization.
   375  	// - It may require specifying regional endpoints when creating the service client as shown in:
   376  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   377  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   378  	if err != nil {
   379  		// TODO: Handle error.
   380  	}
   381  	defer c.Close()
   382  
   383  	req := &longrunningpb.GetOperationRequest{
   384  		// TODO: Fill request struct fields.
   385  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
   386  	}
   387  	resp, err := c.GetOperation(ctx, req)
   388  	if err != nil {
   389  		// TODO: Handle error.
   390  	}
   391  	// TODO: Use resp.
   392  	_ = resp
   393  }
   394  
   395  func ExampleGenAiTuningClient_ListOperations() {
   396  	ctx := context.Background()
   397  	// This snippet has been automatically generated and should be regarded as a code template only.
   398  	// It will require modifications to work:
   399  	// - It may require correct/in-range values for request initialization.
   400  	// - It may require specifying regional endpoints when creating the service client as shown in:
   401  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   402  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   403  	if err != nil {
   404  		// TODO: Handle error.
   405  	}
   406  	defer c.Close()
   407  
   408  	req := &longrunningpb.ListOperationsRequest{
   409  		// TODO: Fill request struct fields.
   410  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
   411  	}
   412  	it := c.ListOperations(ctx, req)
   413  	for {
   414  		resp, err := it.Next()
   415  		if err == iterator.Done {
   416  			break
   417  		}
   418  		if err != nil {
   419  			// TODO: Handle error.
   420  		}
   421  		// TODO: Use resp.
   422  		_ = resp
   423  
   424  		// If you need to access the underlying RPC response,
   425  		// you can do so by casting the `Response` as below.
   426  		// Otherwise, remove this line. Only populated after
   427  		// first call to Next(). Not safe for concurrent access.
   428  		_ = it.Response.(*longrunningpb.ListOperationsResponse)
   429  	}
   430  }
   431  
   432  func ExampleGenAiTuningClient_WaitOperation() {
   433  	ctx := context.Background()
   434  	// This snippet has been automatically generated and should be regarded as a code template only.
   435  	// It will require modifications to work:
   436  	// - It may require correct/in-range values for request initialization.
   437  	// - It may require specifying regional endpoints when creating the service client as shown in:
   438  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   439  	c, err := aiplatform.NewGenAiTuningClient(ctx)
   440  	if err != nil {
   441  		// TODO: Handle error.
   442  	}
   443  	defer c.Close()
   444  
   445  	req := &longrunningpb.WaitOperationRequest{
   446  		// TODO: Fill request struct fields.
   447  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#WaitOperationRequest.
   448  	}
   449  	resp, err := c.WaitOperation(ctx, req)
   450  	if err != nil {
   451  		// TODO: Handle error.
   452  	}
   453  	// TODO: Use resp.
   454  	_ = resp
   455  }