Spaces:
Running
Running
Download api/chat_reset.py from Leon4gr45/openoperator: direct link, hf CLI and curl.
- Browser
- Download file 933 Bytes
-
https://huggingface.co/spaces/Leon4gr45/openoperator/resolve/main/api/chat_reset.py
- Command line
-
hf download hf://spaces/Leon4gr45/openoperator/api/chat_reset.py
-
curl -L -o chat_reset.py https://huggingface.co/spaces/Leon4gr45/openoperator/resolve/main/api/chat_reset.py
933 Bytes
| from helpers.api import ApiHandler, Input, Output, Request, Response | |
| from helpers import persist_chat | |
| from helpers.task_scheduler import TaskScheduler | |
| class Reset(ApiHandler): | |
| async def process(self, input: Input, request: Request) -> Output: | |
| ctxid = input.get("context", "") | |
| # attempt to stop any scheduler tasks bound to this context | |
| TaskScheduler.get().cancel_tasks_by_context(ctxid, terminate_thread=True) | |
| # context instance - get or create | |
| context = self.use_context(ctxid) | |
| context.reset() | |
| persist_chat.save_tmp_chat(context) | |
| persist_chat.remove_msg_files(ctxid) | |
| # Reset updates context metadata (log guid/version) and must refresh other tabs' lists. | |
| from helpers.state_monitor_integration import mark_dirty_all | |
| mark_dirty_all(reason="api.chat_reset.Reset") | |
| return { | |
| "message": "Agent restarted.", | |
| } | |