From 85af52e2435d671aea7bf4ccccad099f19836f8c Mon Sep 17 00:00:00 2001 From: cbh778899 Date: Tue, 22 Oct 2024 11:31:22 +1100 Subject: [PATCH 1/7] use general confirmation dialog instead of just for DeleteConfirm Signed-off-by: cbh778899 --- src/components/ConfirmationDialog.jsx | 26 ++++++++++++++++++++++++ src/components/chat/DeleteConfirm.jsx | 29 --------------------------- 2 files changed, 26 insertions(+), 29 deletions(-) create mode 100644 src/components/ConfirmationDialog.jsx delete mode 100644 src/components/chat/DeleteConfirm.jsx diff --git a/src/components/ConfirmationDialog.jsx b/src/components/ConfirmationDialog.jsx new file mode 100644 index 0000000..d08d5d8 --- /dev/null +++ b/src/components/ConfirmationDialog.jsx @@ -0,0 +1,26 @@ +import { useEffect, useRef } from "react"; + +export default function ConfirmationDialog({children, open_status, setOpenStatus, callback}) { + const dialogRef = useRef(null); + + useEffect(()=>{ + if(dialogRef.current) { + if(open_status) dialogRef.current.showModal(); + else dialogRef.current.close(); + } + }, [open_status]) + + return ( + setOpenStatus(false)}> + { children } +
callback(true)} + >Yes, Continue
+
callback(false)} + >No, Go Back
+
+ ) +} \ No newline at end of file diff --git a/src/components/chat/DeleteConfirm.jsx b/src/components/chat/DeleteConfirm.jsx deleted file mode 100644 index 2105103..0000000 --- a/src/components/chat/DeleteConfirm.jsx +++ /dev/null @@ -1,29 +0,0 @@ -import { useEffect } from "react"; -import { useRef } from "react"; - -export default function DeleteConfirm({showConfirm, closeDialog, deleteHistory, resetRequestDelete, conv_to_delete}) { - const dialogRef = useRef(null); - - useEffect(()=>{ - if(dialogRef.current) { - if(showConfirm) dialogRef.current.showModal(); - else dialogRef.current.close(); - } - }, [showConfirm]) - - return ( - -
- Delete {conv_to_delete && conv_to_delete.title}? -
-
Yes, Delete
-
No, Go Back
-
- ) -} \ No newline at end of file From 29debf3109c4c9601806620c2ec74e9e407abf4b Mon Sep 17 00:00:00 2001 From: cbh778899 Date: Tue, 22 Oct 2024 11:31:34 +1100 Subject: [PATCH 2/7] add deleteModel function Signed-off-by: cbh778899 --- preloader/index.js | 5 +++-- preloader/node-llama-cpp-preloader.js | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/preloader/index.js b/preloader/index.js index 1ece726..2825d0d 100644 --- a/preloader/index.js +++ b/preloader/index.js @@ -6,7 +6,7 @@ const { setClient, downloadModel, updateModelSettings, - formator + formator, deleteModel } = require("./node-llama-cpp-preloader.js") const { @@ -15,7 +15,8 @@ const { contextBridge.exposeInMainWorld('node-llama-cpp', { loadModel, chatCompletions, updateModelSettings, - abortCompletion, setClient, downloadModel, formator + abortCompletion, setClient, downloadModel, formator, + deleteModel }) contextBridge.exposeInMainWorld('file-handler', { diff --git a/preloader/node-llama-cpp-preloader.js b/preloader/node-llama-cpp-preloader.js index bad950c..7001b59 100644 --- a/preloader/node-llama-cpp-preloader.js +++ b/preloader/node-llama-cpp-preloader.js @@ -1,5 +1,5 @@ const { ipcRenderer } = require("electron"); -const { createWriteStream, existsSync, statSync, mkdirSync } = require("fs"); +const { createWriteStream, existsSync, statSync, mkdirSync, rmSync } = require("fs"); const path = require("path"); let llama, getLlama, LlamaChatSession, current_model; @@ -216,6 +216,19 @@ function downloadModel(url, cb=null) { }) } +/** + * Delete a model from disk + * @param {String} model_name the model name on disk + * @returns {Boolean} + */ +function deleteModel(model_name) { + const model = path.join(model_path, model_name); + if(existsSync(model)){ + rmSync(model); + } + return true; +} + /** * format messages, reset history if needed * @param {Message[]} messages @@ -239,5 +252,6 @@ module.exports = { setClient, downloadModel, updateModelSettings, - formator + formator, + deleteModel } \ No newline at end of file From 71cf5701bde3b9578f8ab41fbad6d65e999d419f Mon Sep 17 00:00:00 2001 From: cbh778899 Date: Tue, 22 Oct 2024 11:31:45 +1100 Subject: [PATCH 3/7] update styles Signed-off-by: cbh778899 --- src/main.jsx | 1 + src/styles/chat.css | 22 ------------------- src/styles/confirmation-dialog.css | 20 ++++++++++++++++++ src/styles/index.css | 2 +- src/styles/settings.css | 34 ++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 src/styles/confirmation-dialog.css diff --git a/src/main.jsx b/src/main.jsx index 5fb359b..8ef1946 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -7,6 +7,7 @@ import './styles/sidebar.css'; import './styles/chat.css'; import './styles/entry.css'; import './styles/settings.css'; +import './styles/confirmation-dialog.css'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render( diff --git a/src/styles/chat.css b/src/styles/chat.css index 1efdc61..3bedc36 100644 --- a/src/styles/chat.css +++ b/src/styles/chat.css @@ -78,28 +78,6 @@ color: black; } -.chat > dialog { - border: 2px solid black; - padding: 30px; - border-radius: 10px; - text-align: center; -} -.chat > dialog:focus { - outline: none; -} - -.chat > dialog > .button { - border-bottom: 1px solid; - width: fit-content; - margin: auto; - margin-top: 7px; - padding: 0px 7px; - color: rgb(70, 70, 70); -} -.chat > dialog > .button:hover { - color: black; -} - .chat > .conversation-main { width: calc(100% - var(--tickets-width)); position: absolute; diff --git a/src/styles/confirmation-dialog.css b/src/styles/confirmation-dialog.css new file mode 100644 index 0000000..a5439bf --- /dev/null +++ b/src/styles/confirmation-dialog.css @@ -0,0 +1,20 @@ +.confirmation-dialog { + border: 2px solid black; + padding: 30px; + border-radius: 10px; + text-align: center; + max-width: 60%; +} + +.confirmation-dialog > .button { + border-bottom: 1px solid; + width: fit-content; + margin: auto; + margin-top: 7px; + padding: 0px 7px; + color: rgb(70, 70, 70); +} + +.confirmation-dialog > .button:hover { + color: black; +} \ No newline at end of file diff --git a/src/styles/index.css b/src/styles/index.css index 1ae3cef..c4e16eb 100644 --- a/src/styles/index.css +++ b/src/styles/index.css @@ -25,7 +25,7 @@ cursor: pointer; } .hidden { display: none; } -input:focus { outline: none; } +input:focus, dialog:focus { outline: none; } .main { width: 100%; diff --git a/src/styles/settings.css b/src/styles/settings.css index 999feb7..6538c8d 100644 --- a/src/styles/settings.css +++ b/src/styles/settings.css @@ -170,6 +170,40 @@ padding: 0px 7px; } +.setting-page > .setting-section > .component > .main-part.button { + align-content: center; + text-align: center; + border-radius: 7px; + background-color: dodgerblue; + color: white; + user-select: none; +} + +.setting-page > .setting-section > .component > .main-part.button:hover { + background-color: rgb(19 126 231); +} + +.setting-page > .setting-section > .component > .main-part.button:not(.disabled):hover { + cursor: pointer; +} + +.setting-page > .setting-section > .component > .main-part.button.disabled { + pointer-events: none; +} + +.setting-page > .setting-section > .component > +.main-part.button.dangerous { + --main-color: red; + background-color: white; + color: var(--main-color); + border: 2px solid var(--main-color); +} + +.setting-page > .setting-section > .component > +.main-part.button.dangerous:hover { + --main-color: crimson; +} + dialog:has(.download-protector) { border: none; border-radius: 15px; From 16b23a9d13eec4700e9835002b29af200e81b501 Mon Sep 17 00:00:00 2001 From: cbh778899 Date: Tue, 22 Oct 2024 11:32:01 +1100 Subject: [PATCH 4/7] move to ConfirmationDialog component Signed-off-by: cbh778899 --- src/components/chat/index.jsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/chat/index.jsx b/src/components/chat/index.jsx index cf64802..ff6f6be 100644 --- a/src/components/chat/index.jsx +++ b/src/components/chat/index.jsx @@ -1,12 +1,11 @@ import { useEffect, useRef, useState } from "react"; import Tickets from "./Tickets"; -// import Conversation from "./Conversation"; import useIDB from "../../utils/idb"; -import DeleteConfirm from "./DeleteConfirm"; import ChatPage from "./ChatPage"; import { getCompletionFunctions } from "../../utils/workers"; import { getPlatformSettings } from "../../utils/general_settings"; import { exportChatHistory } from "../../utils/chat-history-handler"; +import ConfirmationDialog from "../ConfirmationDialog"; export default function Chat() { @@ -184,13 +183,15 @@ export default function Chat() { pending_message={pending_message} abort={session_setting.abort} sendMessage={sendMessage} updateSystemInstruction={updateSystemInstruction} /> - toggleConfirm(false)} - deleteHistory={deleteHistory} - resetRequestDelete={resetRequestDelete} - conv_to_delete={conv_to_delete} - /> + { + cb ? deleteHistory() : resetRequestDelete(); + }} + > +
Delete { conv_to_delete && conv_to_delete.title }?
+
: <> ) From 8fbf074c29e44760489a3f57477662155c175f7b Mon Sep 17 00:00:00 2001 From: cbh778899 Date: Tue, 22 Oct 2024 11:32:20 +1100 Subject: [PATCH 5/7] add ButtonComponent for one-click settings Signed-off-by: cbh778899 --- src/components/settings/components/ButtonComponent.jsx | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/components/settings/components/ButtonComponent.jsx diff --git a/src/components/settings/components/ButtonComponent.jsx b/src/components/settings/components/ButtonComponent.jsx new file mode 100644 index 0000000..5644bf9 --- /dev/null +++ b/src/components/settings/components/ButtonComponent.jsx @@ -0,0 +1,9 @@ +export default function ButtonComponent({ cb, value, disabled, title, description, className }) { + return ( +
+
{title}
+ { description &&
{description}
} +
{ value }
+
+ ) +} \ No newline at end of file From f659d17f2dd29320675ba9302d9e18f27959cb6d Mon Sep 17 00:00:00 2001 From: cbh778899 Date: Tue, 22 Oct 2024 11:32:41 +1100 Subject: [PATCH 6/7] add validation for current selected item Signed-off-by: cbh778899 --- .../settings/components/DropdownComponent.jsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/settings/components/DropdownComponent.jsx b/src/components/settings/components/DropdownComponent.jsx index 35be96a..ed21994 100644 --- a/src/components/settings/components/DropdownComponent.jsx +++ b/src/components/settings/components/DropdownComponent.jsx @@ -1,12 +1,27 @@ -export default function DropdownComponent({ cb, value, title, description }) { +import { useEffect } from "react"; +import { useState } from "react"; + +export default function DropdownComponent({ cb, value, selected, title, description }) { + + const [selected_option, setSelectedOption] = useState(selected || (value && value.length && value[0].value) || ''); + + useEffect(()=>{ + selected && setSelectedOption(selected); + }, [selected]) + return (
{title}
{ description &&
{description}
}