@@ -31,17 +31,17 @@ public static void main(String[] args) throws Exception {
3131 );
3232 genAi .listModels ()
3333 .forEach (System .out ::println );
34- System .out .println ("-----" );
34+ System .out .println ("----- Get Model " );
3535 System .out .println (
3636 genAi .getModel (ModelVariant .GEMINI_1_0_PRO )
3737 );
3838
39- System .out .println ("-----" );
39+ System .out .println ("----- Generate content (blocking) " );
4040 var model = GenerativeModel .builder ()
4141 .modelName (ModelVariant .GEMINI_1_0_PRO )
4242 .addContent (new Content .TextContent (
4343 Content .Role .USER .roleName (),
44- "Write a 300 word story about a magic backpack."
44+ "Write a 50 word story about a magic backpack."
4545 ))
4646 .addSafetySetting (SafetySetting .of (
4747 SafetySetting .HarmCategory .HARM_CATEGORY_DANGEROUS_CONTENT ,
@@ -61,8 +61,28 @@ public static void main(String[] args) throws Exception {
6161 .thenAccept (System .out ::println )
6262 .get (20 , TimeUnit .SECONDS );
6363
64- System .out .println ("-----" );
64+ System .out .println ("----- Generate content (streaming) " );
6565 genAi .generateContentStream (model )
6666 .forEach (System .out ::println );
67+
68+
69+ System .out .println ("----- multi turn chat" );
70+ GenerativeModel chatModel = GenerativeModel .builder ()
71+ .modelName (ModelVariant .GEMINI_1_0_PRO )
72+ .addContent (new Content .TextContent (
73+ Content .Role .USER .roleName (),
74+ "Write the first line of a story about a magic backpack."
75+ ))
76+ .addContent (new Content .TextContent (
77+ Content .Role .MODEL .roleName (),
78+ "In the bustling city of Meadow brook, lived a young girl named Sophie. She was a bright and curious soul with an imaginative mind."
79+ ))
80+ .addContent (new Content .TextContent (
81+ Content .Role .USER .roleName (),
82+ "Can you set it in a quiet village in 1600s France? Max 30 words"
83+ ))
84+ .build ();
85+ genAi .generateContentStream (chatModel )
86+ .forEach (System .out ::println );
6787 }
6888}
0 commit comments