You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_commandExecutionStatus.value ="Error during AI generation: $errorMessage"
139
148
_chatState.replaceLastPendingMessage()
149
+
150
+
val apiKeyManager =ApiKeyManager.getInstance(receiverContext)
151
+
val isQuotaError = isQuotaExceededError(errorMessage)
152
+
153
+
if (isQuotaError && currentRetryAttempt <MAX_RETRY_ATTEMPTS) {
154
+
val currentKey = apiKeyManager.getCurrentApiKey()
155
+
if (currentKey !=null) {
156
+
apiKeyManager.markKeyAsFailed(currentKey)
157
+
val newKey = apiKeyManager.switchToNextAvailableKey()
158
+
if (newKey !=null) {
159
+
// Increment retry attempt
160
+
currentRetryAttempt++
161
+
// Remove the last user message (pending already removed)
162
+
val messages =_chatState.messages
163
+
if (messages.isNotEmpty() && messages.last().participant ==PhotoParticipant.USER) {
164
+
_chatState.messages.removeLast()
165
+
}
166
+
// Retry by calling performReasoning with stored parameters
167
+
performReasoning(
168
+
currentUserInput,
169
+
currentSelectedImages,
170
+
currentScreenInfoForPrompt,
171
+
currentImageUrisForChat
172
+
)
173
+
return// Exit without adding error message
174
+
}
175
+
}
176
+
}
177
+
178
+
// Normal error handling if not quota or max retries reached
140
179
_chatState.addMessage(
141
180
PhotoReasoningMessage(
142
181
text = errorMessage,
@@ -235,6 +274,8 @@ class PhotoReasoningViewModel(
235
274
// Store the current user input and selected images
236
275
currentUserInput = userInput // This should ideally store aiPromptText or handle context separately if needed for retry. For now, task is specific to prompt to AI and chat.
237
276
currentSelectedImages = selectedImages
277
+
currentScreenInfoForPrompt = screenInfoForPrompt
278
+
currentImageUrisForChat = imageUrisForChat
238
279
239
280
// Clear previous commands
240
281
_detectedCommands.value = emptyList()
@@ -319,6 +360,7 @@ class PhotoReasoningViewModel(
319
360
return
320
361
}
321
362
ensureInitialized(context)
363
+
currentRetryAttempt =0// Reset retry attempt on new reason call
0 commit comments