diff --git a/examples/server/public_simplechat/readme.md b/examples/server/public_simplechat/readme.md index 1643485f8..5ca5f4ac6 100644 --- a/examples/server/public_simplechat/readme.md +++ b/examples/server/public_simplechat/readme.md @@ -68,6 +68,7 @@ Once inside * oneshot or streamed mode. * In completion mode + * one normally doesnt use a system prompt in completion mode. * logic by default doesnt insert any role specific "ROLE: " prefix wrt each role's message. If the model requires any prefix wrt user role messages, then the end user has to explicitly add the needed prefix, when they enter their chat message. diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index d115fb9b7..6b25b73bc 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -55,6 +55,8 @@ let gUsageMsg = ` /** @typedef {{role: string, content: string}[]} ChatMessages */ +/** @typedef {{iLastSys: number, xchat: ChatMessages}} SimpleChatODS */ + class SimpleChat { /** @@ -76,6 +78,23 @@ class SimpleChat { this.iLastSys = -1; } + save() { + /** @type {SimpleChatODS} */ + let ods = {iLastSys: this.iLastSys, xchat: this.xchat}; + localStorage.setItem(this.chatId, JSON.stringify(ods)); + } + + load() { + let sods = localStorage.getItem(this.chatId); + if (sods == null) { + return; + } + /** @type {SimpleChatODS} */ + let ods = JSON.parse(sods); + this.iLastSys = ods.iLastSys; + this.xchat = ods.xchat; + } + /** * Recent chat messages. * If iRecentUserMsgCnt < 0 @@ -142,6 +161,7 @@ class SimpleChat { if (role == Roles.System) { this.iLastSys = this.xchat.length - 1; } + this.save(); return true; }