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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@
import com.google.genai.gaos.models.operations.GetEnvironmentFilesRequest;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/** An example of using the Unified Gen AI Java SDK to create environments and query environment files. */
public final class EnvironmentFiles {
public static void main(String[] args) {
Client client = new Client();
com.google.genai.types.HttpOptions.Builder httpOptionsBuilder =
com.google.genai.types.HttpOptions.builder().apiVersion("v1alpha");
String baseUrl = System.getenv("GOOGLE_GENAI_BASE_URL");
if (baseUrl != null && !baseUrl.isEmpty()) {
httpOptionsBuilder.baseUrl(baseUrl);
}
Client client = Client.builder().httpOptions(httpOptionsBuilder.build()).build();

if (client.vertexAI()) {
System.out.println(
Expand Down Expand Up @@ -157,8 +164,32 @@ public static void main(String[] args) {
System.out.println("main.py file size: " + file.sizeBytes().orElse("0"));
}
});

System.out.println("\n--- 5. Uploading a New File (path=\"uploaded.txt\") ---");
byte[] contentToUpload =
"Hello from Java Environment Files upload demo!\n".getBytes(java.nio.charset.StandardCharsets.UTF_8);
com.google.genai.gaos.models.operations.UploadEnvironmentFileResponse uploadResponse =
client.environments.files().upload(
envId,
"uploaded.txt",
contentToUpload,
"text/plain",
true,
false);
System.out.println(
"Uploaded file name: "
+ uploadResponse
.files()
.flatMap(f -> f.files().flatMap(list -> list.isEmpty() ? Optional.empty() : list.get(0).name()))
.orElse("unknown"));

System.out.println("\n--- 6. Downloading File Content (path=\"uploaded.txt\") ---");
byte[] downloadedBytes = client.environments.files().download(envId, "uploaded.txt");
System.out.println(
"Downloaded uploaded.txt content: "
+ new String(downloadedBytes, java.nio.charset.StandardCharsets.UTF_8).trim());
} finally {
System.out.println("\n--- 5. Cleaning up Environment ID: " + envId + " ---");
System.out.println("\n--- 7. Cleaning up Environment ID: " + envId + " ---");
DeleteEnvironmentResponse deleteRes = client.environments.deleteEnvironment(envId);
System.out.println("Environment deleted successfully: " + deleteRes.statusCode());
}
Expand Down
370 changes: 370 additions & 0 deletions src/main/java/com/google/genai/gaos/AsyncFiles.java

Large diffs are not rendered by default.

494 changes: 489 additions & 5 deletions src/main/java/com/google/genai/gaos/Files.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
* <p>Request for `CreateEnvironment`.
*/
public class CreateEnvironmentRequest {
/**
* Optional. The source environment to copy/fork from.
* Format: `environments/{environment_id}` or `{environment_id}`.
* When specified, `sources` and `env` must be empty.
*/
@JsonInclude(Include.NON_ABSENT)
@JsonProperty("from_environment")
private String fromEnvironment;

/**
* Network configuration for the environment.
*/
Expand All @@ -53,14 +62,25 @@ public class CreateEnvironmentRequest {

@JsonCreator
public CreateEnvironmentRequest(
@JsonProperty("from_environment") @Nullable String fromEnvironment,
@JsonProperty("network") @Nullable CreateEnvironmentRequestNetworkUnion network,
@JsonProperty("sources") @Nullable List<Source> sources) {
this.fromEnvironment = fromEnvironment;
this.network = network;
this.sources = sources;
}

public CreateEnvironmentRequest() {
this(null, null);
this(null, null, null);
}

/**
* Optional. The source environment to copy/fork from.
* Format: `environments/{environment_id}` or `{environment_id}`.
* When specified, `sources` and `env` must be empty.
*/
public Optional<String> fromEnvironment() {
return Optional.ofNullable(this.fromEnvironment);
}

/**
Expand All @@ -82,6 +102,17 @@ public static Builder builder() {
}


/**
* Optional. The source environment to copy/fork from.
* Format: `environments/{environment_id}` or `{environment_id}`.
* When specified, `sources` and `env` must be empty.
*/
public CreateEnvironmentRequest withFromEnvironment(@Nullable String fromEnvironment) {
this.fromEnvironment = fromEnvironment;
return this;
}


/**
* Network configuration for the environment.
*/
Expand Down Expand Up @@ -110,26 +141,30 @@ public boolean equals(java.lang.Object o) {
}
CreateEnvironmentRequest other = (CreateEnvironmentRequest) o;
return
Utils.enhancedDeepEquals(this.fromEnvironment, other.fromEnvironment) &&
Utils.enhancedDeepEquals(this.network, other.network) &&
Utils.enhancedDeepEquals(this.sources, other.sources);
}

@Override
public int hashCode() {
return Utils.enhancedHash(
network, sources);
fromEnvironment, network, sources);
}

@Override
public String toString() {
return Utils.toString(CreateEnvironmentRequest.class,
"fromEnvironment", fromEnvironment,
"network", network,
"sources", sources);
}

@SuppressWarnings("UnusedReturnValue")
public final static class Builder {

private String fromEnvironment;

private CreateEnvironmentRequestNetworkUnion network;

private List<Source> sources;
Expand All @@ -138,6 +173,16 @@ private Builder() {
// force use of static builder() method
}

/**
* Optional. The source environment to copy/fork from.
* Format: `environments/{environment_id}` or `{environment_id}`.
* When specified, `sources` and `env` must be empty.
*/
public Builder fromEnvironment(@Nullable String fromEnvironment) {
this.fromEnvironment = fromEnvironment;
return this;
}

/**
* Network configuration for the environment.
*/
Expand All @@ -156,7 +201,7 @@ public Builder sources(@Nullable List<Source> sources) {

public CreateEnvironmentRequest build() {
return new CreateEnvironmentRequest(
network, sources);
fromEnvironment, network, sources);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@


public class FunctionResultDelta implements StepDeltaData {
/**
* Required. ID to match the ID from the function call block.
*/
@JsonProperty("call_id")
private String callId;


@JsonInclude(Include.NON_ABSENT)
@JsonProperty("is_error")
Expand All @@ -61,12 +55,9 @@ public class FunctionResultDelta implements StepDeltaData {

@JsonCreator
public FunctionResultDelta(
@JsonProperty("call_id") @Nonnull String callId,
@JsonProperty("is_error") @Nullable Boolean isError,
@JsonProperty("name") @Nullable String name,
@JsonProperty("result") @Nonnull FunctionResultDeltaResultUnion result) {
this.callId = Optional.ofNullable(callId)
.orElseThrow(() -> new IllegalArgumentException("callId cannot be null"));
this.isError = isError;
this.name = name;
this.result = Optional.ofNullable(result)
Expand All @@ -75,17 +66,8 @@ public FunctionResultDelta(
}

public FunctionResultDelta(
@Nonnull String callId,
@Nonnull FunctionResultDeltaResultUnion result) {
this(callId, null, null,
result);
}

/**
* Required. ID to match the ID from the function call block.
*/
public Optional<String> callId() {
return Optional.ofNullable(this.callId);
this(null, null, result);
}

public Optional<Boolean> isError() {
Expand All @@ -110,15 +92,6 @@ public static Builder builder() {
}


/**
* Required. ID to match the ID from the function call block.
*/
public FunctionResultDelta withCallId(@Nonnull String callId) {
this.callId = Utils.checkNotNull(callId, "callId");
return this;
}


public FunctionResultDelta withIsError(@Nullable Boolean isError) {
this.isError = isError;
return this;
Expand Down Expand Up @@ -147,7 +120,6 @@ public boolean equals(java.lang.Object o) {
}
FunctionResultDelta other = (FunctionResultDelta) o;
return
Utils.enhancedDeepEquals(this.callId, other.callId) &&
Utils.enhancedDeepEquals(this.isError, other.isError) &&
Utils.enhancedDeepEquals(this.name, other.name) &&
Utils.enhancedDeepEquals(this.result, other.result) &&
Expand All @@ -157,14 +129,13 @@ public boolean equals(java.lang.Object o) {
@Override
public int hashCode() {
return Utils.enhancedHash(
callId, isError, name,
result, type);
isError, name, result,
type);
}

@Override
public String toString() {
return Utils.toString(FunctionResultDelta.class,
"callId", callId,
"isError", isError,
"name", name,
"result", result,
Expand All @@ -174,8 +145,6 @@ public String toString() {
@SuppressWarnings("UnusedReturnValue")
public final static class Builder {

private String callId;

private Boolean isError;

private String name;
Expand All @@ -186,14 +155,6 @@ private Builder() {
// force use of static builder() method
}

/**
* Required. ID to match the ID from the function call block.
*/
public Builder callId(@Nonnull String callId) {
this.callId = Utils.checkNotNull(callId, "callId");
return this;
}

public Builder isError(@Nullable Boolean isError) {
this.isError = isError;
return this;
Expand All @@ -211,8 +172,7 @@ public Builder result(@Nonnull FunctionResultDeltaResultUnion result) {

public FunctionResultDelta build() {
return new FunctionResultDelta(
callId, isError, name,
result);
isError, name, result);
}


Expand Down
Loading
Loading