Available models
GemAI provides three Gemini model options through theAIModel enum:
UserConfig.kt
Gemini 2.0 Flash (Experimental)
Model name:
gemini-2.0-flash-expThe latest experimental version with cutting-edge features. Best for testing new capabilities and getting early access to improvements.Gemini 1.5 Flash
Model name:
gemini-1.5-flashThe default model optimized for speed and efficiency. Ideal for most chat applications with fast response times and lower costs.This is the default model used by GemAI. It provides the best balance between performance and quality for everyday conversations.
Gemini 1.5 Pro
Model name:
gemini-1.5-pro-latestThe most capable model with enhanced reasoning and understanding. Best for complex tasks requiring deeper analysis and more nuanced responses.Selecting a model
You can configure the model using theModelBuilder.setModel() method:
ModelBuilder.kt
setModel() method accepts a string parameter:
ModelBuilder.kt
Persisting model selection
GemAI persists your model selection in DataStore so it remains active across app sessions:DatastoreRepositoryImpl.kt
DatastoreRepositoryImpl.kt
Generation configuration
Beyond selecting a model, you can fine-tune its behavior using generation parameters. TheModelBuilder provides a setConfig() method:
ModelBuilder.kt
Default configuration
GemAI uses these default generation settings:ModelBuilder.kt
Configuration parameters
Controls randomness in responses. Lower values (0.0-0.5) make output more focused and deterministic. Higher values (0.5-2.0) increase creativity and randomness.
Controls diversity via nucleus sampling. The model considers tokens with cumulative probability up to this value. Range: 0.0 to 1.0.
Limits the number of highest probability tokens to consider. Lower values make responses more focused, higher values add variety.
Strings that signal the model to stop generating. Useful for controlling response length and format.
Custom configuration example
Here’s how to customize generation settings for different use cases:Building the model
After configuration, callbuild() to create the GenerativeModel instance:
ModelBuilder.kt
The
build() method validates that both apiKey and modelName are not blank before creating the model instance.Choosing the right model
Use this guide to select the appropriate model:| Use case | Recommended model | Why |
|---|---|---|
| Quick chat responses | Gemini 1.5 Flash | Fastest response times, lowest cost |
| Complex reasoning | Gemini 1.5 Pro | Better at multi-step logic and analysis |
| Testing new features | Gemini 2.0 Flash Exp | Access to latest capabilities |
| Production apps | Gemini 1.5 Flash or Pro | Stable, well-tested models |