Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Subject: [PATCH] Forget
- ---
- Index: backend/sessions.py
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/backend/sessions.py b/backend/sessions.py
- --- a/backend/sessions.py (revision 396a56f0372ab3d498a394eac95316e28ecb4e4e)
- +++ b/backend/sessions.py (revision 52007e41ce322e84bae6d6b95206f11190a80f2b)
- @@ -168,6 +168,11 @@
- self.settings = settings
- + def reset_cache(self):
- + # print(f"Cleaning cache for session: {self.filename()}")
- + get_loaded_model().cache.reset()
- +
- +
- def load(self):
- # print(f"Loading session: {self.filename()}")
- with open(self.filename(), "r") as s:
- Index: server.py
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/server.py b/server.py
- --- a/server.py (revision 396a56f0372ab3d498a394eac95316e28ecb4e4e)
- +++ b/server.py (revision 52007e41ce322e84bae6d6b95206f11190a80f2b)
- @@ -15,7 +15,6 @@
- from backend.prompts import list_prompt_formats
- from backend.settings import get_settings, set_settings
- -
- if os.name == "nt":
- # Fix Windows inferring text/plain MIME type for static files
- # https://stackoverflow.com/questions/59355194/
- @@ -176,6 +175,17 @@
- if verbose: print("->", result)
- return json.dumps(result) + "\n"
- +@app.route("/api/clean_cache", methods=['POST'])
- +def api_clean_cache():
- + global api_lock, verbose
- + if verbose: print("/api/clean_cache")
- + with api_lock:
- + s = get_session()
- + s.reset_cache()
- + result = { "result": "ok" }
- + if verbose: print("->", result)
- + return json.dumps(result) + "\n"
- +
- @app.route("/api/update_settings", methods=['POST'])
- def api_update_settings():
- global api_lock, verbose
- Index: static/chat.js
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/static/chat.js b/static/chat.js
- --- a/static/chat.js (revision 396a56f0372ab3d498a394eac95316e28ecb4e4e)
- +++ b/static/chat.js (revision 52007e41ce322e84bae6d6b95206f11190a80f2b)
- @@ -255,13 +255,17 @@
- this.inputButton = new controls.Button("⏵ Chat", () => { this.submitInput() }, "session-input-button");
- this.cancelButton = new controls.Button("⏹ Stop", () => { this.cancelGen() }, "session-input-button");
- + this.resetButton = new controls.Button("Forget", () => { this.cleanCache() }, "session-input-button");
- this.inputButton.setHidden(false);
- this.cancelButton.setHidden(true);
- + this.resetButton.setHidden(false);
- this.inputButton.refresh();
- this.cancelButton.refresh();
- + this.resetButton.refresh();
- sdiv.appendChild(div);
- sdiv.appendChild(this.inputButton.element);
- sdiv.appendChild(this.cancelButton.element);
- + sdiv.appendChild(this.resetButton.element);
- return sdiv;
- }
- @@ -335,6 +339,23 @@
- });
- }
- }
- +
- + cleanCache() {
- + let packet = {};
- + if (!this.sessionID || this.sessionID == "new") {
- + fetch("/api/new_session", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(packet) })
- + .then(response => response.json())
- + .then(response => {
- + if (post) post(response);
- + });
- + } else {
- + fetch("/api/clean_cache", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(packet) })
- + .then(response => response.json())
- + .then(response => {
- + if (post) post(response);
- + });
- + }
- + }
- submitInput() {
- let input = this.sessionInput.value.trim();
- @@ -838,4 +859,4 @@
- block.parent.currentStreamingBlock = block;
- block.parent.getModelResponse(block.block.block_uuid, block.block.text);
- }
- -}
- \ No newline at end of file
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement