Implemented a test remote callout to an LLM running on the local host machine for development and testing purposes. Successfully getting LLM responses in the Alice messages UI
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
<application
|
||||
android:name="alice"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
|
||||
@@ -18,6 +18,9 @@ object LlmManager {
|
||||
private val chatModel: ChatLanguageModel = OpenAiChatModel.builder()
|
||||
.baseUrl(LOCAL_LLM_URL)
|
||||
.apiKey("dummy-key-not-needed") // Local servers ignore this, but the builder requires a string
|
||||
// IMPORTANT: Change "llama3.2" to whatever model you currently have pulled in your Ollama instance!
|
||||
// e.g., "mistral", "qwen2.5", "phi3"
|
||||
.modelName("qwen3:8b")
|
||||
.timeout(Duration.ofMinutes(3)) // Local inference can take a bit
|
||||
.maxRetries(0) // ADD THIS LINE: Bypasses the broken Java 15 retry logger!
|
||||
.logRequests(true) // Great for debugging in Logcat
|
||||
|
||||
@@ -22,6 +22,7 @@ import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
import kotlinx.coroutines.Dispatchers //Added so that Kotlin run the query in background threads
|
||||
import android.util.Log //Added to facilitate the logging while developing the app
|
||||
|
||||
// 1. A simple data class to hold our messages
|
||||
data class ChatMessage(val text: String, val isUser: Boolean)
|
||||
@@ -163,6 +164,8 @@ fun MainChatScreen() {
|
||||
// Compose state automatically handles switching back to the main thread for UI updates
|
||||
messages = messages + ChatMessage(response, false)
|
||||
} catch (e: Exception) {
|
||||
// THIS PRINTS THE REAL ERROR TO LOGCAT
|
||||
Log.e("AliceNetwork", "LLM Connection Failed", e)
|
||||
messages = messages + ChatMessage("Connection Error: Is the local LLM server running?", false)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user