Skip to content

Commit 1091051

Browse files
Merge branch 'main' into tpu_ququed_resources_startup_script
2 parents b34eae1 + 3ff39e7 commit 1091051

35 files changed

+1941
-62
lines changed

aiplatform/src/main/java/aiplatform/EmbeddingBatchSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void main(String[] args) throws IOException, InterruptedException
4040
// Could be a BigQuery table or a Google Cloud Storage file.
4141
// E.g. "gs://[BUCKET]/[OUTPUT].jsonl" OR "bq://[PROJECT].[DATASET].[TABLE]"
4242
String outputUri = "gs://YOUR_BUCKET/embedding_batch_output";
43-
String textEmbeddingModel = "textembedding-gecko@003";
43+
String textEmbeddingModel = "text-embedding-005";
4444

4545
embeddingBatchSample(project, location, inputUri, outputUri, textEmbeddingModel);
4646
}

aiplatform/src/main/java/aiplatform/EmbeddingModelTuningSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static PipelineJob createEmbeddingModelTuningPipelineJob(
8484
Matcher matcher = Pattern.compile("^(?<Location>\\w+-\\w+)").matcher(apiEndpoint);
8585
String location = matcher.matches() ? matcher.group("Location") : "us-central1";
8686
String templateUri =
87-
"https://us-kfp.pkg.dev/ml-pipeline/llm-text-embedding/tune-text-embedding-model/v1.1.3";
87+
"https://us-kfp.pkg.dev/ml-pipeline/llm-text-embedding/tune-text-embedding-model/v1.1.4";
8888
PipelineServiceSettings settings =
8989
PipelineServiceSettings.newBuilder().setEndpoint(apiEndpoint).build();
9090
try (PipelineServiceClient client = PipelineServiceClient.create(settings)) {

aiplatform/src/main/java/aiplatform/PredictTextEmbeddingsSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static void main(String[] args) throws IOException {
4141
// https://cloud.google.com/vertex-ai/docs/generative-ai/embeddings/get-text-embeddings
4242
String endpoint = "us-central1-aiplatform.googleapis.com:443";
4343
String project = "YOUR_PROJECT_ID";
44-
String model = "text-embedding-004";
44+
String model = "text-embedding-005";
4545
predictTextEmbeddings(
4646
endpoint,
4747
project,

aiplatform/src/main/java/aiplatform/PredictTextEmbeddingsSamplePreview.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static void main(String[] args) throws IOException {
4141
// https://cloud.google.com/vertex-ai/docs/generative-ai/embeddings/get-text-embeddings
4242
String endpoint = "us-central1-aiplatform.googleapis.com";
4343
String project = "YOUR_PROJECT_ID";
44-
String model = "text-embedding-preview-0815";
44+
String model = "text-embedding-005";
4545
// Calculate the embedding for a code retrieval query. Using 'CODE_RETRIEVAL_QUERY' for query.
4646
predictTextEmbeddings(
4747
endpoint,

aiplatform/src/test/java/aiplatform/EmbeddingBatchSampleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class EmbeddingBatchSampleTest extends TestCase {
4141
"gs://cloud-samples-data/generative-ai/embeddings/embeddings_input.jsonl";
4242
private static final String GCS_OUTPUT_URI =
4343
String.format("gs://%s/embedding_batch_output", BUCKET_NAME);
44-
private static final String MODEL_ID = "textembedding-gecko@003";
44+
private static final String MODEL_ID = "text-embedding-005";
4545
static Storage storage;
4646
static Bucket bucket;
4747

aiplatform/src/test/java/aiplatform/EmbeddingModelTuningSampleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class EmbeddingModelTuningSampleTest {
5353

5454
private static final String API_ENDPOINT = "us-central1-aiplatform.googleapis.com:443";
5555
private static final String PROJECT = System.getenv("UCAIP_PROJECT_ID");
56-
private static final String BASE_MODEL_VERSION_ID = "text-embedding-004";
56+
private static final String BASE_MODEL_VERSION_ID = "text-embedding-005";
5757
private static final String TASK_TYPE = "DEFAULT";
5858
private static final String JOB_DISPLAY_NAME = "embedding-customization-pipeline-sample";
5959
private static final String CORPUS =

aiplatform/src/test/java/aiplatform/PredictTextEmbeddingsSampleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testPredictTextEmbeddings() throws IOException {
5252
PredictTextEmbeddingsSample.predictTextEmbeddings(
5353
APIS_ENDPOINT,
5454
PROJECT,
55-
"text-embedding-004",
55+
"text-embedding-005",
5656
texts,
5757
"QUESTION_ANSWERING",
5858
OptionalInt.of(5));
@@ -70,7 +70,7 @@ public void testPredictTextEmbeddingsPreview() throws IOException {
7070
PredictTextEmbeddingsSamplePreview.predictTextEmbeddings(
7171
APIS_ENDPOINT,
7272
PROJECT,
73-
"text-embedding-preview-0815",
73+
"text-embedding-005",
7474
texts,
7575
"CODE_RETRIEVAL_QUERY",
7676
OptionalInt.of(5));

cdn/signed-urls/src/main/java/com/google/cdn/SignedUrls.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@
2727
import javax.crypto.Mac;
2828
import javax.crypto.spec.SecretKeySpec;
2929

30-
/**
31-
* Samples to create a signed URL for a Cloud CDN endpoint
32-
*/
30+
// [START cloudcdn_sign_url]
31+
/** Samples to create a signed URL for a Cloud CDN endpoint */
3332
public class SignedUrls {
3433

35-
// [START cloudcdn_sign_url]
3634
/**
3735
* Creates a signed URL for a Cloud CDN endpoint with the given key
3836
* URL must start with http:// or https://, and must contain a forward

compute/cloud-client/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
<groupId>com.google.cloud</groupId>
6060
<scope>test</scope>
6161
</dependency>
62+
<dependency>
63+
<groupId>org.mockito</groupId>
64+
<artifactId>mockito-core</artifactId>
65+
<version>5.13.0</version>
66+
<scope>test</scope>
67+
</dependency>
68+
6269

6370
<dependency>
6471
<artifactId>truth</artifactId>
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package compute.reservation;
18+
19+
// [START compute_instance_not_consume_reservation]
20+
import static com.google.cloud.compute.v1.ReservationAffinity.ConsumeReservationType.NO_RESERVATION;
21+
22+
import com.google.api.gax.longrunning.OperationFuture;
23+
import com.google.cloud.compute.v1.AttachedDisk;
24+
import com.google.cloud.compute.v1.AttachedDiskInitializeParams;
25+
import com.google.cloud.compute.v1.InsertInstanceRequest;
26+
import com.google.cloud.compute.v1.Instance;
27+
import com.google.cloud.compute.v1.InstancesClient;
28+
import com.google.cloud.compute.v1.NetworkInterface;
29+
import com.google.cloud.compute.v1.Operation;
30+
import com.google.cloud.compute.v1.ReservationAffinity;
31+
import java.io.IOException;
32+
import java.util.concurrent.ExecutionException;
33+
import java.util.concurrent.TimeUnit;
34+
import java.util.concurrent.TimeoutException;
35+
36+
public class CreateInstanceWithoutConsumingReservation {
37+
public static void main(String[] args)
38+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
39+
// TODO(developer): Replace these variables before running the sample.
40+
// Project ID or project number of the Cloud project you want to use.
41+
String projectId = "YOUR_PROJECT_ID";
42+
// Name of the zone you want to use.
43+
String zone = "us-central1-a";
44+
// Name of the VM instance you want to query.
45+
String instanceName = "YOUR_INSTANCE_NAME";
46+
// machineType: machine type of the VM being created.
47+
// * This value uses the format zones/{zone}/machineTypes/{type_name}.
48+
// * For a list of machine types, see https://cloud.google.com/compute/docs/machine-types
49+
String machineTypeName = "n1-standard-1";
50+
// sourceImage: path to the operating system image to mount.
51+
// * For details about images you can mount, see https://cloud.google.com/compute/docs/images
52+
String sourceImage = "projects/debian-cloud/global/images/family/debian-11";
53+
// diskSizeGb: storage size of the boot disk to attach to the instance.
54+
long diskSizeGb = 10L;
55+
// networkName: network interface to associate with the instance.
56+
String networkName = "default";
57+
58+
createInstanceWithoutConsumingReservationAsync(projectId, zone, instanceName,
59+
machineTypeName, sourceImage, diskSizeGb, networkName);
60+
}
61+
62+
// Create a virtual machine that explicitly doesn't consume reservations
63+
public static Instance createInstanceWithoutConsumingReservationAsync(
64+
String project, String zone, String instanceName,
65+
String machineTypeName, String sourceImage, long diskSizeGb, String networkName)
66+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
67+
String machineType = String.format("zones/%s/machineTypes/%s", zone, machineTypeName);
68+
69+
// Initialize client that will be used to send requests. This client only needs to be created
70+
// once, and can be reused for multiple requests.
71+
try (InstancesClient instancesClient = InstancesClient.create()) {
72+
AttachedDisk disk =
73+
AttachedDisk.newBuilder()
74+
.setBoot(true)
75+
.setAutoDelete(true)
76+
.setType(AttachedDisk.Type.PERSISTENT.toString())
77+
.setDeviceName("disk-1")
78+
.setInitializeParams(
79+
AttachedDiskInitializeParams.newBuilder()
80+
.setSourceImage(sourceImage)
81+
.setDiskSizeGb(diskSizeGb)
82+
.build())
83+
.build();
84+
85+
NetworkInterface networkInterface = NetworkInterface.newBuilder()
86+
.setName(networkName)
87+
.build();
88+
89+
ReservationAffinity reservationAffinity =
90+
ReservationAffinity.newBuilder()
91+
.setConsumeReservationType(NO_RESERVATION.toString())
92+
.build();
93+
94+
Instance instanceResource =
95+
Instance.newBuilder()
96+
.setName(instanceName)
97+
.setMachineType(machineType)
98+
.addDisks(disk)
99+
.addNetworkInterfaces(networkInterface)
100+
.setReservationAffinity(reservationAffinity)
101+
.build();
102+
103+
InsertInstanceRequest insertInstanceRequest = InsertInstanceRequest.newBuilder()
104+
.setProject(project)
105+
.setZone(zone)
106+
.setInstanceResource(instanceResource)
107+
.build();
108+
109+
OperationFuture<Operation, Operation> operation = instancesClient.insertAsync(
110+
insertInstanceRequest);
111+
112+
// Wait for the operation to complete.
113+
Operation response = operation.get(3, TimeUnit.MINUTES);
114+
115+
if (response.hasError()) {
116+
return null;
117+
}
118+
return instancesClient.get(project, zone, instanceName);
119+
}
120+
}
121+
}
122+
// [END compute_instance_not_consume_reservation]

0 commit comments

Comments
 (0)