From b2c1ad628e758b34285640c559340d39726793f3 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Thu, 15 May 2025 23:10:21 +0200 Subject: [PATCH] ai service: rename currentModel and model in setModel for clarity --- .../quickshell/modules/sidebarLeft/AiChat.qml | 4 +- .config/quickshell/services/Ai.qml | 38 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.config/quickshell/modules/sidebarLeft/AiChat.qml b/.config/quickshell/modules/sidebarLeft/AiChat.qml index 3f82b1b58..fe75ac664 100644 --- a/.config/quickshell/modules/sidebarLeft/AiChat.qml +++ b/.config/quickshell/modules/sidebarLeft/AiChat.qml @@ -533,7 +533,7 @@ int main(int argc, char* argv[]) { font.weight: Font.DemiBold color: Appearance.m3colors.m3onSurface elide: Text.ElideRight - text: Ai.models[Ai.currentModel].name + text: Ai.getModel().name } } StyledToolTip { @@ -541,7 +541,7 @@ int main(int argc, char* argv[]) { extraVisibleCondition: false alternativeVisibleCondition: mouseArea.containsMouse // Show tooltip when hovered content: StringUtils.format(qsTr("Current model: {0}\nSet it with {1}model MODEL"), - Ai.models[Ai.currentModel].name, root.commandPrefix) + Ai.getModel().name, root.commandPrefix) } MouseArea { diff --git a/.config/quickshell/services/Ai.qml b/.config/quickshell/services/Ai.qml index f1d972390..ce9ae0b3e 100644 --- a/.config/quickshell/services/Ai.qml +++ b/.config/quickshell/services/Ai.qml @@ -77,10 +77,10 @@ Singleton { }, } property var modelList: Object.keys(root.models) - property var currentModel: PersistentStates.ai.model + property var currentModelId: PersistentStates.ai.model Component.onCompleted: { - setModel(currentModel, false); // Do necessary setup for model + setModel(currentModelId, false); // Do necessary setup for model getOllamaModels.running = true } @@ -159,34 +159,38 @@ Singleton { ); } - function setModel(model, feedback = true) { - if (!model) model = "" - model = model.toLowerCase() - if (modelList.indexOf(model) !== -1) { - PersistentStateManager.setState("ai.model", model); - if (feedback) root.addMessage("Model set to " + models[model].name, Ai.interfaceRole) - if (models[model].requires_key) { + function getModel() { + return models[currentModelId]; + } + + function setModel(modelId, feedback = true) { + if (!modelId) modelId = "" + modelId = modelId.toLowerCase() + if (modelList.indexOf(modelId) !== -1) { + PersistentStateManager.setState("ai.model", modelId); + if (feedback) root.addMessage("Model set to " + models[modelId].name, Ai.interfaceRole) + if (models[modelId].requires_key) { // If key not there show advice - if (root.apiKeysLoaded && (!root.apiKeys[models[model].key_id] || root.apiKeys[models[model].key_id].length === 0)) { - root.addApiKeyAdvice(models[model]) + if (root.apiKeysLoaded && (!root.apiKeys[models[modelId].key_id] || root.apiKeys[models[modelId].key_id].length === 0)) { + root.addApiKeyAdvice(models[modelId]) } } } else { if (feedback) root.addMessage(qsTr("Invalid model. Supported: \n```\n") + modelList.join("\n```\n```\n"), Ai.interfaceRole) + "\n```" } - if (models[model]?.requires_key) { + if (models[modelId]?.requires_key) { KeyringStorage.fetchKeyringData(); } } function setApiKey(key) { - const model = models[currentModel]; + const model = models[currentModelId]; if (!model.requires_key) { root.addMessage(`${model.name} does not require an API key`, Ai.interfaceRole); return; } if (!key || key.length === 0) { - const model = models[currentModel]; + const model = models[currentModelId]; root.addApiKeyAdvice(model) return; } @@ -195,7 +199,7 @@ Singleton { } function printApiKey() { - const model = models[currentModel]; + const model = models[currentModelId]; if (model.requires_key) { const key = root.apiKeys[model.key_id]; if (key) { @@ -263,7 +267,7 @@ Singleton { } function makeRequest() { - const model = models[currentModel]; + const model = models[currentModelId]; requester.apiFormat = model.api_format ?? "openai"; /* Put API key in environment variable */ @@ -280,7 +284,7 @@ Singleton { /* Create local message object */ requester.message = root.aiMessageComponent.createObject(root, { "role": "assistant", - "model": currentModel, + "model": currentModelId, "content": "", "thinking": true, "done": false,