@@ -134,9 +134,7 @@ const ask_gpt = async (message) => {
134
134
135
135
chunk = decodeUnicode ( new TextDecoder ( ) . decode ( value ) ) ;
136
136
137
- if (
138
- chunk . includes ( `<form id="challenge-form" action="${ url_prefix } /backend-api/v2/conversation?` )
139
- ) {
137
+ if ( chunk . includes ( `<form id="challenge-form" action="${ url_prefix } /backend-api/v2/conversation?` ) ) {
140
138
chunk = `cloudflare token expired, please refresh the page.` ;
141
139
}
142
140
@@ -196,7 +194,10 @@ const ask_gpt = async (message) => {
196
194
197
195
const add_user_message_box = ( message ) => {
198
196
const messageDiv = createElement ( "div" , { classNames : [ "message" ] } ) ;
199
- const avatarContainer = createElement ( "div" , { classNames : [ "avatar-container" ] , innerHTML : user_image } ) ;
197
+ const avatarContainer = createElement ( "div" , {
198
+ classNames : [ "avatar-container" ] ,
199
+ innerHTML : user_image ,
200
+ } ) ;
200
201
const contentDiv = createElement ( "div" , {
201
202
classNames : [ "content" ] ,
202
203
id : `user_${ token } ` ,
@@ -266,6 +267,16 @@ const load_conversation = async (conversation_id) => {
266
267
let conversation = await JSON . parse ( localStorage . getItem ( `conversation:${ conversation_id } ` ) ) ;
267
268
console . log ( conversation , conversation_id ) ;
268
269
270
+ model = document . getElementById ( "model" ) ;
271
+ provider = document . getElementById ( "provider" ) ;
272
+ jailbreak = document . getElementById ( "jailbreak" ) ;
273
+ let hasModel = Array . from ( model . options ) . some ( ( option ) => option . value === conversation . model ) ;
274
+ let hasProvider = Array . from ( provider . options ) . some ( ( option ) => option . value === conversation . provider ) ;
275
+ let hasJailbreak = Array . from ( jailbreak . options ) . some ( ( option ) => option . value === conversation . jailbreak ) ;
276
+ if ( hasModel ) model . value = conversation . model ;
277
+ if ( hasProvider ) provider . value = conversation . provider ;
278
+ if ( hasJailbreak ) jailbreak . value = conversation . jailbreak ;
279
+
269
280
for ( item of conversation . items ) {
270
281
if ( is_assistant ( item . role ) ) {
271
282
message_box . innerHTML += load_gpt_message_box ( item . content ) ;
@@ -287,7 +298,10 @@ const load_conversation = async (conversation_id) => {
287
298
288
299
const load_user_message_box = ( content ) => {
289
300
const messageDiv = createElement ( "div" , { classNames : [ "message" ] } ) ;
290
- const avatarContainer = createElement ( "div" , { classNames : [ "avatar-container" ] , innerHTML : user_image } ) ;
301
+ const avatarContainer = createElement ( "div" , {
302
+ classNames : [ "avatar-container" ] ,
303
+ innerHTML : user_image ,
304
+ } ) ;
291
305
const contentDiv = createElement ( "div" , { classNames : [ "content" ] } ) ;
292
306
const preElement = document . createElement ( "pre" ) ;
293
307
preElement . textContent = content ;
@@ -322,19 +336,26 @@ const get_conversation = async (conversation_id) => {
322
336
323
337
const add_conversation = async ( conversation_id , title ) => {
324
338
if ( localStorage . getItem ( `conversation:${ conversation_id } ` ) == null ) {
339
+ jailbreak = document . getElementById ( "jailbreak" ) ;
340
+ model = document . getElementById ( "model" ) ;
341
+ provider = document . getElementById ( "provider" ) ;
325
342
localStorage . setItem (
326
343
`conversation:${ conversation_id } ` ,
327
344
JSON . stringify ( {
328
345
id : conversation_id ,
329
346
title : title ,
330
347
items : [ ] ,
348
+ created_at : Date . now ( ) ,
349
+ model : model . options [ model . selectedIndex ] . value ,
350
+ provider : provider . options [ provider . selectedIndex ] . value ,
351
+ jailbreak : jailbreak . options [ jailbreak . selectedIndex ] . value ,
331
352
} )
332
353
) ;
333
354
}
334
355
} ;
335
356
336
357
const add_message = async ( conversation_id , role , content ) => {
337
- before_adding = JSON . parse ( localStorage . getItem ( `conversation:${ conversation_id } ` ) ) ;
358
+ let before_adding = JSON . parse ( localStorage . getItem ( `conversation:${ conversation_id } ` ) ) ;
338
359
339
360
before_adding . items . push ( {
340
361
role : role ,
@@ -356,6 +377,8 @@ const load_conversations = async (limit, offset, loader) => {
356
377
}
357
378
}
358
379
380
+ conversations . sort ( ( a , b ) => b . created_at - a . created_at ) ;
381
+
359
382
//if (loader === undefined) spinner.parentNode.removeChild(spinner)
360
383
await clear_conversations ( ) ;
361
384
@@ -511,20 +534,20 @@ function createElement(tag, { classNames, id, innerHTML, textContent } = {}) {
511
534
el . appendChild ( preElement ) ;
512
535
}
513
536
return el ;
514
- } ;
537
+ }
515
538
516
539
//(async () => {
517
- //response = await fetch('/backend-api/v2/providers')
540
+ //response = await fetch('/backend-api/v2/providers')
518
541
// providers = await response.json()
519
-
542
+
520
543
// let select = document.getElementById('provider');
521
544
// select.textContent = '';
522
- //
545
+ //
523
546
// let auto = document.createElement('option');
524
547
// auto.value = '';
525
548
// auto.text = 'Provider: Auto';
526
549
// select.appendChild(auto);
527
- //
550
+ //
528
551
// for (provider of providers) {
529
552
// let option = document.createElement('option');
530
553
// option.value = option.text = provider;
0 commit comments