[object Object]

← back to Exo

Added clear all history button

0d8a1ee41e57358c44e3bc7276570f07da948db5 · 2024-11-09 21:11:29 -0500 · Sami Khan

Files touched

Diff

commit 0d8a1ee41e57358c44e3bc7276570f07da948db5
Author: Sami Khan <smsak99@gmail.com>
Date:   Sat Nov 9 21:11:29 2024 -0500

    Added clear all history button
---
 exo/inference/tinygrad/inference.py |  4 ++--
 exo/tinychat/index.css              | 23 +++++++++++++++++++++++
 exo/tinychat/index.html             |  7 +++++++
 exo/tinychat/index.js               |  6 ++++++
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/exo/inference/tinygrad/inference.py b/exo/inference/tinygrad/inference.py
index 1a3f65f4..fd50adda 100644
--- a/exo/inference/tinygrad/inference.py
+++ b/exo/inference/tinygrad/inference.py
@@ -55,7 +55,7 @@ class TinygradDynamicShardInferenceEngine(InferenceEngine):
     self.shard_downloader = shard_downloader
     self.executor = ThreadPoolExecutor(max_workers=1)
 
-  async def infer_prompt(self, request_id: str, shard: Shard, prompt: str, image_str: Optional[str] = None, inference_state: Optional[str] = None) -> (np.ndarray, str, bool):
+  async def infer_prompt(self, request_id: str, shard: Shard, prompt: str, image_str: Optional[str] = None, inference_state: Optional[str] = None) -> tuple[np.ndarray, str, bool]:
     await self.ensure_shard(shard)
     start_pos = json.loads(inference_state or "{}").get("start_pos", 0)
     n_captured_toks = json.loads(inference_state or "{}").get("n_captured_toks", 0)
@@ -72,7 +72,7 @@ class TinygradDynamicShardInferenceEngine(InferenceEngine):
       n_captured_toks = len(toks)
       return h.numpy(), json.dumps({"start_pos": start_pos, "n_captured_toks": n_captured_toks}), False
 
-  async def infer_tensor(self, request_id: str, shard: Shard, input_data: np.ndarray, inference_state: Optional[str] = None) -> Tuple[np.ndarray, str, bool]:
+  async def infer_tensor(self, request_id: str, shard: Shard, input_data: np.ndarray, inference_state: Optional[str] = None) -> tuple[np.ndarray, str, bool]:
     await self.ensure_shard(shard)
     start_pos = json.loads(inference_state or "{}").get("start_pos", 0)
     n_captured_toks = json.loads(inference_state or "{}").get("n_captured_toks", 0)
diff --git a/exo/tinychat/index.css b/exo/tinychat/index.css
index 95213929..c873412d 100644
--- a/exo/tinychat/index.css
+++ b/exo/tinychat/index.css
@@ -414,4 +414,27 @@ p {
   max-width: 100%;
   max-height: 100%;
   object-fit: contain;
+}
+
+.clear-history-button {
+  background-color: var(--red-color);
+  color: white;
+  padding: 10px 20px;
+  border-radius: 5px;
+  display: flex;
+  align-items: center;
+  gap: 8px;
+  transition: all 0.3s ease;
+  margin: 1rem auto;
+  border: none;
+  cursor: pointer;
+}
+
+.clear-history-button:hover {
+  opacity: 0.8;
+  transform: scale(1.05);
+}
+
+.clear-history-button i {
+  font-size: 14px;
 }
\ No newline at end of file
diff --git a/exo/tinychat/index.html b/exo/tinychat/index.html
index 07952423..5a7e7038 100644
--- a/exo/tinychat/index.html
+++ b/exo/tinychat/index.html
@@ -71,6 +71,13 @@
       if (home === -1) setTimeout(() =&gt; home = 0, 100);
     " x-show="home === 0" x-transition="">
 <h1 class="title megrim-regular">tinychat</h1>
+<template x-if="histories.length">
+  <button 
+    @click="if(confirm('Are you sure you want to clear all history?')) clearAllHistory();" 
+    class="clear-history-button">
+    <i class="fas fa-trash"></i> Clear All History
+  </button>
+</template>
 <div class="histories-container-container">
 <template x-if="histories.length">
 <div class="histories-start"></div>
diff --git a/exo/tinychat/index.js b/exo/tinychat/index.js
index 01b082c1..0d2f0654 100644
--- a/exo/tinychat/index.js
+++ b/exo/tinychat/index.js
@@ -47,6 +47,12 @@ document.addEventListener("alpine:init", () => {
         localStorage.setItem("histories", JSON.stringify(this.histories));
       }
     },
+
+    clearAllHistory() {
+      this.histories = [];
+      localStorage.setItem("histories", JSON.stringify([]));
+    },
+
     // Utility functions
     formatBytes(bytes) {
       if (bytes === 0) return '0 B';

← f1c74732 m4 device capabilities  ·  back to Exo  ·  add llama 3.1 405b 8bit at mlx-community/Meta-Llama-3.1-405B 98948441 →