diff --git a/components/chat-page/chatMain.js b/components/chat-page/chatMain.js
index 48e96a0..a4fa7a9 100644
--- a/components/chat-page/chatMain.js
+++ b/components/chat-page/chatMain.js
@@ -185,7 +185,8 @@ async function sendMessage(message, send) {
signal: abort_controller.signal,
body: {
sessionUuid: conversation.id || "uuid",
- message, ...model_settings
+ message, ...model_settings,
+ collection_name: conversation.dataset_name
}
}, true)
diff --git a/components/chat-page/index.js b/components/chat-page/index.js
index a89e4ba..9c737ff 100644
--- a/components/chat-page/index.js
+++ b/components/chat-page/index.js
@@ -3,7 +3,7 @@ import createChatMain from "./chatMain.js";
import createChatHistory from "./history.js";
import createChatSettingsPage from "./settings.js";
-const [settings_main, { toggleModal }] = createDialog();
+const [settings_main, { toggleModal, close }] = createDialog();
export default function createChatPage() {
const chatPage = document.createElement('div');
@@ -19,7 +19,7 @@ export default function createChatPage() {
dismount_components.push(createChatHistory(chatPage));
dismount_components.push(createChatMain(chatPage, toggleExpand, toggleModal));
- createChatSettingsPage(settings_main);
+ createChatSettingsPage(settings_main, close);
return () => {
dismount_components.forEach(e=>e());
diff --git a/components/chat-page/session-settings.js b/components/chat-page/session-settings.js
index 0a44cb6..cf4b8bd 100644
--- a/components/chat-page/session-settings.js
+++ b/components/chat-page/session-settings.js
@@ -16,6 +16,7 @@ import rangeSettingSection from './range-setting-section.js';
let current_conversation = {}, user_id = null;
let rag_dataset_options = {};
+let closeSetting;
// ===================================================
//
@@ -30,6 +31,30 @@ show_dataset_loading.innerHTML =
`${getSVG('arrow-clockwise')}
Dataset loading, please wait...
`
upload_dataset_cover.appendChild(show_dataset_loading);
+const [confirm_delete_session_cover, confirm_delete_session_controller] = createDialog(false);
+const confirm_delete_session_main = document.createElement('div');
+confirm_delete_session_main.className = 'confirm-delete-session';
+const cancel_btn = document.createElement('div');
+cancel_btn.className = 'button';
+cancel_btn.textContent = 'Cancel'
+cancel_btn.onclick = confirm_delete_session_controller.close;
+const confirm_delete_btn = document.createElement('div');
+confirm_delete_btn.className = 'dangerous-btn clickable';
+confirm_delete_btn.textContent = 'Confirm Delete'
+confirm_delete_btn.onclick = async ()=>{
+ const session_name = current_conversation.name;
+ if(await deleteConversation()) {
+ showMessage(
+ `Session "${session_name}" successfully deleted!`,
+ { type: 'success' }
+ );
+ confirm_delete_session_controller.close();
+ closeSetting();
+ }
+}
+confirm_delete_session_main.append(confirm_delete_btn, cancel_btn);
+confirm_delete_session_cover.appendChild(confirm_delete_session_main)
+
const session_settings = document.createElement('div');
session_settings.className = 'session-settings'
session_settings.innerHTML =
@@ -93,6 +118,13 @@ const [submit_dataset_btn, {
)
submit_dataset_btn.classList.add('rag-option','hide-on-no-change')
+const [delete_session_btn] = normalSettingSection(
+ 'button', 'Delete Session', ()=>{},
+ 'Delete This Session',
+ confirm_delete_session_controller.showModal
+)
+delete_session_btn.classList.add('dangerous');
+
// ===================================================
//
// Functions
@@ -166,7 +198,7 @@ useUser(user=>{
const { updateHistoryInfo } = useHistory();
-const { rename } = useConversation(conversation=>{
+const { rename, deleteConversation } = useConversation(conversation=>{
current_conversation = conversation;
setSessionName(conversation.name)
session_settings.classList.toggle(
@@ -201,6 +233,7 @@ session_settings.appendChild(dataset_list_elem);
session_settings.appendChild(dataset_range_elem);
session_settings.appendChild(submit_dataset_btn);
session_settings.insertAdjacentHTML("beforeend", "
");
+session_settings.appendChild(delete_session_btn)
// ===================================================
//
@@ -208,6 +241,7 @@ session_settings.insertAdjacentHTML("beforeend", "
evt.stopPropagation();
- createSessionSettings(setting_main);
+ createSessionSettings(setting_main, close_setting);
createModelSettings(setting_main);
main.appendChild(setting_main);
diff --git a/global/useConversation.js b/global/useConversation.js
index b065ef5..19dddc9 100644
--- a/global/useConversation.js
+++ b/global/useConversation.js
@@ -17,7 +17,7 @@ const conversation_histories = {}
let currentUser;
const { onmount, remount, dismount, updateAll } = createHook();
-const { addHistory, updateHistoryName } = useHistory(h=>{
+const { addHistory, removeHistory, updateHistoryName } = useHistory(h=>{
if(currentConversation.id) {
if(!h.filter(e=>e.id === currentConversation.id).length) {
currentConversation = {
@@ -54,6 +54,25 @@ async function startNewConversation() {
updateAll(currentConversation);
}
+async function deleteConversation() {
+ const { http_error } = await request(`chat/session/${currentConversation.id}`, {
+ method: 'DELETE'
+ })
+ if(!http_error) {
+ removeHistory(currentConversation.id);
+ currentConversation = {
+ id: null,
+ pending: false,
+ name: '',
+ session_type: '',
+ dataset_name: '',
+ history: []
+ }
+ updateAll(currentConversation);
+ }
+ return !http_error;
+}
+
function togglePending() {
currentConversation.pending = !currentConversation.pending;
updateAll(currentConversation);
@@ -98,7 +117,7 @@ export default function useConversation(updated) {
updated && updated(currentConversation);
return {
- selectConversation, startNewConversation,
+ selectConversation, startNewConversation, deleteConversation,
sendMessage, togglePending, rename, updateConversationInfo,
componetDismount:dismount(mount_key), componentReMount
}
diff --git a/global/useHistory.js b/global/useHistory.js
index 71e70cc..ac7257c 100644
--- a/global/useHistory.js
+++ b/global/useHistory.js
@@ -38,6 +38,11 @@ function addHistory(new_ticket) {
updateAll(history);
}
+function removeHistory(id) {
+ history.splice(history.findIndex(e=>e.id === id), 1);
+ updateAll(history);
+}
+
async function updateHistoryName(id, name) {
history[history.findIndex(h=>h.id === id)].name = name;
const { http_error } = await request('chat/session', {
@@ -72,7 +77,8 @@ export default function useHistory(updated = null) {
updated && updated(history);
return {
- requestUpdateHistory, addHistory, getHistory, updateHistoryName, updateHistoryInfo,
+ requestUpdateHistory, addHistory, removeHistory,
+ getHistory, updateHistoryName, updateHistoryInfo,
componetDismount: dismount(mount_key), componentReMount
}
}
\ No newline at end of file
diff --git a/global/useModelSettings.js b/global/useModelSettings.js
index fa41d24..41c7a8b 100644
--- a/global/useModelSettings.js
+++ b/global/useModelSettings.js
@@ -5,8 +5,7 @@ const defaultSettings = {
temperature: 0.2,
top_k: 40,
top_p: 0.9,
- n_predict: 512,
- collection_name: 'collection_name'
+ n_predict: 512
}
const savedSettings = localStorage.getItem('model-settings') ?
diff --git a/settings.js b/settings.js
index ca6bd14..abcf99a 100644
--- a/settings.js
+++ b/settings.js
@@ -1,2 +1,2 @@
-export const VERSION = '0.1.8'
+export const VERSION = '0.1.9'
export const API_ADDRESS = '/api'
diff --git a/styles/chat_settings.css b/styles/chat_settings.css
index 9e9bad7..42cb54d 100644
--- a/styles/chat_settings.css
+++ b/styles/chat_settings.css
@@ -66,10 +66,17 @@
border: none;
font-size: 16px;
}
-.chat-settings .setting-section input[type="button"]:hover {
+.chat-settings .setting-section:not(.dangerous) input[type="button"]:hover {
background-color: var(--button-change-color);
}
+.confirm-delete-session .dangerous-btn,
+.setting-section.dangerous > input[type="button"] {
+ background-color: red;
+ color: white;
+ font-size: 16px;
+}
+
.chat-settings .setting-section input[type="text"]:focus,
.chat-settings .setting-section select:focus {
outline: none;
@@ -173,4 +180,24 @@
width: 30px;
height: 30px;
animation: rotateLoading 1s linear infinite;
+}
+
+.confirm-delete-session {
+ background-color: white;
+ border-radius: 10px;
+ margin: auto;
+ margin-top: 35vh;
+ padding: 30px;
+ width: fit-content;
+}
+
+.confirm-delete-session > div {
+ width: 160px;
+ padding: 0px 20px;
+ height: 40px;
+ border-radius: 10px;
+ align-content: center;
+ text-align: center;
+ margin: auto;
+ margin-top: 10px;
}
\ No newline at end of file