@@ -10,22 +10,45 @@ import com.google.ai.sample.feature.chat.ChatViewModel
1010import com.google.ai.sample.feature.multimodal.PhotoReasoningViewModel
1111import com.google.ai.sample.feature.text.SummarizeViewModel
1212
13+ // Model options
14+ enum class ModelOption (val displayName : String , val modelName : String ) {
15+ GEMINI_FLASH_LITE (" Gemini Flash Lite" , " gemini-2.0-flash-lite" ),
16+ GEMINI_FLASH (" Gemini Flash" , " gemini-2.0-flash" ),
17+ GEMINI_FLASH_PREVIEW (" Gemini 2.5 Flash Preview" , " gemini-2.5-flash-preview-04-17" ),
18+ GEMINI_PRO (" Gemini 2.5 Pro" , " gemini-2.5-pro-exp-03-25" )
19+ }
20+
1321val GenerativeViewModelFactory = object : ViewModelProvider .Factory {
1422 // Current selected model name
15- private var currentModelName = " gemini-2.0-flash-lite "
23+ private var currentModelName = ModelOption . GEMINI_FLASH_LITE .modelName
1624
1725 /* *
1826 * Set the model to high reasoning capability (gemini-2.5-pro-preview-03-25)
1927 */
2028 fun highReasoningModel () {
21- currentModelName = " gemini-2.5-pro-exp-03-25 "
29+ currentModelName = ModelOption . GEMINI_PRO .modelName
2230 }
2331
2432 /* *
2533 * Set the model to low reasoning capability (gemini-2.0-flash-lite)
2634 */
2735 fun lowReasoningModel () {
28- currentModelName = " gemini-2.0-flash-lite"
36+ currentModelName = ModelOption .GEMINI_FLASH_LITE .modelName
37+ }
38+
39+ /* *
40+ * Set the model to a specific model option
41+ */
42+ fun setModel (modelOption : ModelOption ) {
43+ currentModelName = modelOption.modelName
44+ }
45+
46+ /* *
47+ * Get the current model option
48+ */
49+ fun getCurrentModel (): ModelOption {
50+ return ModelOption .values().find { it.modelName == currentModelName }
51+ ? : ModelOption .GEMINI_FLASH_LITE
2952 }
3053
3154 override fun <T : ViewModel > create (
@@ -93,13 +116,13 @@ val GenerativeViewModelFactory = object : ViewModelProvider.Factory {
93116// Add companion object with static methods for easier access
94117object GenerativeAiViewModelFactory {
95118 // Current selected model name - duplicated from GenerativeViewModelFactory
96- private var currentModelName = " gemini-2.0-flash-lite "
119+ private var currentModelName = ModelOption . GEMINI_FLASH_LITE .modelName
97120
98121 /* *
99122 * Set the model to high reasoning capability (gemini-2.5-pro-preview-03-25)
100123 */
101124 fun highReasoningModel () {
102- currentModelName = " gemini-2.5-pro-exp-03-25 "
125+ currentModelName = ModelOption . GEMINI_PRO .modelName
103126 // Also update the original factory to keep them in sync
104127 (GenerativeViewModelFactory as ViewModelProvider .Factory ).apply {
105128 if (this is ViewModelProvider .Factory ) {
@@ -118,7 +141,26 @@ object GenerativeAiViewModelFactory {
118141 * Set the model to low reasoning capability (gemini-2.0-flash-lite)
119142 */
120143 fun lowReasoningModel () {
121- currentModelName = " gemini-2.0-flash-lite"
144+ currentModelName = ModelOption .GEMINI_FLASH_LITE .modelName
145+ // Also update the original factory to keep them in sync
146+ (GenerativeViewModelFactory as ViewModelProvider .Factory ).apply {
147+ if (this is ViewModelProvider .Factory ) {
148+ try {
149+ val field = this .javaClass.getDeclaredField(" currentModelName" )
150+ field.isAccessible = true
151+ field.set(this , currentModelName)
152+ } catch (e: Exception ) {
153+ // Fallback if reflection fails
154+ }
155+ }
156+ }
157+ }
158+
159+ /* *
160+ * Set the model to a specific model option
161+ */
162+ fun setModel (modelOption : ModelOption ) {
163+ currentModelName = modelOption.modelName
122164 // Also update the original factory to keep them in sync
123165 (GenerativeViewModelFactory as ViewModelProvider .Factory ).apply {
124166 if (this is ViewModelProvider .Factory ) {
@@ -132,4 +174,12 @@ object GenerativeAiViewModelFactory {
132174 }
133175 }
134176 }
177+
178+ /* *
179+ * Get the current model option
180+ */
181+ fun getCurrentModel (): ModelOption {
182+ return ModelOption .values().find { it.modelName == currentModelName }
183+ ? : ModelOption .GEMINI_FLASH_LITE
184+ }
135185}
0 commit comments