Generate images in a new chat too: force_tool on POST /chats (server e0c2332)
CI / check (push) Canceled after 0s
CI / check (push) Canceled after 0s
The + option shows in a new chat as well (never an agent chat); the first message makes the chat and asks for the picture. /me is read on opening any non-agent chat for services.images. A send that fails gives the picture request back with the words. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
4 files changed
+12
-9
No files matched your search
+1
-1
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<Application>().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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)) },
|
||||
|
||||
Reference in new issue
Block a user