From bad36c744d3a7cbe26bb3d27260fc62d20ad9266 Mon Sep 17 00:00:00 2001 From: Lukasz Papierkowski Date: Tue, 30 Jul 2024 18:33:31 +0200 Subject: [PATCH] AI Assistant: Settings UI Change-Id: Icb98ac9869d01295d9e64737766d37e51ba86a76 Reviewed-by: Marcus Tillmanns --- .../images/settingscategory_ai_assistant.png | Bin 0 -> 251 bytes .../lua-plugins/ai_asistant/init.lua | 76 +++++++++++++++++- src/plugins/lua/meta/settings.lua | 2 +- 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 share/qtcreator/lua-plugins/ai_asistant/images/settingscategory_ai_assistant.png diff --git a/share/qtcreator/lua-plugins/ai_asistant/images/settingscategory_ai_assistant.png b/share/qtcreator/lua-plugins/ai_asistant/images/settingscategory_ai_assistant.png new file mode 100644 index 0000000000000000000000000000000000000000..9a47fb241351b4566a0fdf77b425396a31a6f94d GIT binary patch literal 251 zcmeAS@N?(olHy`uVBq!ia0y~yV2}V|4h9AWhNCh`Dhvz^hdf;zLp07O|LA8n2#9}l zz0XJAIr#jRv-Sb1d@BtZ7}*81-#AUPIIwQ|~;R$P!9-Lqc z+MRm;kZM{=;|Wvl@Uv_eMPmy(8~8SC*~U3z-aC%z1|OJ(_OCr8^u-~sE3n1e!_e&B zt(U7leQjNLciQdPGjj?!73;0l&TTNS|6kMdIBg3@x{Jq|AOFA0ANl$J-=FwSrAC&H zNfF&T8~GI#3*{ppsp`ip;x|1~{Xi%_Ky}{*jVwb3hRCQ7zQVi9_&~n$boFyt=akR{ E0EdNUS^xk5 literal 0 HcmV?d00001 diff --git a/share/qtcreator/lua-plugins/ai_asistant/init.lua b/share/qtcreator/lua-plugins/ai_asistant/init.lua index 62b1d267ced..d4ba0fde6bc 100644 --- a/share/qtcreator/lua-plugins/ai_asistant/init.lua +++ b/share/qtcreator/lua-plugins/ai_asistant/init.lua @@ -36,6 +36,27 @@ local function createCommand() return cmd end +local function createInitOptions() + local llm_config = { + cppLLM = Settings.cppLLM.stringValue, + qmlLLM = Settings.qmlLLM.stringValue, + otherLLM = Settings.otherLLM.stringValue, + debugLLM = Settings.debugLLM.stringValue, + reviewLLM = Settings.reviewLLM.stringValue, + explainLLM = Settings.explainLLM.stringValue + } + + local auth_token_config = { + authTokenLama35 = Settings.authTokenLlama3.value, + authTokenClaude35 = Settings.authTokenClaude35.value + } + + return { + llm_config = llm_config, + auth_token_config = auth_token_config + } +end + local function installOrUpdateServer() -- TODO: Download/Update/Install end @@ -47,6 +68,7 @@ local function setupClient() name = 'AI Assistant Server', cmd = createCommand, transport = 'stdio', + initializationOptions = createInitOptions, languageFilter = { patterns = { '*.*' }, }, @@ -83,12 +105,45 @@ local function layoutSettings() br, }, st - } + }, + br, + Settings.cppLLM, br, + Settings.qmlLLM, br, + Settings.otherLLM, br, + Settings.debugLLM, br, + Settings.reviewLLM, br, + Settings.explainLLM, br, + Settings.authTokenLlama3, br, + Settings.authTokenClaude35 } return layout end +local available_llms = {"Llama 3 70B Fine-Tuned", "Claude 3.5 Sonnet"} + +local function createSelectionAspect(settingsKey, displayName) + return S.SelectionAspect.create({ + settingsKey = settingsKey, + options = available_llms, + displayStyle = S.SelectionDisplayStyle.ComboBox, + displayName = displayName + }) +end + +local function addLLMSetting(keySuffix, displayText) + Settings[keySuffix] = createSelectionAspect("AiAssistant." .. keySuffix, displayText) +end + +local function addAuthTokenSetting(llm_name, displayText) + Settings["authToken" .. llm_name] = S.StringAspect.create({ + settingsKey = "AiAssistant.AuthToken." .. llm_name, + labelText = displayText .. ":", + displayStyle = S.StringDisplayStyle.LineEdit, + defaultValue = "AUTH_TOKEN", + }) +end + local function setupAspect() Settings = S.AspectContainer.create({ autoApply = false, @@ -104,6 +159,25 @@ local function setupAspect() defaultPath = Utils.FilePath.fromUserInput("/path/to/server"), }) + addLLMSetting("cppLLM", "LLM for C++:") + addLLMSetting("qmlLLM", "LLM for QML:") + addLLMSetting("otherLLM", "LLM for other languages:") + addLLMSetting("debugLLM", "LLM for debug:") + addLLMSetting("reviewLLM", "LLM for review") + addLLMSetting("explainLLM", "LLM for explain:") + + addAuthTokenSetting("Llama3", "Llama 3 API authentication Token") + addAuthTokenSetting("Claude35", "Claude 3.5 API authentication Token") + + Options = S.OptionsPage.create({ + aspectContainer = Settings, + categoryId = "AiAssistant.OptionsPage", + displayName = tr("AI Assistant"), + id = "AiAssistant.Settings", + displayCategory = "AI Assistant", + categoryIconPath = PluginSpec.pluginDirectory:resolvePath("images/settingscategory_ai_assistant.png") + }) + return Settings end diff --git a/src/plugins/lua/meta/settings.lua b/src/plugins/lua/meta/settings.lua index caa8a5301a2..97f60d53b7e 100644 --- a/src/plugins/lua/meta/settings.lua +++ b/src/plugins/lua/meta/settings.lua @@ -12,7 +12,7 @@ settings.BaseAspect = {} function settings.BaseAspect:apply() end ---@class AspectCreate ----@field settingsKey? string The settings key of the aspect. +---@field settingsKey? string The settings key of the aspect. If not set, the aspect will not be saved to the settings persistently. ---@field displayName? string The display name of the aspect. ---@field labelText? string The label text of the aspect. ---@field toolTip? string The tool tip of the aspect.