Advertisement
Guest User

Untitled

a guest
Jul 30th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.17 KB | None | 0 0
  1. Subject: [PATCH] Forget
  2. ---
  3. Index: backend/sessions.py
  4. IDEA additional info:
  5. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  6. <+>UTF-8
  7. ===================================================================
  8. diff --git a/backend/sessions.py b/backend/sessions.py
  9. --- a/backend/sessions.py   (revision 396a56f0372ab3d498a394eac95316e28ecb4e4e)
  10. +++ b/backend/sessions.py   (revision 52007e41ce322e84bae6d6b95206f11190a80f2b)
  11. @@ -168,6 +168,11 @@
  12.          self.settings = settings
  13.  
  14.  
  15. +    def reset_cache(self):
  16. +        # print(f"Cleaning cache for session: {self.filename()}")
  17. +        get_loaded_model().cache.reset()
  18. +
  19. +
  20.      def load(self):
  21.          # print(f"Loading session: {self.filename()}")
  22.          with open(self.filename(), "r") as s:
  23. Index: server.py
  24. IDEA additional info:
  25. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  26. <+>UTF-8
  27. ===================================================================
  28. diff --git a/server.py b/server.py
  29. --- a/server.py (revision 396a56f0372ab3d498a394eac95316e28ecb4e4e)
  30. +++ b/server.py (revision 52007e41ce322e84bae6d6b95206f11190a80f2b)
  31. @@ -15,7 +15,6 @@
  32.  from backend.prompts import list_prompt_formats
  33.  from backend.settings import get_settings, set_settings
  34.  
  35. -
  36.  if os.name == "nt":
  37.      # Fix Windows inferring text/plain MIME type for static files
  38.      # https://stackoverflow.com/questions/59355194/
  39. @@ -176,6 +175,17 @@
  40.          if verbose: print("->", result)
  41.          return json.dumps(result) + "\n"
  42.  
  43. +@app.route("/api/clean_cache", methods=['POST'])
  44. +def api_clean_cache():
  45. +    global api_lock, verbose
  46. +    if verbose: print("/api/clean_cache")
  47. +    with api_lock:
  48. +        s = get_session()
  49. +        s.reset_cache()
  50. +        result = { "result": "ok" }
  51. +        if verbose: print("->", result)
  52. +        return json.dumps(result) + "\n"
  53. +
  54.  @app.route("/api/update_settings", methods=['POST'])
  55.  def api_update_settings():
  56.      global api_lock, verbose
  57. Index: static/chat.js
  58. IDEA additional info:
  59. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  60. <+>UTF-8
  61. ===================================================================
  62. diff --git a/static/chat.js b/static/chat.js
  63. --- a/static/chat.js    (revision 396a56f0372ab3d498a394eac95316e28ecb4e4e)
  64. +++ b/static/chat.js    (revision 52007e41ce322e84bae6d6b95206f11190a80f2b)
  65. @@ -255,13 +255,17 @@
  66.  
  67.          this.inputButton = new controls.Button("⏵ Chat", () => { this.submitInput() }, "session-input-button");
  68.          this.cancelButton = new controls.Button("⏹ Stop", () => { this.cancelGen() }, "session-input-button");
  69. +        this.resetButton = new controls.Button("Forget", () => { this.cleanCache() }, "session-input-button");
  70.          this.inputButton.setHidden(false);
  71.          this.cancelButton.setHidden(true);
  72. +        this.resetButton.setHidden(false);
  73.          this.inputButton.refresh();
  74.          this.cancelButton.refresh();
  75. +        this.resetButton.refresh();
  76.          sdiv.appendChild(div);
  77.          sdiv.appendChild(this.inputButton.element);
  78.          sdiv.appendChild(this.cancelButton.element);
  79. +        sdiv.appendChild(this.resetButton.element);
  80.          return sdiv;
  81.      }
  82.  
  83. @@ -335,6 +339,23 @@
  84.              });
  85.          }
  86.      }
  87. +
  88. +    cleanCache() {
  89. +        let packet = {};
  90. +        if (!this.sessionID || this.sessionID == "new") {
  91. +            fetch("/api/new_session", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(packet) })
  92. +            .then(response => response.json())
  93. +            .then(response => {
  94. +                if (post) post(response);
  95. +            });
  96. +        } else {
  97. +            fetch("/api/clean_cache", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(packet) })
  98. +            .then(response => response.json())
  99. +            .then(response => {
  100. +                if (post) post(response);
  101. +            });
  102. +        }
  103. +    }
  104.  
  105.      submitInput() {
  106.          let input = this.sessionInput.value.trim();
  107. @@ -838,4 +859,4 @@
  108.          block.parent.currentStreamingBlock = block;
  109.          block.parent.getModelResponse(block.block.block_uuid, block.block.text);
  110.      }
  111. -}
  112. \ No newline at end of file
  113. +}
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement