Skip to content

Commit e413392

Browse files
Fix screenshot prompt carry-over and model routing issues
1 parent 495d42a commit e413392

3 files changed

Lines changed: 11 additions & 25 deletions

File tree

app/src/main/kotlin/com/google/ai/sample/GenerativeAiViewModelFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ enum class ModelOption(
3535
val additionalDownloadUrls: List<String> = emptyList(),
3636
val requiresVisionBackend: Boolean = false
3737
) {
38+
PUTER_GPT_5_4_NANO("GPT-5.4 Nano (Puter)", "openai/gpt-5.4-nano", ApiProvider.PUTER, supportsScreenshot = true),
3839
PUTER_GLM5("GLM-5V Turbo (Puter)", "openrouter:z-ai/glm-5v-turbo", ApiProvider.PUTER, supportsScreenshot = true),
3940
MISTRAL_LARGE_3("Mistral Large 3", "mistral-large-latest", ApiProvider.MISTRAL),
4041
MISTRAL_MEDIUM_3_1("Mistral Medium 3.1", "mistral-medium-latest", ApiProvider.MISTRAL),

app/src/main/kotlin/com/google/ai/sample/MenuScreen.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,14 @@ fun MenuScreen(
215215
}
216216
val normalModels = allModels.filter {
217217
it != ModelOption.MISTRAL_MEDIUM_3_1 &&
218+
it != ModelOption.PUTER_GPT_5_4_NANO &&
218219
it.apiProvider != ApiProvider.VERCEL &&
219220
!STRIKETHROUGH_MODELS.contains(it)
220221
}
221-
val orderedModels = listOf(ModelOption.MISTRAL_MEDIUM_3_1) +
222+
val orderedModels = listOf(
223+
ModelOption.PUTER_GPT_5_4_NANO,
224+
ModelOption.MISTRAL_MEDIUM_3_1
225+
) +
222226
normalModels +
223227
vercelModels +
224228
STRIKETHROUGH_MODELS
@@ -288,7 +292,7 @@ fun MenuScreen(
288292
ModelOption.GPT_OSS_120B -> "This is a pure text model\nCerebras sometimes discontinues free access in the Free Tier, displaying an \"Error 404: gpt-oss-120b does not exist or you do not have access to it\" message, or changes the rate limits."
289293
ModelOption.MISTRAL_LARGE_3 -> "Mistral AI rejects requests containing non-black images with a 429 Error: Rate limit exceeded response"
290294
ModelOption.GEMINI_3_FLASH -> "Google often rejects requests to this model with a 503 Model is exhausted error"
291-
ModelOption.PUTER_GLM5 -> "This model is expensive and uses up the free quota quickly. Consider GPT 5.4 nano"
295+
ModelOption.PUTER_GLM5 -> "This model is expensive and uses up the free quota quickly. Consider GPT-5.4 Nano."
292296
ModelOption.GPT_5_1_CODEX_MAX,
293297
ModelOption.GPT_5_1_CODEX_MINI,
294298
ModelOption.GPT_5_NANO -> "Vercel requires a credit card"

app/src/main/kotlin/com/google/ai/sample/feature/multimodal/PhotoReasoningViewModel.kt

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,8 @@ class PhotoReasoningViewModel(
11911191
}
11921192

11931193
// CerebrasRequest braucht stream-Feld — inline als JSON-String um Datenklasse nicht zu ändern
1194-
val streamingBody = """{"model":"$modelName","messages":${Json.encodeToString(apiMessages)},"max_completion_tokens":1024,"temperature":0.2,"top_p":1.0,"stream":true}"""
1194+
val selectedModelName = com.google.ai.sample.GenerativeAiViewModelFactory.getCurrentModel().modelName
1195+
val streamingBody = """{"model":"$selectedModelName","messages":${Json.encodeToString(apiMessages)},"max_completion_tokens":1024,"temperature":0.2,"top_p":1.0,"stream":true}"""
11951196
val mediaType = "application/json".toMediaType()
11961197
val client = OkHttpClient()
11971198

@@ -1859,7 +1860,7 @@ class PhotoReasoningViewModel(
18591860
context = context,
18601861
inputContentJson = inputContentJson,
18611862
chatHistoryJson = chatHistoryJson,
1862-
modelName = generativeModel.modelName,
1863+
modelName = currentModel.modelName,
18631864
apiKey = apiKey,
18641865
apiProvider = currentModel.apiProvider,
18651866
tempFilePaths = tempFilePaths
@@ -2168,30 +2169,10 @@ class PhotoReasoningViewModel(
21682169
private fun createGenericScreenshotPrompt(): String {
21692170
val latestTask = latestUserTaskInput.trim()
21702171
if (latestTask.isNotBlank()) {
2172+
latestUserTaskInput = ""
21712173
return latestTask
21722174
}
21732175

2174-
val lastUserMessage = _chatState.getAllMessages()
2175-
.asReversed()
2176-
.firstOrNull { it.participant == PhotoParticipant.USER && it.text.isNotBlank() }
2177-
?.text
2178-
?.trim()
2179-
2180-
if (!lastUserMessage.isNullOrBlank()) {
2181-
val screenInfoMarker = "\n\nScreen elements:\n"
2182-
return lastUserMessage.substringBefore(screenInfoMarker).trim()
2183-
}
2184-
2185-
val persistedInput = _userInput.value.trim()
2186-
if (persistedInput.isNotBlank()) {
2187-
return persistedInput
2188-
}
2189-
2190-
val lastKnownInput = currentUserInput.trim()
2191-
if (lastKnownInput.isNotBlank()) {
2192-
return lastKnownInput
2193-
}
2194-
21952176
return ""
21962177
}
21972178

0 commit comments

Comments
 (0)