Update app.py
Browse files
app.py
CHANGED
@@ -239,13 +239,29 @@ theme = gr.themes.Base(
|
|
239 |
)
|
240 |
|
241 |
js_code = """
|
242 |
-
function saveChat(chat) {
|
243 |
-
localStorage.setItem('chatHistory', JSON.stringify(chat));
|
244 |
-
}
|
245 |
-
|
246 |
function loadChat() {
|
247 |
const chatHistory = localStorage.getItem('chatHistory');
|
248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
}
|
250 |
"""
|
251 |
|
|
|
239 |
)
|
240 |
|
241 |
js_code = """
|
|
|
|
|
|
|
|
|
242 |
function loadChat() {
|
243 |
const chatHistory = localStorage.getItem('chatHistory');
|
244 |
+
if (chatHistory) {
|
245 |
+
try {
|
246 |
+
const parsedHistory = JSON.parse(chatHistory);
|
247 |
+
if (Array.isArray(parsedHistory)) {
|
248 |
+
// Her öğenin 'role' ve 'content' anahtarlarına sahip bir sözlük olduğunu kontrol et
|
249 |
+
if (parsedHistory.every(item => typeof item === 'object' && item !== null && 'role' in item && 'content' in item)) {
|
250 |
+
return parsedHistory;
|
251 |
+
} else {
|
252 |
+
console.error('localStorage: Chat history items are not in the correct format.');
|
253 |
+
return [];
|
254 |
+
}
|
255 |
+
} else {
|
256 |
+
console.error('localStorage: Chat history is not an array.');
|
257 |
+
return [];
|
258 |
+
}
|
259 |
+
} catch (e) {
|
260 |
+
console.error('localStorage: Error parsing chat history:', e);
|
261 |
+
return [];
|
262 |
+
}
|
263 |
+
}
|
264 |
+
return [];
|
265 |
}
|
266 |
"""
|
267 |
|