Spaces:
Sleeping
Sleeping
Create tasks.py
Browse files
tasks.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from environment import CodeReviewEnv
|
| 2 |
+
from models import Action, Observation
|
| 3 |
+
|
| 4 |
+
def run_task(task_name: str, agent_func) -> float:
|
| 5 |
+
"""
|
| 6 |
+
Run a single task episode with the given agent function.
|
| 7 |
+
|
| 8 |
+
Args:
|
| 9 |
+
task_name: one of 'easy', 'medium', 'hard'
|
| 10 |
+
agent_func: a callable that takes an Observation and returns an Action.
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
float: the final reward (score) from the environment.
|
| 14 |
+
"""
|
| 15 |
+
env = CodeReviewEnv()
|
| 16 |
+
env.set_task(task_name)
|
| 17 |
+
obs = env.reset()
|
| 18 |
+
done = False
|
| 19 |
+
step = 0
|
| 20 |
+
final_reward = 0.0
|
| 21 |
+
|
| 22 |
+
while not done and step < 5: # max 5 steps
|
| 23 |
+
step += 1
|
| 24 |
+
action = agent_func(obs)
|
| 25 |
+
obs, reward, done, info = env.step(action)
|
| 26 |
+
final_reward = reward.value
|
| 27 |
+
|
| 28 |
+
return final_reward
|