Download src/clfgui/backend/profiles.py from smlflg/CLFGUI: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/smlflg/CLFGUI/resolve/main/src/clfgui/backend/profiles.py
- Command line
-
hf download hf://smlflg/CLFGUI/src/clfgui/backend/profiles.py
-
curl -L -o profiles.py https://huggingface.co/smlflg/CLFGUI/resolve/main/src/clfgui/backend/profiles.py
1.28 kB
| from __future__ import annotations | |
| import re | |
| from dataclasses import dataclass | |
| from pathlib import Path | |
| PROFILE_ID_RE = re.compile(r"^[a-z0-9][a-z0-9_-]{0,63}$") | |
| class AgentProfile: | |
| id: str | |
| name: str | |
| class InvalidAgentId(ValueError): | |
| pass | |
| class UnknownAgent(ValueError): | |
| pass | |
| class ProfileDiscovery: | |
| def __init__(self, profiles_dir: str | Path = "Hermes/profiles") -> None: | |
| self.profiles_dir = Path(profiles_dir) | |
| def list_agents(self) -> list[AgentProfile]: | |
| if not self.profiles_dir.exists(): | |
| return [] | |
| agents: list[AgentProfile] = [] | |
| for child in sorted(self.profiles_dir.iterdir(), key=lambda item: item.name): | |
| if child.is_dir() and PROFILE_ID_RE.fullmatch(child.name): | |
| agents.append(AgentProfile(id=child.name, name=child.name)) | |
| return agents | |
| def validate_agent_id(self, agent_id: str) -> str: | |
| if not PROFILE_ID_RE.fullmatch(agent_id): | |
| raise InvalidAgentId("Invalid agent_id.") | |
| path = (self.profiles_dir / agent_id).resolve() | |
| root = self.profiles_dir.resolve() | |
| if path.parent != root or not path.is_dir(): | |
| raise UnknownAgent("Unknown agent_id.") | |
| return agent_id | |