File tree Expand file tree Collapse file tree 3 files changed +10
-8
lines changed
main/java/genai/text_generation
test/java/genai/text_generation Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 3636 </dependency >
3737 </dependencies >
3838 </dependencyManagement >
39- <!-- [START googlegenaisdk_install_with_bom] -->
4039 <dependencies >
4140 <dependency >
4241 <groupId >com.google.genai</groupId >
4342 <artifactId >google-genai</artifactId >
43+ <version >0.2.0</version >
4444 </dependency >
45- <!-- [END googlegenaisdk_install_with_bom] -->
4645 <dependency >
4746 <groupId >junit</groupId >
4847 <artifactId >junit</artifactId >
Original file line number Diff line number Diff line change 1717package genai .text_generation ;
1818
1919// [START googlegenaisdk_textgen_with_txt]
20+
2021import com .google .genai .Client ;
2122import com .google .genai .types .GenerateContentResponse ;
2223import java .io .IOException ;
2324import org .apache .http .HttpException ;
2425
2526public class TextGeneration {
27+
2628 public static void main (String [] args ) throws IOException , HttpException {
2729 // TODO(Developer): Replace the below variables before running the sample.
2830 String modelId = "gemini-2.0-flash-001" ;
2931 String prompt = "How does AI work?" ;
3032 generateContent (modelId , prompt );
3133 }
3234
33- public static String generateContent (String modelId , String prompt ) throws HttpException , IOException {
35+ public static String generateContent (String modelId , String prompt )
36+ throws HttpException , IOException {
3437 // Initialize client that will be used to send requests. This client only needs to be created
3538 // once, and can be reused for multiple requests.
3639 try (Client client = new Client ()) {
Original file line number Diff line number Diff line change 3131@ RunWith (JUnit4 .class )
3232public class TextGenerationIT {
3333
34- private String MODEL_ID = "gemini-2.0-flash-001" ;
34+ private final String MODEL_ID = "gemini-2.0-flash-001" ;
3535
3636 // Check if the required environment variables are set.
3737 public static void requireEnvVar (String envVarName ) {
@@ -42,10 +42,10 @@ public static void requireEnvVar(String envVarName) {
4242
4343 @ BeforeClass
4444 public static void setUp () {
45- requireEnvVar ("GOOGLE_APPLICATION_CREDENTIALS" );
46- requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
47- requireEnvVar ("GOOGLE_CLOUD_LOCATION" );
48- requireEnvVar ("GOOGLE_GENAI_USE_VERTEXAI" );
45+ requireEnvVar ("GOOGLE_APPLICATION_CREDENTIALS" );
46+ requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
47+ requireEnvVar ("GOOGLE_CLOUD_LOCATION" );
48+ requireEnvVar ("GOOGLE_GENAI_USE_VERTEXAI" );
4949 }
5050
5151 @ Test
You can’t perform that action at this time.
0 commit comments