Skip to content

Commit

Permalink
history ng patch 1
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-husky committed Dec 21, 2024
1 parent 17b5c22 commit 4ec87fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
49 changes: 28 additions & 21 deletions themes/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,17 +940,17 @@ function gpt_academic_gradio_saveload(

function update_conversation_metadata() {
// Create a conversation UUID and timestamp
const conversationId = crypto.randomUUID();
const timestamp = new Date().toISOString();
const conversationData = {
id: conversationId,
timestamp: timestamp
};
// Save to cookie
setCookie("conversation_metadata", JSON.stringify(conversationData), 2);
// read from cookie
let conversation_metadata = getCookie("conversation_metadata");
// console.log("conversation_metadata", conversation_metadata);
try {
const conversationId = crypto.randomUUID();
const timestamp = new Date().toISOString();
const conversationData = {
id: conversationId,
timestamp: timestamp
};
setCookie("conversation_metadata", JSON.stringify(conversationData), 2);
} catch (e) {
console.error('Error in updating conversation metadata:', e);
}
}


Expand All @@ -970,16 +970,23 @@ async function save_conversation_history() {
let chatbot = await get_data_from_gradio_component('gpt-chatbot');
let history = await get_data_from_gradio_component('history-ng');
let conversation_metadata = getCookie("conversation_metadata");
conversation_metadata = JSON.parse(conversation_metadata);
// console.log("conversation_metadata", conversation_metadata);
let conversation = {
timestamp: conversation_metadata.timestamp,
id: conversation_metadata.id,
metadata: conversation_metadata,
conversation: chatbot,
history: history,
preview: generatePreview(JSON.parse(history), conversation_metadata.timestamp)
};
let conversation = {};
try {
conversation_metadata = JSON.parse(conversation_metadata);
conversation = {
timestamp: conversation_metadata.timestamp,
id: conversation_metadata.id,
metadata: conversation_metadata,
conversation: chatbot,
history: history,
preview: generatePreview(JSON.parse(history), conversation_metadata.timestamp)
};
} catch (e) {
console.log(history);
console.error('Conversation metadata parse error');
update_conversation_metadata();
return;
}

// Get existing conversation history from local storage
let conversation_history = [];
Expand Down
1 change: 1 addition & 0 deletions toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def update_ui(chatbot:ChatBotWithCookies, history:list, msg:str="正常", **kwar
else:
chatbot_gr = chatbot

history = [str(history_item) for history_item in history] # ensure all items are string
json_history = json.dumps(history, ensure_ascii=False)
yield cookies, chatbot_gr, json_history, msg

Expand Down

0 comments on commit 4ec87fb

Please sign in to comment.