Spaces:
No application file
No application file
Download models.py from Pankaj10346/Openenv-Hackathon: direct link, hf CLI and curl.
- Browser
- Download file 2.7 kB
-
https://huggingface.co/spaces/Pankaj10346/Openenv-Hackathon/resolve/main/models.py
- Command line
-
hf download hf://spaces/Pankaj10346/Openenv-Hackathon/models.py
-
curl -L -o models.py https://huggingface.co/spaces/Pankaj10346/Openenv-Hackathon/resolve/main/models.py
2.7 kB
| """ | |
| Pydantic models for the Legal Contract Clause Review environment. | |
| """ | |
| from __future__ import annotations | |
| from typing import Any, Dict, List, Literal, Optional | |
| from openenv.core.env_server.types import Action, Observation, State | |
| from pydantic import Field, model_validator | |
| TaskName = Literal["classify", "risk", "fix"] | |
| STANDARD_RULES: Dict[str, str] = { | |
| "liability": "Liability capped at 1x fees", | |
| "termination": "Either party can terminate with 30 days notice", | |
| "auto_renewal": "Renewal requires prior notice", | |
| } | |
| class ContractAction(Action): | |
| """Agent action for clause review workflow.""" | |
| action_type: Literal["classify_clause", "flag_risk", "suggest_fix", "finish"] | |
| clause_index: Optional[int] = None | |
| clause_type: Optional[str] = None | |
| risk_flag: Optional[bool] = None | |
| suggestion: Optional[str] = None | |
| def _validate_payload(self) -> ContractAction: | |
| if self.action_type == "classify_clause": | |
| if self.clause_index is None or self.clause_type is None: | |
| raise ValueError("classify_clause requires clause_index and clause_type") | |
| elif self.action_type == "flag_risk": | |
| if self.clause_index is None or self.risk_flag is None: | |
| raise ValueError("flag_risk requires clause_index and risk_flag") | |
| elif self.action_type == "suggest_fix": | |
| if self.clause_index is None or self.suggestion is None: | |
| raise ValueError("suggest_fix requires clause_index and suggestion") | |
| return self | |
| class ContractObservation(Observation): | |
| """What the agent sees each step (no hidden ground-truth labels).""" | |
| document_text: str = "" | |
| clauses: List[str] = Field(default_factory=list) | |
| standard_rules: Dict[str, str] = Field(default_factory=dict) | |
| step_count: int = Field( | |
| 0, | |
| description="Steps taken in this contract-review episode (client-visible).", | |
| ) | |
| task: TaskName = "classify" | |
| message: str = "" | |
| grader_score: Optional[float] = Field( | |
| default=None, | |
| description="Task grader in [0,1] (set when episode completes).", | |
| ) | |
| episode_return: Optional[float] = Field( | |
| default=None, | |
| description="Cumulative reward for the episode when done.", | |
| ) | |
| class ContractState(State): | |
| """Server-visible session state (returned by state()).""" | |
| current_task: TaskName = "classify" | |
| current_clause_index: int = 0 | |
| completed_actions: List[str] = Field(default_factory=list) | |
| remaining_clauses: int = 0 | |
| episode_reward: float = 0.0 | |
| last_grader_score: Optional[float] = None | |
| last_info: Dict[str, Any] = Field(default_factory=dict) | |