Skip to content

Commit 592f1c0

Browse files
matthew29tangcopybara-github
authored andcommitted
chore: Add examples folder for sample code
PiperOrigin-RevId: 890648307
1 parent 0c1eff4 commit 592f1c0

2 files changed

Lines changed: 125 additions & 0 deletions

File tree

examples/pom.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.google.cloud.vertexai.genai.examples</groupId>
7+
<artifactId>google-vertexai-examples</artifactId>
8+
<version>1.50.0-SNAPSHOT</version><!-- {x-version-update:google-cloud-vertexai:current} -->
9+
<name>google-vertexai-examples</name>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
<!-- {x-version-update:google-cloud-vertexai:current} -->
16+
<google-cloud-vertexai.version>1.50.0-SNAPSHOT</google-cloud-vertexai.version>
17+
<!-- {x-version-update-end} -->
18+
</properties>
19+
<build>
20+
<plugins>
21+
<plugin>
22+
<groupId>org.apache.maven.plugins</groupId>
23+
<artifactId>maven-compiler-plugin</artifactId>
24+
<version>3.14.0</version>
25+
<configuration>
26+
<compilerArgs>
27+
<arg>-parameters</arg>
28+
</compilerArgs>
29+
</configuration>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.codehaus.mojo</groupId>
33+
<artifactId>exec-maven-plugin</artifactId>
34+
<version>3.5.0</version>
35+
<configuration>
36+
<cleanupDaemonThreads>false</cleanupDaemonThreads>
37+
</configuration>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
42+
<dependencies>
43+
<dependency>
44+
<groupId>com.google.cloud</groupId>
45+
<artifactId>google-cloud-vertexai</artifactId>
46+
<version>${google-cloud-vertexai.version}</version>
47+
</dependency>
48+
</dependencies>
49+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2026 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+
* https://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+
/**
18+
* Usage:
19+
*
20+
* <p>1a. If you are using Vertex AI, setup ADC to get credentials:
21+
* https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
22+
*
23+
* <p>Then set Project, Location, and USE_VERTEXAI flag as environment variables:
24+
*
25+
* <p>export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
26+
*
27+
* <p>export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
28+
*
29+
* <p>2. Compile the java package and run the sample code.
30+
*
31+
* <p>mvn clean compile exec:java
32+
* -Dexec.mainClass="com.google.cloud.vertexai.genai.examples.AgentEngineCreate"
33+
*/
34+
package com.google.cloud.vertexai.genai.examples;
35+
36+
import com.google.cloud.vertexai.genai.Client;
37+
import com.google.cloud.vertexai.genai.types.AgentEngineOperation;
38+
import com.google.cloud.vertexai.genai.types.CreateAgentEngineConfig;
39+
import com.google.cloud.vertexai.genai.types.DeleteAgentEngineOperation;
40+
import com.google.common.collect.ImmutableMap;
41+
42+
/** An example of using the Java SDK to create an agent engine. */
43+
public final class AgentEngineCreate {
44+
public static void main(String[] args) {
45+
46+
// Instantiate the client. It reads from the environment variables `GOOGLE_CLOUD_LOCATION` and
47+
// `GOOGLE_CLOUD_PROJECT`.
48+
Client client = new Client();
49+
50+
CreateAgentEngineConfig config =
51+
CreateAgentEngineConfig.builder()
52+
.labels(ImmutableMap.of("test-label", "test-value"))
53+
.build();
54+
AgentEngineOperation createOperation = client.agentEngines.privateCreate(config);
55+
56+
System.out.println("Create operation name: " + createOperation.name());
57+
58+
while (!createOperation.done().filter(Boolean::booleanValue).isPresent()) {
59+
try {
60+
Thread.sleep(10000); // Sleep for 10 seconds.
61+
createOperation =
62+
client.agentEngines.privateGetAgentOperation(createOperation.name().get(), null);
63+
} catch (InterruptedException e) {
64+
Thread.currentThread().interrupt();
65+
}
66+
}
67+
System.out.println("Create operation response: " + createOperation.response());
68+
69+
// Optionally, delete to clean up resources.
70+
DeleteAgentEngineOperation deleteOperation =
71+
client.agentEngines.privateDelete(
72+
createOperation.response().get().name().get(), true, null);
73+
}
74+
75+
private AgentEngineCreate() {}
76+
}

0 commit comments

Comments
 (0)