Skip to content

Commit

Permalink
Bug fix (#57)
Browse files Browse the repository at this point in the history
* format link in markdown

Signed-off-by: cbh778899 <[email protected]>

* move switchPage back to index.js, previous version can cause bugs

Signed-off-by: cbh778899 <[email protected]>

* hide training page, we might recover it in furture

Signed-off-by: cbh778899 <[email protected]>

* parse no more string to html document to make sure the program is secure

Signed-off-by: cbh778899 <[email protected]>

* update email pattern

Signed-off-by: cbh778899 <[email protected]>

* update version

Signed-off-by: cbh778899 <[email protected]>

* comment out yeager route

Signed-off-by: cbh778899 <[email protected]>

* add dataset_name in chat request

Signed-off-by: cbh778899 <[email protected]>

* remove collection_name

Signed-off-by: cbh778899 <[email protected]>

* implement remove session

Signed-off-by: cbh778899 <[email protected]>

* update version

Signed-off-by: cbh778899 <[email protected]>

* Create FUNDING.yml (#56)

Signed-off-by: Bohan Cheng <[email protected]>

---------

Signed-off-by: cbh778899 <[email protected]>
Signed-off-by: Bohan Cheng <[email protected]>
  • Loading branch information
cbh778899 authored Jul 29, 2024
1 parent 7373b4c commit e874ab7
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 14 deletions.
3 changes: 2 additions & 1 deletion components/chat-page/chatMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions components/chat-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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());
Expand Down
38 changes: 36 additions & 2 deletions components/chat-page/session-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import rangeSettingSection from './range-setting-section.js';

let current_conversation = {}, user_id = null;
let rag_dataset_options = {};
let closeSetting;

// ===================================================
//
Expand All @@ -30,6 +31,30 @@ show_dataset_loading.innerHTML =
`${getSVG('arrow-clockwise')}<div>Dataset loading, please wait...</div>`
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 =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -201,13 +233,15 @@ session_settings.appendChild(dataset_list_elem);
session_settings.appendChild(dataset_range_elem);
session_settings.appendChild(submit_dataset_btn);
session_settings.insertAdjacentHTML("beforeend", "<hr class='rag-option hide-on-no-change'>");
session_settings.appendChild(delete_session_btn)

// ===================================================
//
// Entry
//
// ===================================================

export default function createSessionSettings(main) {
export default function createSessionSettings(main, close_setting) {
closeSetting = close_setting;
main.appendChild(session_settings);
}
4 changes: 2 additions & 2 deletions components/chat-page/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import createSessionSettings from "./session-settings.js";

let init = false

export default function createChatSettingsPage(main) {
export default function createChatSettingsPage(main, close_setting) {
if(!init) {
const setting_main = document.createElement('div');
setting_main.className = 'chat-settings'
setting_main.onclick = evt => evt.stopPropagation();

createSessionSettings(setting_main);
createSessionSettings(setting_main, close_setting);
createModelSettings(setting_main);

main.appendChild(setting_main);
Expand Down
23 changes: 21 additions & 2 deletions global/useConversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 7 additions & 1 deletion global/useHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -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
}
}
3 changes: 1 addition & 2 deletions global/useModelSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') ?
Expand Down
2 changes: 1 addition & 1 deletion settings.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const VERSION = '0.1.8'
export const VERSION = '0.1.9'
export const API_ADDRESS = '/api'
29 changes: 28 additions & 1 deletion styles/chat_settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

0 comments on commit e874ab7

Please sign in to comment.