Spaces:
Running
Running
Download plugins/_chat_naming/commands/rename_command.py from Leon4gr45/openoperator: direct link, hf CLI and curl.
- Browser
- Download file 909 Bytes
-
https://huggingface.co/spaces/Leon4gr45/openoperator/resolve/main/plugins/_chat_naming/commands/rename_command.py
- Command line
-
hf download hf://spaces/Leon4gr45/openoperator/plugins/_chat_naming/commands/rename_command.py
-
curl -L -o rename_command.py https://huggingface.co/spaces/Leon4gr45/openoperator/resolve/main/plugins/_chat_naming/commands/rename_command.py
909 Bytes
| from __future__ import annotations | |
| from typing import Any | |
| from plugins._chat_naming.helpers import naming | |
| async def run(payload: dict[str, Any]) -> dict[str, Any]: | |
| invocation = payload.get("invocation") or {} | |
| raw_name = str(invocation.get("raw_arguments") or "").strip() | |
| agent = (payload.get("context") or {}).get("agent") | |
| if not agent: | |
| return _toast("Open or create a chat context first.", level="error") | |
| if not raw_name: | |
| return _toast("Usage: /rename <new name|auto>", level="error") | |
| if raw_name.casefold() == "auto": | |
| raw_name = await naming.generate_name(agent) | |
| name = naming.save_context_name(agent, raw_name) | |
| return _toast(f'Chat renamed to "{name}".') | |
| def _toast(message: str, *, level: str = "success") -> dict[str, Any]: | |
| return { | |
| "text": "", | |
| "effects": [{"type": "toast", "message": message, "level": level}], | |
| } | |