← back to Exo
clean up download progress
4746ffdd607b5f6e17cc0d2d829ac5f4d57bc350 · 2024-10-03 00:04:39 +0400 · Alex Cheema
Files touched
M exo/api/chatgpt_api.pyM exo/main.pyM exo/tinychat/index.js
Diff
commit 4746ffdd607b5f6e17cc0d2d829ac5f4d57bc350
Author: Alex Cheema <alexcheema123@gmail.com>
Date: Thu Oct 3 00:04:39 2024 +0400
clean up download progress
---
exo/api/chatgpt_api.py | 12 ++++--------
exo/main.py | 4 ----
exo/tinychat/index.js | 42 ++++--------------------------------------
3 files changed, 8 insertions(+), 50 deletions(-)
diff --git a/exo/api/chatgpt_api.py b/exo/api/chatgpt_api.py
index be3b2712..035344f7 100644
--- a/exo/api/chatgpt_api.py
+++ b/exo/api/chatgpt_api.py
@@ -209,14 +209,10 @@ class ChatGPTAPI:
async def handle_get_download_progress(self, request):
progress_data = {}
for node_id, progress_event in self.node.node_download_progress.items():
- if isinstance(progress_event, RepoProgressEvent):
- # Convert to dict if not already
- progress_data[node_id] = progress_event.to_dict()
- elif isinstance(progress_event, dict):
- progress_data[node_id] = progress_event
- else:
- # Handle unexpected types
- progress_data[node_id] = str(progress_event)
+ if isinstance(progress_event, RepoProgressEvent):
+ progress_data[node_id] = progress_event.to_dict()
+ else:
+ print(f"Unknown progress event type: {type(progress_event)}. {progress_event}")
return web.json_response(progress_data)
diff --git a/exo/main.py b/exo/main.py
index b606452a..49774da9 100644
--- a/exo/main.py
+++ b/exo/main.py
@@ -90,8 +90,6 @@ node = StandardNode(
)
server = GRPCServer(node, args.node_host, args.node_port)
node.server = server
-node.download_progress = {} # Initialize download progress tracking
-node.node_download_progress = {} # For tracking per-node download progress
api = ChatGPTAPI(
node,
inference_engine.__class__.__name__,
@@ -125,8 +123,6 @@ def throttled_broadcast(shard: Shard, event: RepoProgressEvent):
current_time = time.time()
if event.status == "complete" or current_time - last_broadcast_time >= 0.1:
last_broadcast_time = current_time
- node.download_progress[event.repo_id] = event.to_dict()
- node.node_download_progress[node.id] = event.to_dict()
asyncio.create_task(node.broadcast_opaque_status("", json.dumps({
"type": "download_progress",
"node_id": node.id,
diff --git a/exo/tinychat/index.js b/exo/tinychat/index.js
index e8c40b9f..665ee39a 100644
--- a/exo/tinychat/index.js
+++ b/exo/tinychat/index.js
@@ -32,8 +32,10 @@ document.addEventListener("alpine:init", () => {
init() {
// Clean up any pending messages
- this.pendingMessage = null;
localStorage.removeItem("pendingMessage");
+
+ // Start polling for download progress
+ this.startDownloadProgressPolling();
},
removeHistory(cstate) {
@@ -107,36 +109,14 @@ document.addEventListener("alpine:init", () => {
// Proceed to handle the message
this.processMessage(value);
-
- // Start polling for download progress
- this.startDownloadProgressPolling();
-
- // Delay the check for downloadProgress by 8 seconds without blocking execution
- setTimeout(async () => {
- this.pendingMessageHandler(value);
- }, 8000);
-
} catch (error) {
console.error('error', error)
this.errorMessage = error.message || 'Errore durante l\'invio del messaggio.';
setTimeout(() => {
this.errorMessage = null;
}, 5 * 1000)
- }
- },
-
- async pendingMessageHandler(value) {
- console.log("Pending message handler called");
- // Check if download is in progress
- if (this.downloadProgress && this.downloadProgress.status !== "complete") {
- // Save the message in pendingMessage
- this.pendingMessage = value;
localStorage.setItem("pendingMessage", value);
- console.log("Pending message saved:", localStorage.getItem("pendingMessage"));
- // Inform the user
- this.cstate.messages.push({ role: "system", content: "Download is in progress. Your message will be processed once the download completes." });
- this.generating = false; // Reset generating
- return;
+ this.generating = false;
}
},
@@ -325,8 +305,6 @@ document.addEventListener("alpine:init", () => {
async fetchDownloadProgress() {
try {
- console.log("fetching download progress");
- await new Promise(resolve => setTimeout(resolve, 4000)); // Necessary delay
const response = await fetch(`${this.endpoint}/download/progress`);
if (response.ok) {
const data = await response.json();
@@ -336,8 +314,6 @@ document.addEventListener("alpine:init", () => {
// Check if download is complete
if (progress.status === "complete" || progress.status === "failed") {
this.downloadProgress = null; // Hide the progress section
- // Stop polling
- this.stopDownloadProgressPolling();
if (progress.status === "complete") {
// Download is complete
@@ -345,7 +321,6 @@ document.addEventListener("alpine:init", () => {
const savedMessage = localStorage.getItem("pendingMessage");
if (savedMessage) {
// Clear pendingMessage
- this.pendingMessage = null;
localStorage.removeItem("pendingMessage");
// Call processMessage() with savedMessage
await this.processMessage(savedMessage);
@@ -364,8 +339,6 @@ document.addEventListener("alpine:init", () => {
} else {
// No ongoing download
this.downloadProgress = null;
- // Stop polling
- this.stopDownloadProgressPolling();
}
}
} catch (error) {
@@ -386,13 +359,6 @@ document.addEventListener("alpine:init", () => {
this.fetchDownloadProgress();
}, 1000); // Poll every second
},
-
- stopDownloadProgressPolling() {
- if (this.downloadProgressInterval) {
- clearInterval(this.downloadProgressInterval);
- this.downloadProgressInterval = null;
- }
- },
}));
});
← 5521dcbf add script to calculate pipsize
·
back to Exo
·
more robust handling of timeouts c3864f5e →