diff --git a/CHANGELOG.md b/CHANGELOG.md index a2dd58d..3c42b64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ is in alpha and releases come off `main`. the titles at once; a moment later the chats whose messages hold the words follow under *In the messages*, with the words marked. - **Generate images** in a chat, when your instance makes pictures: from **+** in the composer, - the next message asks for one, and the picture shows in the reply at its own size. A tap opens + the next message asks for one (a new chat can start with a picture too), and the picture shows in the reply at its own size. A tap opens it whole. Only pictures your instance made and keeps are drawn; nothing is loaded from an address a reply names. - **Memory**, in the drawer: what models remember about you, as Settings › Memory on the web. diff --git a/app/src/main/java/eu/llembas/android/api/ApiClient.kt b/app/src/main/java/eu/llembas/android/api/ApiClient.kt index 99d4b02..197ac48 100644 --- a/app/src/main/java/eu/llembas/android/api/ApiClient.kt +++ b/app/src/main/java/eu/llembas/android/api/ApiClient.kt @@ -226,6 +226,7 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli mode: String? = null, agent: AgentTarget? = null, agents: AgentsSetting? = null, + forceTool: String? = null, ): NewChat = send( "POST", "/chats", @@ -237,6 +238,7 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli mode?.let { put("mode", it) } agents?.let { put("agents", agentsJson(it)) } put("temporary", temporary) + forceTool?.let { put("force_tool", it) } // An agent chat runs on a linked device; an empty directory is the device's first // allowed one. A device that is no longer linked makes it an ordinary chat on the // server, rather than losing the message. diff --git a/app/src/main/java/eu/llembas/android/ui/chat/ChatViewModel.kt b/app/src/main/java/eu/llembas/android/ui/chat/ChatViewModel.kt index 7fb3f72..422a819 100644 --- a/app/src/main/java/eu/llembas/android/ui/chat/ChatViewModel.kt +++ b/app/src/main/java/eu/llembas/android/ui/chat/ChatViewModel.kt @@ -227,6 +227,7 @@ class ChatViewModel(app: Application) : val list = runCatching { client.modelList(chatId) }.getOrNull() val models = list?.models.orEmpty() _state.update { it.copy(modelsCap = list?.subagentsCap) } + if (!agent) runCatching { client.me() }.onSuccess { me -> _state.update { it.copy(imagesOffered = me.hasImages) } } if (chatId == null) { val devices = if (agent) client.devices() else emptyList() val base = if (agent) getApplication().lembas.instances.current()?.base.orEmpty() else "" @@ -234,7 +235,6 @@ class ChatViewModel(app: Application) : if (agent) readAgentFacts() return@launch } - runCatching { client.me() }.onSuccess { me -> _state.update { it.copy(imagesOffered = me.hasImages) } } val detail = client.chat(chatId) _state.update { it.copy(chat = detail.chat, messages = detail.messages, more = detail.more, models = models, loading = false) @@ -350,11 +350,13 @@ class ChatViewModel(app: Application) : val attached = _state.value.pending val files = attached.map { it.id } if (text.isBlank() && files.isEmpty()) return + // A picture, asked for from + (not in an agent chat, which runs on a computer). + val picture = draft.image && now.imagesOffered && !agentChat viewModelScope.launch { try { val client = api() val chat = _state.value.chat - _state.update { it.copy(pending = emptyList()) } + _state.update { it.copy(pending = emptyList(), draft = it.draft.copy(image = false)) } if (chat == null) { val made = client.createChat( text, @@ -365,17 +367,16 @@ class ChatViewModel(app: Application) : mode = mode, agent = agent, agents = agents, + forceTool = if (picture) IMAGE_TOOL else null, ) _state.update { it.copy(chat = made.chat, messages = listOfNotNull(made.message, made.reply)) } made.reply?.let { follow(it.id) } } else { - val picture = _state.value.draft.image && _state.value.imagesOffered - _state.update { it.copy(draft = it.draft.copy(image = false)) } took(client.sendMessage(chat.id, text, files, forceTool = if (picture) IMAGE_TOOL else null)) } } catch (e: Exception) { // Nothing was sent: the words and the attachments go back to the composer. - _state.update { it.copy(pending = attached + it.pending, unsent = text) } + _state.update { it.copy(pending = attached + it.pending, unsent = text, draft = it.draft.copy(image = picture || it.draft.image)) } fail(e) } } diff --git a/app/src/main/java/eu/llembas/android/ui/chat/Composer.kt b/app/src/main/java/eu/llembas/android/ui/chat/Composer.kt index 980a5ee..668be64 100644 --- a/app/src/main/java/eu/llembas/android/ui/chat/Composer.kt +++ b/app/src/main/java/eu/llembas/android/ui/chat/Composer.kt @@ -323,9 +323,9 @@ fun Composer(state: ChatState, actions: ChatActions, agent: Boolean, onTune: () pickFiles.launch("*/*") }, ) - // A picture made by the instance, in a chat that exists (the server takes - // `force_tool` on a turn, not on the message that makes a chat). - if (state.imagesOffered && state.chat != null && !agent) { + // A picture made by the instance: the next message (or the one that makes + // the chat) asks for it. Not in an agent chat, which runs on a computer. + if (state.imagesOffered && !agent) { DropdownMenuItem( leadingIcon = { Icon(Icons.Filled.Brush, contentDescription = null) }, text = { Text(stringResource(R.string.image_generate)) },