Skip to content

Commit 776a217

Browse files
committed
publish version 1beta.0.1.0 (and adjust some javadoc warnings)
1 parent c0ea3ac commit 776a217

File tree

10 files changed

+146
-21
lines changed

10 files changed

+146
-21
lines changed

gemini-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>swiss.ameri</groupId>
88
<artifactId>gemini</artifactId>
9-
<version>1beta.0.0.1-SNAPSHOT</version>
9+
<version>1beta.0.1.0</version>
1010
</parent>
1111

1212
<artifactId>gemini-api</artifactId>

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,21 @@ record MediaContent(
7777
/**
7878
* A part of a conversation that contains text and media.
7979
*
80-
* @param role belonging to this turn in the conversation. see {@link Role}
80+
* @param role belonging to this turn in the conversation. see {@link Role}
81+
* @param text of the conversation part
82+
* @param media the medias
8183
*/
8284
record TextAndMediaContent(
8385
String role,
8486
String text,
8587
List<MediaData> media
8688
) implements Content {
89+
90+
/**
91+
* Create a {@link TextAndMediaContentBuilder}.
92+
*
93+
* @return a new builder
94+
*/
8795
public static TextAndMediaContentBuilder builder() {
8896
return new TextAndMediaContentBuilder();
8997
}
@@ -168,9 +176,17 @@ record MediaData(
168176
) {
169177
}
170178

171-
179+
/**
180+
* The producer of the content. Mainly relevant for multi turn conversations.
181+
*/
172182
enum Role {
183+
/**
184+
* Content by user.
185+
*/
173186
USER,
187+
/**
188+
* Content by model.
189+
*/
174190
MODEL;
175191

176192
private final String roleName;
@@ -179,6 +195,11 @@ enum Role {
179195
this.roleName = name().toLowerCase(Locale.ROOT);
180196
}
181197

198+
/**
199+
* Role name for the api
200+
*
201+
* @return Role name for the api
202+
*/
182203
public String roleName() {
183204
return roleName;
184205
}

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

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public class GenAi implements AutoCloseable {
3737
private final JsonParser jsonParser;
3838
private final Map<UUID, GenerateContentResponse> responseById = new ConcurrentHashMap<>();
3939

40+
/**
41+
* Create a new instance with a default {@link HttpClient}
42+
*
43+
* @param apiKey to be used for all communications with Gemini API
44+
* @param jsonParser used to (de-)serialize JSON objects
45+
*/
4046
public GenAi(
4147
String apiKey,
4248
JsonParser jsonParser
@@ -48,6 +54,13 @@ public GenAi(
4854
);
4955
}
5056

57+
/**
58+
* Create a new instance
59+
*
60+
* @param apiKey to be used for all communications with Gemini API
61+
* @param jsonParser used to (de-)serialize JSON objects
62+
* @param client a custom {@link HttpClient} for communication with Gemini API
63+
*/
5164
public GenAi(
5265
String apiKey,
5366
JsonParser jsonParser,
@@ -60,6 +73,8 @@ public GenAi(
6073

6174
/**
6275
* List models that are currently available.
76+
*
77+
* @return available models
6378
*/
6479
public List<Model> listModels() {
6580
return execute(() -> {
@@ -80,6 +95,7 @@ public List<Model> listModels() {
8095
* Get information of a model. Can be used to create a {@link GenerativeModel}.
8196
*
8297
* @param model of which the information is wanted.
98+
* @return information of a model
8399
* @see #listModels()
84100
*/
85101
public Model getModel(ModelVariant model) {
@@ -90,6 +106,7 @@ public Model getModel(ModelVariant model) {
90106
* Get model information.
91107
*
92108
* @param model must start with "models/"
109+
* @return information of a model
93110
*/
94111
public Model getModel(String model) {
95112
return execute(() -> {
@@ -388,7 +405,8 @@ public void close() {
388405
/**
389406
* Content generated by Gemini API.
390407
*
391-
* @param id the id of the request, for subsequent queries regarding metadata of the query
408+
* @param id the id of the request, for subsequent queries regarding metadata of the query
409+
* @param text of the generated content
392410
*/
393411
public record GeneratedContent(
394412
UUID id,
@@ -458,6 +476,59 @@ public record ContentEmbedding(
458476
) {
459477
}
460478

479+
/**
480+
* Information on a model
481+
*
482+
* @param name The resource name of the Model.
483+
* <p>
484+
* Format: models/{model} with a {model} naming convention of:
485+
* <p>
486+
* "{baseModelId}-{version}"
487+
* Examples:
488+
* <p>
489+
* models/chat-bison-001
490+
* @param baseModelId The name of the base model, pass this to the generation request.
491+
* @param version The version number of the model.
492+
* @param displayName The human-readable name of the model. E.g. "Chat Bison".
493+
* <p>
494+
* The name can be up to 128 characters long and can consist of any UTF-8 characters.
495+
* @param description A short description of the model.
496+
* @param inputTokenLimit Maximum number of input tokens allowed for this model.
497+
* @param outputTokenLimit Maximum number of output tokens available for this model.
498+
* @param supportedGenerationMethods The model's supported generation methods.
499+
* <p>
500+
* The method names are defined as Pascal case strings, such as generateMessage which correspond to API methods.
501+
* @param temperature Controls the randomness of the output.
502+
* <p>
503+
* Values can range over [0.0,2.0], inclusive.
504+
* A higher value will produce responses that are more varied,
505+
* while a value closer to 0.0 will typically result in less surprising responses from the model.
506+
* This value specifies default to be used by the backend while making the call to the model.
507+
* @param topP For Nucleus sampling.
508+
* <p>
509+
* Nucleus sampling considers the smallest set of tokens whose probability sum is at least topP.
510+
* This value specifies default to be used by the backend while making the call to the model.
511+
* @param topK For Top-k sampling.
512+
* <p>
513+
* Top-k sampling considers the set of topK most probable tokens.
514+
* This value specifies default to be used by the backend while making the call to the model.
515+
* If empty, indicates the model doesn't use top-k sampling, and topK isn't allowed as a generation parameter.
516+
*/
517+
public record Model(
518+
String name,
519+
String baseModelId,
520+
String version,
521+
String displayName,
522+
String description,
523+
int inputTokenLimit,
524+
int outputTokenLimit,
525+
List<String> supportedGenerationMethods,
526+
double temperature,
527+
double topP,
528+
int topK
529+
) {
530+
}
531+
461532
private record BatchEmbedContentRequest(
462533
List<EmbedContentRequest> requests
463534
) {
@@ -533,20 +604,6 @@ private record InlineData(
533604
private record ModelResponse(List<Model> models) {
534605
}
535606

536-
public record Model(
537-
String name,
538-
String version,
539-
String displayName,
540-
String description,
541-
int inputTokenLimit,
542-
int outputTokenLimit,
543-
List<String> supportedGenerationMethods,
544-
double temperature,
545-
double topP,
546-
int topK
547-
) {
548-
}
549-
550607
private interface ThrowingSupplier<T> {
551608
T get() throws IOException, InterruptedException;
552609
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public static class GenerativeModelBuilder {
3636
private final List<Content> contents = new ArrayList<>();
3737
private final List<SafetySetting> safetySettings = new ArrayList<>();
3838

39+
private GenerativeModelBuilder() {
40+
}
41+
3942
/**
4043
* Set the model name.
4144
*

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,25 @@
66
* @see <a href="https://ai.google.dev/gemini-api/docs/models/gemini">Gemini Models</a>
77
*/
88
public enum ModelVariant {
9+
/**
10+
* Complex reasoning tasks such as code and text generation, text editing, problem-solving, data extraction and generation.
11+
*/
912
GEMINI_1_5_PRO("gemini-1.5-pro"),
13+
/**
14+
* Fast and versatile performance across a diverse variety of tasks.
15+
*/
1016
GEMINI_1_5_FLASH("gemini-1.5-flash"),
17+
/**
18+
* Natural language tasks, multi-turn text and code chat, and code generation.
19+
*/
1120
GEMINI_1_0_PRO("gemini-1.0-pro"),
21+
/**
22+
* Visual-related tasks, like generating image descriptions or identifying objects in images.
23+
*/
1224
GEMINI_1_0_PRO_VISION("gemini-pro-vision"),
25+
/**
26+
* Measuring the relatedness of text strings.
27+
*/
1328
TEXT_EMBEDDING_004("text-embedding-004"),
1429
;
1530

@@ -19,6 +34,11 @@ public enum ModelVariant {
1934
this.variant = variant;
2035
}
2136

37+
/**
38+
* Model variant name.
39+
*
40+
* @return Model variant name as needed by Gemini API
41+
*/
2242
public String variant() {
2343
return "models/" + variant;
2444
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
/**
44
* Safety settings according to <a href="https://ai.google.dev/api/rest/v1beta/SafetySetting#harmblockthreshold">SafetySetting</a>.
5+
*
6+
* @param category the harm category, see {@link HarmCategory}
7+
* @param threshold the threshold, see {@link HarmBlockThreshold}
58
*/
69
public record SafetySetting(
710
String category,
@@ -11,6 +14,10 @@ public record SafetySetting(
1114
/**
1215
* Create a SafetySetting by using the provided enums. Use the constructor for custom string values that might
1316
* be missing in the enums.
17+
*
18+
* @param category the harm category, see {@link HarmCategory}
19+
* @param threshold the threshold, see {@link HarmBlockThreshold}
20+
* @return the new {@link SafetySetting}
1421
*/
1522
public static SafetySetting of(
1623
HarmCategory category,

gemini-api/src/main/java/swiss/ameri/gemini/spi/JsonParser.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ public interface JsonParser {
99

1010
/**
1111
* This method serializes the specified object into its equivalent JSON representation.
12+
*
13+
* @param object to be serialized
14+
* @return the serialized object
1215
*/
1316
String toJson(Object object);
1417

1518
/**
1619
* This method deserializes the specified JSON into an object of the specified class.
20+
*
21+
* @param json to be deserialized
22+
* @param clazz to be created from the json
23+
* @param <T> type of the class
24+
* @return the deserialized object
1725
*/
1826
<T> T fromJson(String json, Class<T> clazz);
1927

gemini-gson/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>swiss.ameri</groupId>
99
<artifactId>gemini</artifactId>
10-
<version>1beta.0.0.1-SNAPSHOT</version>
10+
<version>1beta.0.1.0</version>
1111
</parent>
1212

1313
<artifactId>gemini-gson</artifactId>

gemini-tester/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>swiss.ameri</groupId>
99
<artifactId>gemini</artifactId>
10-
<version>1beta.0.0.1-SNAPSHOT</version>
10+
<version>1beta.0.1.0</version>
1111
</parent>
1212
<artifactId>gemini-tester</artifactId>
1313

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>swiss.ameri</groupId>
88
<artifactId>gemini</artifactId>
9-
<version>1beta.0.0.1-SNAPSHOT</version>
9+
<version>1beta.0.1.0</version>
1010
<packaging>pom</packaging>
1111

1212
<licenses>
@@ -77,6 +77,15 @@
7777
<goals>
7878
<goal>jar</goal>
7979
</goals>
80+
<configuration>
81+
<tags>
82+
<tag>
83+
<name>apiNote</name>
84+
<placement>a</placement>
85+
<head>API Note</head>
86+
</tag>
87+
</tags>
88+
</configuration>
8089
</execution>
8190
</executions>
8291
</plugin>

0 commit comments

Comments
 (0)