Gemini Chat Model
Gemini is a simpler platform designed for a broader audience than Vertex AI Gemini, including non-technical users. It is a good first step for developers to get started with Gemini models.
Using Gemini Chat Models
To use Gemini chat models, add the following dependency to your project:
<dependency>
<groupId>io.quarkiverse.langchain4j</groupId>
<artifactId>quarkus-langchain4j-ai-gemini</artifactId>
<version>1.0.2</version>
</dependency>
If no other LLM extension is installed, AI Services will automatically utilize the configured Gemini model.
Configuration
Gemini requires an API key, which can be generated from the Gemini platform.
Set the key in your application.properties
:
quarkus.langchain4j.ai.gemini.api-key=...
Alternatively, you can set the QUARKUS_LANGCHAIN4J_AI_GEMINI_API_KEY environment variable.
|
Several configuration properties are available:
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
---|---|---|
Whether the model should be enabled Environment variable: |
boolean |
|
Whether the model should be enabled Environment variable: |
boolean |
|
The api key Environment variable: |
string |
|
Publisher of model Environment variable: |
string |
|
Meant to be used for testing only in order to override the base URL used by the client Environment variable: |
string |
|
Whether to enable the integration. Defaults to Environment variable: |
boolean |
|
Whether the Vertex AI client should log requests Environment variable: |
boolean |
|
Whether the Vertex AI client should log responses Environment variable: |
boolean |
|
Timeout for requests to gemini APIs Environment variable: |
|
|
The id of the model to use. Environment variable: |
string |
|
The temperature is used for sampling during response generation, which occurs when topP and topK are applied. Temperature controls the degree of randomness in token selection. Lower temperatures are good for prompts that require a less open-ended or creative response, while higher temperatures can lead to more diverse or creative results. A temperature of 0 means that the highest probability tokens are always selected. In this case, responses for a given prompt are mostly deterministic, but a small amount of variation is still possible. If the model returns a response that’s too generic, too short, or the model gives a fallback response, try increasing the temperature. Environment variable: |
double |
|
Maximum number of tokens that can be generated in the response. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words. Specify a lower value for shorter responses and a higher value for potentially longer responses. Environment variable: |
int |
|
Top-P changes how the model selects tokens for output. Tokens are selected from the most (see top-K) to least probable until the sum of their probabilities equals the top-P value. For example, if tokens A, B, and C have a probability of 0.3, 0.2, and 0.1 and the top-P value is 0.5, then the model will select either A or B as the next token by using temperature and excludes C as a candidate. Specify a lower value for less random responses and a higher value for more random responses. Range: 0.0 - 1.0 gemini-1.0-pro and gemini-1.5-pro don’t support topK Environment variable: |
double |
|
Top-K changes how the model selects tokens for output. A top-K of 1 means the next selected token is the most probable among all tokens in the model’s vocabulary (also called greedy decoding), while a top-K of 3 means that the next token is selected from among the three most probable tokens by using temperature. For each token selection step, the top-K tokens with the highest probabilities are sampled. Then tokens are further filtered based on top-P with the final token selected using temperature sampling. Specify a lower value for less random responses and a higher value for more random responses. Range: 1-40 Default for gemini-1.5-pro: 0.94 Default for gemini-1.0-pro: 1 Environment variable: |
int |
|
Whether chat model requests should be logged Environment variable: |
boolean |
|
Whether chat model responses should be logged Environment variable: |
boolean |
|
Global timeout for requests to gemini APIs Environment variable: |
|
|
The id of the model to use. Environment variable: |
string |
|
Reduced dimension for the output embedding Environment variable: |
int |
|
Optional task type for which the embeddings will be used. Can only be set for models/embedding-001 Possible values: TASK_TYPE_UNSPECIFIED, RETRIEVAL_QUERY, RETRIEVAL_DOCUMENT, SEMANTIC_SIMILARITY, CLASSIFICATION, CLUSTERING, QUESTION_ANSWERING, FACT_VERIFICATION Environment variable: |
string |
|
Whether chat model requests should be logged Environment variable: |
boolean |
|
Whether chat model responses should be logged Environment variable: |
boolean |
|
Global timeout for requests to gemini APIs Environment variable: |
|
|
Type |
Default |
|
The api key Environment variable: |
string |
|
Publisher of model Environment variable: |
string |
|
Meant to be used for testing only in order to override the base URL used by the client Environment variable: |
string |
|
Whether to enable the integration. Defaults to Environment variable: |
boolean |
|
Whether the Vertex AI client should log requests Environment variable: |
boolean |
|
Whether the Vertex AI client should log responses Environment variable: |
boolean |
|
Timeout for requests to gemini APIs Environment variable: |
|
|
The id of the model to use. Environment variable: |
string |
|
The temperature is used for sampling during response generation, which occurs when topP and topK are applied. Temperature controls the degree of randomness in token selection. Lower temperatures are good for prompts that require a less open-ended or creative response, while higher temperatures can lead to more diverse or creative results. A temperature of 0 means that the highest probability tokens are always selected. In this case, responses for a given prompt are mostly deterministic, but a small amount of variation is still possible. If the model returns a response that’s too generic, too short, or the model gives a fallback response, try increasing the temperature. Environment variable: |
double |
|
Maximum number of tokens that can be generated in the response. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words. Specify a lower value for shorter responses and a higher value for potentially longer responses. Environment variable: |
int |
|
Top-P changes how the model selects tokens for output. Tokens are selected from the most (see top-K) to least probable until the sum of their probabilities equals the top-P value. For example, if tokens A, B, and C have a probability of 0.3, 0.2, and 0.1 and the top-P value is 0.5, then the model will select either A or B as the next token by using temperature and excludes C as a candidate. Specify a lower value for less random responses and a higher value for more random responses. Range: 0.0 - 1.0 gemini-1.0-pro and gemini-1.5-pro don’t support topK Environment variable: |
double |
|
Top-K changes how the model selects tokens for output. A top-K of 1 means the next selected token is the most probable among all tokens in the model’s vocabulary (also called greedy decoding), while a top-K of 3 means that the next token is selected from among the three most probable tokens by using temperature. For each token selection step, the top-K tokens with the highest probabilities are sampled. Then tokens are further filtered based on top-P with the final token selected using temperature sampling. Specify a lower value for less random responses and a higher value for more random responses. Range: 1-40 Default for gemini-1.5-pro: 0.94 Default for gemini-1.0-pro: 1 Environment variable: |
int |
|
Whether chat model requests should be logged Environment variable: |
boolean |
|
Whether chat model responses should be logged Environment variable: |
boolean |
|
Global timeout for requests to gemini APIs Environment variable: |
|
|
The id of the model to use. Environment variable: |
string |
|
Reduced dimension for the output embedding Environment variable: |
int |
|
Optional task type for which the embeddings will be used. Can only be set for models/embedding-001 Possible values: TASK_TYPE_UNSPECIFIED, RETRIEVAL_QUERY, RETRIEVAL_DOCUMENT, SEMANTIC_SIMILARITY, CLASSIFICATION, CLUSTERING, QUESTION_ANSWERING, FACT_VERIFICATION Environment variable: |
string |
|
Whether chat model requests should be logged Environment variable: |
boolean |
|
Whether chat model responses should be logged Environment variable: |
boolean |
|
Global timeout for requests to gemini APIs Environment variable: |
|
About the Duration format
To write duration values, use the standard You can also use a simplified format, starting with a number:
In other cases, the simplified format is translated to the
|