Commit d691c6c
committed
Fix ViewModel initialization order and chat history
This commit addresses issues related to the initialization order in PhotoReasoningViewModel:
1. Automatic Initialization:
- Added an `init` block to PhotoReasoningViewModel to automatically call `initializeViewModel()` upon creation.
- `initializeViewModel()` loads the system message and chat history, then sets an `_isInitialized` flag.
2. Robust `reason()` Method:
- The `reason()` method now checks if the ViewModel is initialized.
- If not initialized, it launches a coroutine to initialize first, then proceeds with the reasoning logic.
- If already initialized, it proceeds directly.
- The core logic of `reason()` has been moved to a new private method `performReasoning()`.
This ensures that:
- The ViewModel attempts to initialize as soon as it's created.
- Calls to `reason()` will always wait for initialization to complete if it hasn't happened yet.
- The system message and database entries (loaded during `loadSystemMessage` which calls `loadChatHistory` which calls `rebuildChatHistory`) are consistently included in the chat history before any user interaction that triggers `reason()`.1 parent 3030db5 commit d691c6c
1 file changed
Lines changed: 28 additions & 2 deletions
Lines changed: 28 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
108 | 118 | | |
109 | 119 | | |
110 | 120 | | |
111 | 121 | | |
112 | 122 | | |
113 | | - | |
| 123 | + | |
114 | 124 | | |
115 | 125 | | |
116 | 126 | | |
| |||
197 | 207 | | |
198 | 208 | | |
199 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
200 | 226 | | |
201 | 227 | | |
202 | 228 | | |
| |||
0 commit comments