@@ -7,7 +7,7 @@ See the documentation here: https://ai.google.dev/gemini-api
77
88# Usage
99## Dependency
10- Add the ` gemini-api ` dependency. Maven example:
10+ Add the ` gemini-api ` dependency. Maven example (replace ${gemini.version} with the latest version) :
1111
1212 <dependency>
1313 <groupId>swiss.ameri</groupId>
@@ -25,4 +25,74 @@ Alternatively, an example gson implementation can be used with the following dep
2525 <version>${gemini.version}</version>
2626 </dependency>
2727
28+ ## Example code
29+
30+ See gemini-tester for some examples.
31+
32+ JsonParser parser = new GsonJsonParser(); // or some custom implementation
33+ String apiKey = ...;
34+ GenAi genAi = new GenAi(
35+ apiKey,
36+ parser
37+ );
38+ // list available models
39+ genAi.listModels().forEach(System.out::println)
40+ // create a prompt
41+ var model = GenerativeModel.builder()
42+ .modelName(ModelVariant.GEMINI_1_0_PRO)
43+ .addContent(new Content.TextContent(
44+ Content.Role.USER.roleName(),
45+ "Write a 300 word story about a magic backpack."
46+ ))
47+ .build();
48+ // execute the prompt, wait for the full response
49+ genAi.generateContent(model)
50+ .thenAccept(System.out::println)
51+ .get(20, TimeUnit.SECONDS); // block here until the response arrives. Probably not a good idea in production code.
52+
53+ // execute the prompt, process the chunks of responses as they arrive
54+ genAi.generateContentStream(model)
55+ .forEach(System.out::println)
56+
2857# Versioning
58+ The library versioning follows the scheme:
59+ ` <gemini-api-version>.<major>.<minor>.<patch> `
60+
61+ Example:
62+ ` 1beta.0.0.1 `
63+
64+ # Requirements
65+ - > = Java 17
66+
67+ # Modules
68+ The project is composed of the following maven modules, which are deployed to maven central.
69+ ## gemini-api
70+
71+ <dependency>
72+ <groupId>swiss.ameri</groupId>
73+ <artifactId>gemini-api</artifactId>
74+ <version>${gemini.version}</version>
75+ </dependency>
76+
77+ Main module to be used. Must not contain any dependencies to other modules.
78+
79+ ## gemini-gson
80+
81+ <dependency>
82+ <groupId>swiss.ameri</groupId>
83+ <artifactId>gemini-gson</artifactId>
84+ <version>${gemini.version}</version>
85+ </dependency>
86+
87+ Provides an example implementation of the ` swiss.ameri.gemini.spi.JsonParser ` class using ` Gson ` .
88+ Contains a maven dependency to ` Gson `
89+
90+ ## gemini-tester
91+
92+ <dependency>
93+ <groupId>swiss.ameri</groupId>
94+ <artifactId>gemini-tester</artifactId>
95+ <version>${gemini.version}</version>
96+ </dependency>
97+
98+ Contains some example code of how the API can be used.
0 commit comments