From af91df85c27ef12ffc74852cf39ae0f1e33c417b Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Mon, 12 Jun 2023 14:34:30 -0400 Subject: [PATCH] Add a /history/{prompt_id} endpoint. --- execution.py | 9 +++++++-- server.py | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/execution.py b/execution.py index 218a84c3..fc9578bc 100644 --- a/execution.py +++ b/execution.py @@ -728,9 +728,14 @@ class PromptQueue: return True return False - def get_history(self): + def get_history(self, prompt_id=None): with self.mutex: - return copy.deepcopy(self.history) + if prompt_id is None: + return copy.deepcopy(self.history) + elif prompt_id in self.history: + return {prompt_id: copy.deepcopy(self.history[prompt_id])} + else: + return {} def wipe_history(self): with self.mutex: diff --git a/server.py b/server.py index 174d38af..300221f6 100644 --- a/server.py +++ b/server.py @@ -372,6 +372,11 @@ class PromptServer(): async def get_history(request): return web.json_response(self.prompt_queue.get_history()) + @routes.get("/history/{prompt_id}") + async def get_history(request): + prompt_id = request.match_info.get("prompt_id", None) + return web.json_response(self.prompt_queue.get_history(prompt_id=prompt_id)) + @routes.get("/queue") async def get_queue(request): queue_info = {}