File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
examples/server/public_simplechat Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ Once inside
68
68
* oneshot or streamed mode.
69
69
70
70
* In completion mode
71
+ * one normally doesnt use a system prompt in completion mode.
71
72
* logic by default doesnt insert any role specific "ROLE: " prefix wrt each role's message.
72
73
If the model requires any prefix wrt user role messages, then the end user has to
73
74
explicitly add the needed prefix, when they enter their chat message.
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ let gUsageMsg = `
55
55
56
56
/** @typedef {{role: string, content: string}[] } ChatMessages */
57
57
58
+ /** @typedef {{iLastSys: number, xchat: ChatMessages} } SimpleChatODS */
59
+
58
60
class SimpleChat {
59
61
60
62
/**
@@ -76,6 +78,23 @@ class SimpleChat {
76
78
this . iLastSys = - 1 ;
77
79
}
78
80
81
+ save ( ) {
82
+ /** @type {SimpleChatODS } */
83
+ let ods = { iLastSys : this . iLastSys , xchat : this . xchat } ;
84
+ localStorage . setItem ( this . chatId , JSON . stringify ( ods ) ) ;
85
+ }
86
+
87
+ load ( ) {
88
+ let sods = localStorage . getItem ( this . chatId ) ;
89
+ if ( sods == null ) {
90
+ return ;
91
+ }
92
+ /** @type {SimpleChatODS } */
93
+ let ods = JSON . parse ( sods ) ;
94
+ this . iLastSys = ods . iLastSys ;
95
+ this . xchat = ods . xchat ;
96
+ }
97
+
79
98
/**
80
99
* Recent chat messages.
81
100
* If iRecentUserMsgCnt < 0
@@ -142,6 +161,7 @@ class SimpleChat {
142
161
if ( role == Roles . System ) {
143
162
this . iLastSys = this . xchat . length - 1 ;
144
163
}
164
+ this . save ( ) ;
145
165
return true ;
146
166
}
147
167
You can’t perform that action at this time.
0 commit comments