Spaces:
Paused
Paused
Download python/api/chat_remove.py from OnyxMunk/GravityFalls: direct link, hf CLI and curl.
- Browser
- Download file 843 Bytes
-
https://huggingface.co/spaces/OnyxMunk/GravityFalls/resolve/main/python/api/chat_remove.py
- Command line
-
hf download hf://spaces/OnyxMunk/GravityFalls/python/api/chat_remove.py
-
curl -L -o chat_remove.py https://huggingface.co/spaces/OnyxMunk/GravityFalls/resolve/main/python/api/chat_remove.py
843 Bytes
| from python.helpers.api import ApiHandler, Input, Output, Request, Response | |
| from agent import AgentContext | |
| from python.helpers import persist_chat | |
| from python.helpers.task_scheduler import TaskScheduler | |
| class RemoveChat(ApiHandler): | |
| async def process(self, input: Input, request: Request) -> Output: | |
| ctxid = input.get("context", "") | |
| context = AgentContext.use(ctxid) | |
| if context: | |
| # stop processing any tasks | |
| context.reset() | |
| AgentContext.remove(ctxid) | |
| persist_chat.remove_chat(ctxid) | |
| scheduler = TaskScheduler.get() | |
| await scheduler.reload() | |
| tasks = scheduler.get_tasks_by_context_id(ctxid) | |
| for task in tasks: | |
| await scheduler.remove_task_by_uuid(task.uuid) | |
| return { | |
| "message": "Context removed.", | |
| } | |