Spaces:
Sleeping
Sleeping
Upload models.py with huggingface_hub
Browse files
models.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Bug Report Structuring Environment - Data Models
|
| 3 |
+
|
| 4 |
+
Defines typed request/response models for the OpenEnv API:
|
| 5 |
+
- BugReportAction: What the agent submits (structured bug report)
|
| 6 |
+
- BugReportObservation: What the environment returns (feedback + score)
|
| 7 |
+
- BugReportState: Episode metadata
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from pydantic import BaseModel, Field
|
| 11 |
+
from typing import Optional, Dict, List
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# βββ Request Models βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 15 |
+
|
| 16 |
+
class ResetRequest(BaseModel):
|
| 17 |
+
"""Request body for POST /reset"""
|
| 18 |
+
task_id: Optional[str] = Field(
|
| 19 |
+
default=None,
|
| 20 |
+
description="Task difficulty: 'easy', 'medium', or 'hard'. Random if not specified."
|
| 21 |
+
)
|
| 22 |
+
seed: Optional[int] = Field(default=None, description="Random seed for reproducibility")
|
| 23 |
+
episode_id: Optional[str] = Field(default=None, description="Custom episode ID")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class BugReportAction(BaseModel):
|
| 27 |
+
"""
|
| 28 |
+
The structured bug report submitted by the agent.
|
| 29 |
+
This is the action the agent takes at each step.
|
| 30 |
+
"""
|
| 31 |
+
title: str = Field(
|
| 32 |
+
...,
|
| 33 |
+
description="Clear, concise bug title"
|
| 34 |
+
)
|
| 35 |
+
steps_to_reproduce: str = Field(
|
| 36 |
+
...,
|
| 37 |
+
description="Step-by-step reproduction instructions"
|
| 38 |
+
)
|
| 39 |
+
expected_behavior: str = Field(
|
| 40 |
+
...,
|
| 41 |
+
description="What should happen"
|
| 42 |
+
)
|
| 43 |
+
actual_behavior: str = Field(
|
| 44 |
+
...,
|
| 45 |
+
description="What actually happens"
|
| 46 |
+
)
|
| 47 |
+
severity: str = Field(
|
| 48 |
+
...,
|
| 49 |
+
description="Severity level: 'low', 'medium', 'high', or 'critical'"
|
| 50 |
+
)
|
| 51 |
+
environment: str = Field(
|
| 52 |
+
...,
|
| 53 |
+
description="OS, browser, version, platform info"
|
| 54 |
+
)
|
| 55 |
+
additional_notes: Optional[str] = Field(
|
| 56 |
+
default="",
|
| 57 |
+
description="Any additional relevant information"
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class StepRequest(BaseModel):
|
| 62 |
+
"""Request body for POST /step"""
|
| 63 |
+
action: BugReportAction
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# βββ Response Models ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 67 |
+
|
| 68 |
+
class BugReportObservation(BaseModel):
|
| 69 |
+
"""
|
| 70 |
+
What the environment returns after reset() or step().
|
| 71 |
+
Contains the raw report, feedback, and scoring.
|
| 72 |
+
"""
|
| 73 |
+
raw_report: str = Field(
|
| 74 |
+
...,
|
| 75 |
+
description="The messy, unstructured bug report to process"
|
| 76 |
+
)
|
| 77 |
+
feedback: str = Field(
|
| 78 |
+
default="",
|
| 79 |
+
description="Grading feedback explaining the score"
|
| 80 |
+
)
|
| 81 |
+
score: float = Field(
|
| 82 |
+
default=0.0,
|
| 83 |
+
description="Overall score from 0.0 to 1.0"
|
| 84 |
+
)
|
| 85 |
+
field_scores: Dict[str, float] = Field(
|
| 86 |
+
default_factory=dict,
|
| 87 |
+
description="Per-field scores: title, steps, expected, actual, severity, environment"
|
| 88 |
+
)
|
| 89 |
+
done: bool = Field(
|
| 90 |
+
default=False,
|
| 91 |
+
description="Whether the episode is complete"
|
| 92 |
+
)
|
| 93 |
+
reward: float = Field(
|
| 94 |
+
default=0.0,
|
| 95 |
+
description="Reward signal for this step"
|
| 96 |
+
)
|
| 97 |
+
step_count: int = Field(
|
| 98 |
+
default=0,
|
| 99 |
+
description="Current step number"
|
| 100 |
+
)
|
| 101 |
+
task_id: str = Field(
|
| 102 |
+
default="",
|
| 103 |
+
description="Current task identifier"
|
| 104 |
+
)
|
| 105 |
+
max_steps: int = Field(
|
| 106 |
+
default=5,
|
| 107 |
+
description="Maximum steps allowed for this task"
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
class BugReportState(BaseModel):
|
| 112 |
+
"""
|
| 113 |
+
Episode state metadata returned by GET /state.
|
| 114 |
+
"""
|
| 115 |
+
episode_id: str = Field(default="", description="Unique episode identifier")
|
| 116 |
+
step_count: int = Field(default=0, description="Steps taken so far")
|
| 117 |
+
task_id: str = Field(default="", description="Current task ID")
|
| 118 |
+
max_steps: int = Field(default=5, description="Maximum steps for this task")
|
| 119 |
+
current_score: float = Field(default=0.0, description="Best score achieved so far")
|
| 120 |
+
best_score: float = Field(default=0.0, description="Best score across all steps")
|
| 121 |
+
done: bool = Field(default=False, description="Whether episode is complete")
|
| 122 |
+
rewards: List[float] = Field(default_factory=list, description="Rewards per step")
|