Skip to content

Commit 5cb6ee5

Browse files
jaycee-licopybara-github
authored andcommitted
docs: Update examples and README after removing checked exceptions
PiperOrigin-RevId: 743335710
1 parent cad9eba commit 5cb6ee5

22 files changed

+31
-93
lines changed

README.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,9 @@ package <your package name>;
9393

9494
import com.google.genai.Client;
9595
import com.google.genai.types.GenerateContentResponse;
96-
import java.io.IOException;
97-
import org.apache.http.HttpException;
9896

9997
public class GenerateContentWithTextInput {
100-
public static void main(String[] args) throws IOException, HttpException {
98+
public static void main(String[] args) {
10199
// Instantiate the client. The client by default uses the Gemini API. It gets
102100
// the API key from the environment variable `GOOGLE_API_KEY`.
103101
Client client = new Client();
@@ -121,11 +119,9 @@ import com.google.genai.Client;
121119
import com.google.genai.types.Content;
122120
import com.google.genai.types.GenerateContentResponse;
123121
import com.google.genai.types.Part;
124-
import java.io.IOException;
125-
import org.apache.http.HttpException;
126122

127123
public class GenerateContentWithImageInput {
128-
public static void main(String[] args) throws IOException, HttpException {
124+
public static void main(String[] args) {
129125
// Instantiate the client using Vertex API. The client gets the project and location from the
130126
// environment variables `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION`.
131127
Client client = Client.builder().vertexAI(true).build();
@@ -153,11 +149,9 @@ package <your package name>;
153149
import com.google.genai.Client;
154150
import com.google.genai.ResponseStream;
155151
import com.google.genai.types.GenerateContentResponse;
156-
import java.io.IOException;
157-
import org.apache.http.HttpException;
158152

159153
public class StreamGeneration {
160-
public static void main(String[] args) throws IOException, HttpException {
154+
public static void main(String[] args) {
161155
// Instantiate the client using Vertex API. The client gets the project and location from the
162156
// environment variables `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION`.
163157
Client client = Client.builder().vertexAI(true).build();
@@ -187,12 +181,10 @@ package <your package name>;
187181

188182
import com.google.genai.Client;
189183
import com.google.genai.types.GenerateContentResponse;
190-
import java.io.IOException;
191184
import java.util.concurrent.CompletableFuture;
192-
import org.apache.http.HttpException;
193185

194186
public class GenerateContentAsync {
195-
public static void main(String[] args) throws IOException, HttpException {
187+
public static void main(String[] args) {
196188
// Instantiates the client using Gemini API, and sets the API key in the builder.
197189
Client client = Client.builder().apiKey("your-api-key").build();
198190

@@ -226,11 +218,9 @@ import com.google.genai.types.GoogleSearch;
226218
import com.google.genai.types.Part;
227219
import com.google.genai.types.SafetySetting;
228220
import com.google.genai.types.Tool;
229-
import java.io.IOException;
230-
import org.apache.http.HttpException;
231221

232222
public class GenerateContentWithConfigs {
233-
public static void main(String[] args) throws IOException, HttpException {
223+
public static void main(String[] args) {
234224
Client client = new Client();
235225

236226
// Sets the safety settings in the config.
@@ -280,11 +270,9 @@ import com.google.genai.Client;
280270
import com.google.genai.types.GenerateContentConfig;
281271
import com.google.genai.types.GenerateContentResponse;
282272
import com.google.genai.types.Schema;
283-
import java.io.IOException;
284-
import org.apache.http.HttpException;
285273

286274
public class GenerateContentWithSchema {
287-
public static void main(String[] args) throws IOException, HttpException {
275+
public static void main(String[] args) {
288276
Client client = new Client();
289277

290278
Schema schema =

examples/src/main/java/com/google/genai/examples/EditImageControlReference.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@
4747
import com.google.genai.types.GenerateImagesResponse;
4848
import com.google.genai.types.Image;
4949
import com.google.genai.types.ReferenceImage;
50-
import java.io.IOException;
5150
import java.util.ArrayList;
52-
import org.apache.http.HttpException;
5351

5452
/** An example of using the Unified Gen AI Java SDK to edit an image (Control reference). */
5553
public class EditImageControlReference {
56-
public static void main(String[] args) throws IOException, HttpException {
54+
public static void main(String[] args) {
5755
// Instantiates the client using Vertex AI, and sets the project and location in the builder.
5856
Client client =
5957
Client.builder()

examples/src/main/java/com/google/genai/examples/EditImageMaskReference.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,25 @@
3333
*
3434
* <p>2. Compile the java package and run the sample code.
3535
*
36-
* <p>mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.EditImage"
36+
* <p>mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.EditImageMaskReference"
3737
*/
3838
package com.google.genai.examples;
3939

4040
import com.google.genai.Client;
41-
import com.google.genai.types.GenerateImagesConfig;
42-
import com.google.genai.types.GenerateImagesResponse;
4341
import com.google.genai.types.EditImageConfig;
4442
import com.google.genai.types.EditImageResponse;
43+
import com.google.genai.types.GenerateImagesConfig;
44+
import com.google.genai.types.GenerateImagesResponse;
4545
import com.google.genai.types.Image;
4646
import com.google.genai.types.MaskReferenceConfig;
4747
import com.google.genai.types.MaskReferenceImage;
4848
import com.google.genai.types.RawReferenceImage;
4949
import com.google.genai.types.ReferenceImage;
50-
import com.google.genai.types.StyleReferenceImage;
51-
import com.google.genai.types.StyleReferenceConfig;
52-
import com.google.genai.types.SubjectReferenceConfig;
53-
import com.google.genai.types.SubjectReferenceImage;
54-
import java.io.IOException;
5550
import java.util.ArrayList;
56-
import org.apache.http.HttpException;
5751

5852
/** An example of using the Unified Gen AI Java SDK to edit an image (Mask reference). */
5953
public class EditImageMaskReference {
60-
public static void main(String[] args) throws IOException, HttpException {
54+
public static void main(String[] args) {
6155
// Instantiates the client using Vertex AI, and sets the project and location in the builder.
6256
Client client =
6357
Client.builder()

examples/src/main/java/com/google/genai/examples/EditImageStyleTransfer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@
4747
import com.google.genai.types.ReferenceImage;
4848
import com.google.genai.types.StyleReferenceConfig;
4949
import com.google.genai.types.StyleReferenceImage;
50-
import java.io.IOException;
5150
import java.util.ArrayList;
52-
import org.apache.http.HttpException;
5351

5452
/** An example of using the Unified Gen AI Java SDK to edit an image (Style transfer). */
5553
public class EditImageStyleTransfer {
56-
public static void main(String[] args) throws IOException, HttpException {
54+
public static void main(String[] args) {
5755
// Instantiates the client using Vertex AI, and sets the project and location in the builder.
5856
Client client =
5957
Client.builder()

examples/src/main/java/com/google/genai/examples/EditImageSubjectReference.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@
4747
import com.google.genai.types.ReferenceImage;
4848
import com.google.genai.types.SubjectReferenceConfig;
4949
import com.google.genai.types.SubjectReferenceImage;
50-
import java.io.IOException;
5150
import java.util.ArrayList;
52-
import org.apache.http.HttpException;
5351

5452
/** An example of using the Unified Gen AI Java SDK to edit an image (Subject reference). */
5553
public class EditImageSubjectReference {
56-
public static void main(String[] args) throws IOException, HttpException {
54+
public static void main(String[] args) {
5755
// Instantiates the client using Vertex AI, and sets the project and location in the builder.
5856
Client client =
5957
Client.builder()

examples/src/main/java/com/google/genai/examples/GenerateContent.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@
3939

4040
import com.google.genai.Client;
4141
import com.google.genai.types.GenerateContentResponse;
42-
import java.io.IOException;
43-
import org.apache.http.HttpException;
4442

4543
/** An example of using the Unified Gen AI Java SDK to generate content. */
4644
public class GenerateContent {
47-
public static void main(String[] args) throws IOException, HttpException {
45+
public static void main(String[] args) {
4846
// Instantiate the client. The client by default uses the Gemini Developer API. It gets the API
4947
// key from the environment variable `GOOGLE_API_KEY`.
5048
Client client = new Client();

examples/src/main/java/com/google/genai/examples/GenerateContentAsync.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@
3939

4040
import com.google.genai.Client;
4141
import com.google.genai.types.GenerateContentResponse;
42-
import java.io.IOException;
4342
import java.util.concurrent.CompletableFuture;
44-
import org.apache.http.HttpException;
4543

4644
/** An example of using the Unified Gen AI Java SDK to generate content asynchronously. */
4745
public class GenerateContentAsync {
48-
public static void main(String[] args) throws IOException, HttpException {
46+
public static void main(String[] args) {
4947
// Instantiates the client using Gemini Developer API, and sets the API key in the builder.
5048
Client client = Client.builder().apiKey(System.getenv("GOOGLE_API_KEY")).build();
5149

examples/src/main/java/com/google/genai/examples/GenerateContentStream.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@
4040
import com.google.genai.Client;
4141
import com.google.genai.ResponseStream;
4242
import com.google.genai.types.GenerateContentResponse;
43-
import java.io.IOException;
44-
import org.apache.http.HttpException;
4543

4644
/** An example of using the Unified GenAI Java SDK to generate stream of content. */
4745
public class GenerateContentStream {
48-
public static void main(String[] args) throws IOException, HttpException {
46+
public static void main(String[] args) {
4947
// Instantiate the client using Vertex API. The client gets the project and location from the
5048
// environment variables `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION`.
5149
Client client = Client.builder().vertexAI(true).build();

examples/src/main/java/com/google/genai/examples/GenerateContentWithConfigs.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@
4848
import com.google.genai.types.Part;
4949
import com.google.genai.types.SafetySetting;
5050
import com.google.genai.types.Tool;
51-
import java.io.IOException;
52-
import org.apache.http.HttpException;
5351

5452
/** An example of using the Unified Gen AI Java SDK to generate content with extra configs. */
5553
public class GenerateContentWithConfigs {
56-
public static void main(String[] args) throws IOException, HttpException {
54+
public static void main(String[] args) {
5755
// Instantiate the client using Gemini Developer API.
5856
Client client = new Client();
5957

examples/src/main/java/com/google/genai/examples/GenerateContentWithFunctionCall.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@
4545
import com.google.genai.types.GenerateContentConfig;
4646
import com.google.genai.types.GenerateContentResponse;
4747
import com.google.genai.types.Schema;
48-
import java.io.IOException;
49-
import org.apache.http.HttpException;
5048

5149
/** An example of using the Unified Gen AI Java SDK to generate content with function calling. */
5250
public class GenerateContentWithFunctionCall {
53-
public static void main(String[] args) throws IOException, HttpException {
51+
public static void main(String[] args) {
5452
// Instantiate the client using Gemini Developer API.
5553
Client client = new Client();
5654

0 commit comments

Comments
 (0)