Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phase 1 #9

Merged
merged 6 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEMINI_API_KEY=AIzaSyBk4YjBizGHvRY2EPWHvGVyvVIMT2giW4w
14 changes: 4 additions & 10 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@ jobs:
- name: Start WireMock
run: java -jar wiremock-standalone-3.8.0.jar --port 8080 &
- name: Build with Maven
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: mvn -B package --file ${{ env.POM_FILE }}
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
- name: Deploy Javadoc to GitHub Pages
uses: MathieuSoysal/Javadoc-publisher.yml@v2.5.0
with:
java-version: '11'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
javadoc-branch: gh-pages
target-folder: javadocs
javadoc-source-folder: target/site/apidocs
- name: Deploy website to GitHub Pages
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs
publish_dir: ./target/site/apidocs
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@ buildNumber.properties

# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar

.env
2 changes: 1 addition & 1 deletion GENERATE_CONTENT_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ be configurable for every model.
#### Fields

* **`stopSequences[]` string**: Optional. The set of character sequences (up to
5) that will stop output generation. If specified, the API will stop at the
1) that will stop output generation. If specified, the API will stop at the
first appearance of a stop sequence. The stop sequence will not be
included as
part of the response.
Expand Down
201 changes: 121 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
## Gemini4J: A Java Library for the Google Gemini API

Gemini4J is a powerful and intuitive Java library that empowers developers to seamlessly integrate the advanced capabilities of the Google Gemini API into their applications. With Gemini4J, you can unlock the potential of Gemini's state-of-the-art artificial intelligence to generate text, translate languages, create diverse creative content, and obtain informative answers to your questions.
Gemini4J is a powerful and intuitive Java library that empowers developers to
seamlessly integrate the advanced capabilities of the Google Gemini API into
their applications. With Gemini4J, you can unlock the potential of Gemini's
state-of-the-art artificial intelligence to generate text, translate languages,
create diverse creative content, and obtain informative answers to your
questions.

**Key Features of Google Gemini:**

* **Advanced Text Generation:** Gemini is a cutting-edge language model capable of generating natural and creative text in various styles and formats. It can adapt to different writing styles, tones, and complexities, making it ideal for tasks ranging from writing stories and poems to crafting marketing copy and technical documentation.
* **Natural Language Understanding:** Gemini possesses a deep understanding of human language, enabling it to comprehend complex questions, translate languages accurately, and generate contextually relevant content. This makes it suitable for applications like chatbots, question answering systems, and content summarization.
* **Creative and Informative Content:** Gemini can be used to create a wide range of content, including stories, poems, articles, emails, and much more. It can also provide informative summaries and answer questions based on its vast knowledge base, making it a valuable tool for research, education, and entertainment.
* **Flexibility and Customization:** The Gemini API offers customization options to fine-tune the model's behavior. Parameters like temperature and top-k sampling allow developers to control the level of creativity and randomness in the responses, tailoring the output to specific application needs.
* **Advanced Text Generation:** Gemini is a cutting-edge language model capable
of generating natural and creative text in various styles and formats. It can
adapt to different writing styles, tones, and complexities, making it ideal
for tasks ranging from writing stories and poems to crafting marketing copy
and technical documentation.
* **Natural Language Understanding:** Gemini possesses a deep understanding of
human language, enabling it to comprehend complex questions, translate
languages accurately, and generate contextually relevant content. This makes
it suitable for applications like chatbots, question answering systems, and
content summarization.
* **Creative and Informative Content:** Gemini can be used to create a wide
range of content, including stories, poems, articles, emails, and much more.
It can also provide informative summaries and answer questions based on its
vast knowledge base, making it a valuable tool for research, education, and
entertainment.
* **Flexibility and Customization:** The Gemini API offers customization options
to fine-tune the model's behavior. Parameters like temperature and top-k
sampling allow developers to control the level of creativity and randomness in
the responses, tailoring the output to specific application needs.

**Gemini4J Simplifies Integration with the Gemini API by Providing:**

* **Abstraction of API Complexity:** Gemini4J encapsulates the underlying complexities of HTTP communication and JSON serialization, allowing developers to focus on their application logic without needing to delve into low-level details.
* **Intuitive and Easy-to-Use Interface:** Gemini4J provides a high-level interface for interacting with the Gemini API resources, making integration quick and straightforward. This simplifies the process of leveraging Gemini's capabilities, reducing development time and effort.
* **Support for Key Gemini Features:** Gemini4J offers support for key Gemini features, including text generation, embedding generation, listing available models, and more. This allows developers to access a wide range of Gemini's capabilities through a unified and consistent API.
* **Abstraction of API Complexity:** Gemini4J encapsulates the underlying
complexities of HTTP communication and JSON serialization, allowing developers
to focus on their application logic without needing to delve into low-level
details.
* **Intuitive and Easy-to-Use Interface:** Gemini4J provides a high-level
interface for interacting with the Gemini API resources, making integration
quick and straightforward. This simplifies the process of leveraging Gemini's
capabilities, reducing development time and effort.
* **Support for Key Gemini Features:** Gemini4J offers support for key Gemini
features, including text generation, embedding generation, listing available
models, and more. This allows developers to access a wide range of Gemini's
capabilities through a unified and consistent API.

**Example Usage:**

Expand All @@ -30,90 +59,102 @@ import com.enovka.gemini4j.resource.spec.ModelResource;
public class SimpleExample {

public static void main(String[] args) {
// Replace with your actual API key
String apiKey = "API-KEY";

// Create a GeminiClient
GeminiClient client = GeminiClientBuilder.builder()
.withApiKey(apiKey)
.withModel(
"gemini-1.5-flash-001") // Set the desired Gemini model
.build();

// Create a GenerationResource
GenerationResource generationResource = ResourceBuilder.builder(client)
.buildGenerationResource();

// Example 1: Simple text generation with system instructions
GenerateContentRequest request1 = GenerateContentRequestBuilder.builder(
generationResource.getGeminiClient())
.withUserInput(
"Write a short story about a cat who goes on an adventure.") // User input prompt
.withSystemInstructions(
"Make it a humorous story with a happy ending.") // System-level instructions for the model
.withGenerationConfig()
.withTemperature(
0.7) // Controls the randomness of the output (higher = more random)
.withMaxOutputTokens(
200) // Limits the maximum number of tokens in the generated response
.and()
.build();

// Example 2: Text generation with safety settings
GenerateContentRequest request2 = GenerateContentRequestBuilder.builder(
generationResource.getGeminiClient())
.withUserInput("Tell me a joke.") // User input prompt
.withSafetySetting()
.withCategory(HarmCategoryEnum.HARM_CATEGORY_DANGEROUS_CONTENT)
.withThreshold(HarmBlockThresholdEnum.BLOCK_MEDIUM_AND_ABOVE)
.and()
.build();

// Example 3: Text generation with multiple candidates
GenerateContentRequest request3 = GenerateContentRequestBuilder.builder(
generationResource.getGeminiClient())
.withUserInput(
"Give me three ideas for a birthday party.") // User input prompt
.withGenerationConfig()
.withCandidateCount(
1) // Request 1 different response candidates
.and()
.build();

// Execute the requests and print the generated text
try {
GeminiResult result1 = generationResource.generateContent(request1);
System.out.println("Example 1 - Generated Text: "
+ result1.getGeneratedText());

GeminiResult result2 = generationResource.generateContent(request2);
System.out.println("Example 2 - Generated Text: "
+ result2.getGeneratedText());

GeminiResult result3 = generationResource.generateContent(request3);
System.out.println("Example 3 - Generated Text: "
+ result3.getGeneratedText());

} catch (GeminiApiException | JsonException | HttpException e) {
e.printStackTrace();
}
// Replace with your actual API key
String apiKey = "API-KEY";

// Create a GeminiClient
GeminiClient client = GeminiClientBuilder.builder()
.withApiKey(apiKey)
.withModel(
"gemini-1.5-flash-001") // Set the desired Gemini model
.build();

// Create a GenerationResource
GenerationResource generationResource = ResourceBuilder.builder(client)
.buildGenerationResource();

// Example 1: Simple text generation with system instructions
GenerateContentRequest request1 = GenerateContentRequestBuilder.builder(
generationResource.getGeminiClient())
.withUserInput(
"Write a short story about a cat who goes on an adventure.") // User input prompt
.withSystemInstructions(
"Make it a humorous story with a happy ending.") // System-level instructions for the model
.withGenerationConfig()
.withTemperature(
0.7) // Controls the randomness of the output (higher = more random)
.withMaxOutputTokens(
200) // Limits the maximum number of tokens in the generated response
.and()
.build();

// Example 2: Text generation with safety settings
GenerateContentRequest request2 = GenerateContentRequestBuilder.builder(
generationResource.getGeminiClient())
.withUserInput("Tell me a joke.") // User input prompt
.withSafetySetting()
.withCategory(HarmCategoryEnum.HARM_CATEGORY_DANGEROUS_CONTENT)
.withThreshold(HarmBlockThresholdEnum.BLOCK_MEDIUM_AND_ABOVE)
.and()
.build();

// Example 3: Text generation with multiple candidates
GenerateContentRequest request3 = GenerateContentRequestBuilder.builder(
generationResource.getGeminiClient())
.withUserInput(
"Give me three ideas for a birthday party.") // User input prompt
.withGenerationConfig()
.withCandidateCount(
1) // Request 1 different response candidates
.and()
.build();

// Execute the requests and print the generated text
try {
GeminiResult result1 = generationResource.generateContent(request1);
System.out.println("Example 1 - Generated Text: "
+ result1.getGeneratedText());

GeminiResult result2 = generationResource.generateContent(request2);
System.out.println("Example 2 - Generated Text: "
+ result2.getGeneratedText());

GeminiResult result3 = generationResource.generateContent(request3);
System.out.println("Example 3 - Generated Text: "
+ result3.getGeneratedText());

} catch (GeminiApiException e) {
e.printStackTrace();
}
}
}
```

## Gemini4J Roadmap: Version 1.0.0

This roadmap outlines the key milestones for the initial release of Gemini4J, focusing on providing a comprehensive and robust set of features for interacting with the Google Gemini API.
This roadmap outlines the key milestones for the initial release of Gemini4J,
focusing on providing a comprehensive and robust set of features for interacting
with the Google Gemini API.

### Phase 1: Core Functionality and Essential Resources

* **Complete `GenerationResource`:**
* ~~Implement all remaining methods of the `GenerationResource` interface, providing full coverage of the content generation capabilities offered by the Gemini API.~~
* **Crucial Feature:** Implement **incremental conversation support**, enabling developers to build conversational experiences by maintaining context across multiple interactions with the API.
* ~~Implement all remaining methods of the `GenerationResource` interface,
providing full coverage of the content generation capabilities offered by
the Gemini API.~~
* **Crucial Feature:** Implement **incremental conversation support**,
enabling developers to build conversational experiences by maintaining
context across multiple interactions with the API.
* **Enhance `ModelResource`:**
* ~~Add the `getModel()` method to the `ModelResource` interface, allowing developers to retrieve detailed information about specific Gemini models.~~
* ~~Add the `getModel()` method to the `ModelResource` interface, allowing
developers to retrieve detailed information about specific Gemini
models.~~
* **Implement `EmbedResource`:**
* ~~Create a new `EmbedResource` interface and its corresponding implementation to expose the embedding functionalities of the Gemini API. This will allow developers to generate embeddings for text and content, enabling various downstream tasks like semantic search and similarity comparisons.~~
* ~~Create a new `EmbedResource` interface and its corresponding
implementation to expose the embedding functionalities of the Gemini API.
This will allow developers to generate embeddings for text and content,
enabling various downstream tasks like semantic search and similarity
comparisons.~~

### Phase 2: Advanced Features and Usability Enhancements

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.enovka</groupId>
<artifactId>gemini4j</artifactId>
<version>0.0.2</version>
<version>0.0.3</version>

<name>Gemini4J</name>
<description>A powerful and easy-to-use Java library that simplifies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enovka.gemini4j.domain.type;

import lombok.Getter;

import java.util.Arrays;

/**
Expand All @@ -11,6 +13,7 @@
* @author Everson Novka &lt;enovka@gmail.com&gt;
* @since 0.0.2
*/
@Getter
public enum SupportedGenerationMethod {

/**
Expand Down Expand Up @@ -92,6 +95,11 @@ public enum SupportedGenerationMethod {
*/
GENERATE_ANSWER("generateAnswer");

/**
* -- GETTER -- Returns the string representation of the generation method.
*
* @return The string representation of the generation method.
*/
private final String value;

SupportedGenerationMethod(String value) {
Expand All @@ -113,12 +121,4 @@ public static SupportedGenerationMethod fromValue(String value) {
.orElse(null);
}

/**
* Returns the string representation of the generation method.
*
* @return The string representation of the generation method.
*/
public String getValue() {
return value;
}
}
Loading
Loading