From 4a9e342a1cf82f0e7e2229e8e0dcbe09adcbc693 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Mon, 28 Jul 2025 18:11:23 +0700 Subject: [PATCH] ai: add suggestions for /tool --- .../ii/modules/sidebarLeft/AiChat.qml | 21 ++++++++++++++++++- .config/quickshell/ii/services/Ai.qml | 8 ++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.config/quickshell/ii/modules/sidebarLeft/AiChat.qml b/.config/quickshell/ii/modules/sidebarLeft/AiChat.qml index d42e6b608..44f70633c 100644 --- a/.config/quickshell/ii/modules/sidebarLeft/AiChat.qml +++ b/.config/quickshell/ii/modules/sidebarLeft/AiChat.qml @@ -56,7 +56,7 @@ Item { const tool = args[0]; const switched = Ai.setTool(tool); if (switched) { - Ai.addMessage(Translation.tr("Tool set to %1").arg(tool), Ai.interfaceRole); + Ai.addMessage(Translation.tr("Tool set to: %1").arg(tool), Ai.interfaceRole); } } } @@ -538,6 +538,25 @@ Inline w/ backslash and round brackets \\(e^{i\\pi} + 1 = 0\\) description: Translation.tr(`Load chat from %1`).arg(file.target), } }) + } else if (messageInputField.text.startsWith(`${root.commandPrefix}tool`)) { + root.suggestionQuery = messageInputField.text.split(" ")[1] ?? "" + const toolResults = Fuzzy.go(root.suggestionQuery, Ai.availableTools.map(tool => { + return { + name: Fuzzy.prepare(tool), + obj: tool, + } + }), { + all: true, + key: "name" + }) + root.suggestionList = toolResults.map(tool => { + const toolName = tool.target + return { + name: `${messageInputField.text.trim().split(" ").length == 1 ? (root.commandPrefix + "tool ") : ""}${tool.target}`, + displayName: toolName, + description: Ai.toolDescriptions[toolName], + } + }) } else if(messageInputField.text.startsWith(root.commandPrefix)) { root.suggestionQuery = messageInputField.text root.suggestionList = root.allCommands.filter(cmd => cmd.name.startsWith(messageInputField.text.substring(1))).map(cmd => { diff --git a/.config/quickshell/ii/services/Ai.qml b/.config/quickshell/ii/services/Ai.qml index b23698d78..2d7b1c48a 100644 --- a/.config/quickshell/ii/services/Ai.qml +++ b/.config/quickshell/ii/services/Ai.qml @@ -144,6 +144,12 @@ Singleton { "none": [], } } + property list availableTools: Object.keys(root.tools[models[currentModelId]?.api_format]) + property var toolDescriptions: { + "functions": Translation.tr("Commands, edit configs, search.\nTakes an extra turn to switch to search mode if that's needed"), + "search": Translation.tr("Gives the model search capabilities (immediately)"), + "none": Translation.tr("Disable tools") + } // Model properties: // - name: Name of the model @@ -402,7 +408,7 @@ Singleton { function setTool(tool) { if (!root.tools[models[currentModelId]?.api_format] || !(tool in root.tools[models[currentModelId]?.api_format])) { - root.addMessage(Translation.tr("Invalid tool. Supported tools:\n- %1").arg(Object.keys(root.tools[models[currentModelId]?.api_format]).join("\n- ")), root.interfaceRole); + root.addMessage(Translation.tr("Invalid tool. Supported tools:\n- %1").arg(root.availableTools.join("\n- ")), root.interfaceRole); return false; } Config.options.ai.tool = tool;