Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@
</dependency>
</dependencies>
</project>

17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@
<artifactId>jspecify</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.18.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
Expand Down Expand Up @@ -295,6 +305,13 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<excludes>com/google/genai/gaos/**</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/com/google/genai/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import com.google.auth.oauth2.GoogleCredentials;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.genai.gaos.AsyncGenAI; // android:strip_line
import com.google.genai.gaos.GenAI; // android:strip_line
import com.google.genai.gaos.SecuritySource; // android:strip_line
import com.google.genai.gaos.utils.HasSecurity; // android:strip_line
import com.google.genai.types.ClientOptions;
import com.google.genai.types.HttpOptions;
import java.util.Optional;
Expand All @@ -43,6 +47,12 @@ public final class Async {
public final AsyncTokens authTokens;
public final AsyncTunings tunings;
public final AsyncFileSearchStores fileSearchStores;
// android:strip_begin
public final com.google.genai.gaos.AsyncInteractions interactions;
public final com.google.genai.gaos.AsyncAgents agents;
public final com.google.genai.gaos.AsyncWebhooks webhooks;

// android:strip_end

public Async(ApiClient apiClient) {
this.models = new AsyncModels(apiClient);
Expand All @@ -55,6 +65,12 @@ public Async(ApiClient apiClient) {
this.authTokens = new AsyncTokens(apiClient);
this.tunings = new AsyncTunings(apiClient);
this.fileSearchStores = new AsyncFileSearchStores(apiClient);
// android:strip_begin
AsyncGenAI asyncGaos = Client.this.gaosClient.async();
this.interactions = asyncGaos.interactions();
this.agents = asyncGaos.agents();
this.webhooks = asyncGaos.webhooks();
// android:strip_end
}
}

Expand All @@ -70,6 +86,13 @@ public Async(ApiClient apiClient) {
public final Tokens authTokens;
public final Tunings tunings;
public final FileSearchStores fileSearchStores;
// android:strip_begin
private final GenAI gaosClient;
public final com.google.genai.gaos.Interactions interactions;
public final com.google.genai.gaos.Agents agents;
public final com.google.genai.gaos.Webhooks webhooks;

// android:strip_end

/** Builder for {@link Client}. */
public static class Builder {
Expand Down Expand Up @@ -263,6 +286,7 @@ private Client(
throw new IllegalArgumentException("Gemini API does not support project/location.");
}


this.debugConfig = debugConfig.orElse(new DebugConfig());
if (this.debugConfig.clientMode().equals("replay")) {
if (!useVertexAI) {
Expand Down Expand Up @@ -311,6 +335,82 @@ private Client(
caches = new Caches(apiClient);
operations = new Operations(this.apiClient);
chats = new Chats(this.apiClient);

// android:strip_begin
GenAI.Builder gaosBuilder = GenAI.builder();
Optional<String> baseUrlOpt = this.apiClient.httpOptions().baseUrl();
Optional<String> apiVersionOpt = this.apiClient.httpOptions().apiVersion();
if (this.apiClient.vertexAI()
&& this.apiClient.project() != null
&& this.apiClient.location() != null) {
String apiVersion = apiVersionOpt.orElse("v1beta1");
String vertexLocation = this.apiClient.location();
String vertexProject = this.apiClient.project();
String host = baseUrlOpt.orElse("https://" + vertexLocation + "-aiplatform.googleapis.com");
if (host.endsWith("/")) {
host = host.substring(0, host.length() - 1);
}
String customBaseUrl = host + "/" + apiVersion + "/projects/" + vertexProject + "/locations";
gaosBuilder.serverURL(customBaseUrl);
gaosBuilder.apiVersion(vertexLocation);
} else {
baseUrlOpt.ifPresent(gaosBuilder::serverURL);
apiVersionOpt.ifPresent(gaosBuilder::apiVersion);
}
if (apiClient.credentials() != null && apiClient.credentials().getQuotaProjectId() != null) {
gaosBuilder.userProject(apiClient.credentials().getQuotaProjectId());
}
gaosBuilder.securitySource(
new SecuritySource() {
@Override
public HasSecurity getSecurity() {
com.google.genai.gaos.models.shared.Security.Builder builder =
com.google.genai.gaos.models.shared.Security.builder();
if (apiClient.apiKey() != null) {
builder.apiKey(apiClient.apiKey());
} else if (apiClient.credentials() != null) {
GoogleCredentials creds = apiClient.credentials();
try {
creds.refreshIfExpired();
} catch (Exception e) {
throw new RuntimeException("Failed to refresh credentials for GAOS client", e);
}
builder.accessToken(creds.getAccessToken().getTokenValue());
}
java.util.Map<String, String> headersMap = new java.util.HashMap<>();
apiClient.httpOptions().headers().ifPresent(headersMap::putAll);
// Api-Revision is injected by GoogleGenAIAuthHook (gaos before-request hook).
String ua = headersMap.get("user-agent");
if (ua != null) {
headersMap.put(
"user-agent",
ua.replaceAll("google-genai-sdk/1\\.[0-9]+\\.[0-9]+", "google-genai-sdk/2.0.0"));
} else {
headersMap.put(
"user-agent",
"google-genai-sdk/2.0.0 gl-java/" + System.getProperty("java.version"));
}
String xgac = headersMap.get("x-goog-api-client");
if (xgac != null) {
headersMap.put(
"x-goog-api-client",
xgac.replaceAll(
"google-genai-sdk/1\\.[0-9]+\\.[0-9]+", "google-genai-sdk/2.0.0"));
} else {
headersMap.put(
"x-goog-api-client",
"google-genai-sdk/2.0.0 gl-java/" + System.getProperty("java.version"));
}
builder.defaultHeaders(headersMap);
return builder.build();
}
});
this.gaosClient = gaosBuilder.build();
this.interactions = gaosClient.interactions();
this.agents = gaosClient.agents();
this.webhooks = gaosClient.webhooks();
// android:strip_end

async = new Async(this.apiClient);
files = new Files(this.apiClient);
authTokens = new Tokens(this.apiClient);
Expand Down
Loading
Loading