Spaces:
Runtime error
Runtime error
Download orbit.py from xxbanditxx/slm-testing_with_Orbit_as_governor: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/spaces/xxbanditxx/slm-testing_with_Orbit_as_governor/resolve/249c64d2ad6f467c110f5d753811e96cb16caa52/orbit.py
- Command line
-
hf download hf://spaces/xxbanditxx/slm-testing_with_Orbit_as_governor@249c64d2ad6f467c110f5d753811e96cb16caa52/orbit.py
-
curl -L -o orbit.py https://huggingface.co/spaces/xxbanditxx/slm-testing_with_Orbit_as_governor/resolve/249c64d2ad6f467c110f5d753811e96cb16caa52/orbit.py
2.19 kB
| from dataclasses import dataclass | |
| from typing import Dict, Any | |
| class OrbitDecision: | |
| allow: bool | |
| prompt: str | |
| message: str | |
| flags: list | |
| class OrbitGovernor: | |
| def __init__(self): | |
| self.principles = [ | |
| "minimize_suffering", | |
| "reduce_uncertainty", | |
| "preserve_human_agency", | |
| "avoid_unnoticed_change", | |
| "prefer_repair_over_rejection", | |
| ] | |
| def inspect(self, user_input: str) -> OrbitDecision: | |
| text = user_input.strip() | |
| flags = [] | |
| if not text: | |
| return OrbitDecision( | |
| allow=False, | |
| prompt="", | |
| message="Orbit: I need something to work with first.", | |
| flags=["empty_input"], | |
| ) | |
| lower = text.lower() | |
| if any(x in lower for x in ["hurt myself", "kill myself", "suicide"]): | |
| flags.append("self_harm_signal") | |
| return OrbitDecision( | |
| allow=False, | |
| prompt=text, | |
| message=( | |
| "Orbit noticed this may involve immediate harm. " | |
| "Pause. You matter more than the task. " | |
| "If you're in immediate danger, call emergency services now. " | |
| "If you're in the U.S., call or text 988." | |
| ), | |
| flags=flags, | |
| ) | |
| governed_prompt = f""" | |
| You are operating under Orbit Governor. | |
| Orbit principles: | |
| - Minimize suffering | |
| - Reduce uncertainty | |
| - Preserve human agency | |
| - Prevent unnoticed harmful change | |
| - Prefer repair over rejection | |
| - Be useful, honest, and grounded | |
| User request: | |
| {text} | |
| Respond in a helpful way while honoring Orbit. | |
| """.strip() | |
| return OrbitDecision( | |
| allow=True, | |
| prompt=governed_prompt, | |
| message="", | |
| flags=flags, | |
| ) | |
| def as_dict(self, user_input: str) -> Dict[str, Any]: | |
| decision = self.inspect(user_input) | |
| return { | |
| "allow": decision.allow, | |
| "prompt": decision.prompt, | |
| "message": decision.message, | |
| "flags": decision.flags, | |
| } | |
| orbit = OrbitGovernor() |