Skip to content

Commit c09f2d2

Browse files
committed
fix: ensure system message is loaded before every AI request
reasonWithCustomJsModel() and reasonWithBuiltInModelViaJs() - the two functions that build the payload for the WebView's JS AI callers - read _systemMessage.value directly without ever calling ensureInitialized() first. Every other reasoning path (offline model, regular GOOGLE SDK path, Puter) already calls ensureInitialized() before touching _systemMessage. Since these two functions cover every online built-in model plus all custom JSON-defined models, _systemMessage.value could still be the initial empty string on the very first turn after process start (or any time isInitialized was reset), so the system message (and by extension the database entry headings, which are sent together with it in the same payload/system slot) silently failed to reach the AI. Adding ensureInitialized(context) at the top of each coroutine loads the persisted system message from SharedPreferences before the payload (systemMessage + databaseEntries) is built and emitted to JS.
1 parent 82cf730 commit c09f2d2

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,7 @@ class PhotoReasoningViewModel(
15181518

15191519
viewModelScope.launch(Dispatchers.IO) {
15201520
try {
1521+
ensureInitialized(context)
15211522
val systemMessageText = _systemMessage.value
15221523
val formattedDbEntries = PhotoReasoningTextPolicies.formatDatabaseEntriesAsText(context)
15231524

@@ -1641,6 +1642,7 @@ class PhotoReasoningViewModel(
16411642

16421643
viewModelScope.launch(Dispatchers.IO) {
16431644
try {
1645+
ensureInitialized(context)
16441646
val systemMessageText = _systemMessage.value
16451647
val formattedDbEntries = PhotoReasoningTextPolicies.formatDatabaseEntriesAsText(context)
16461648

0 commit comments

Comments
 (0)