Skip to content

Commit 2b534b4

Browse files
committed
Multi turn chat example
1 parent f25f5a9 commit 2b534b4

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

gemini-api/src/main/java/swiss/ameri/gemini/api/Content.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
*/
99
public sealed interface Content {
1010

11-
// todo add builder (with support for role enum)
12-
1311
/**
1412
* A part of a conversation that contains text.
1513
*

gemini-tester/src/main/java/swiss/ameri/gemini/tester/GeminiTester.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)