Shreya Pal commited on
Commit
ada3dd4
ยท
1 Parent(s): 99e1c7c

Fix OpenEnv mapping architecture matching explicit tasks

Browse files
Files changed (2) hide show
  1. openenv.yaml +0 -6
  2. server/app.py +24 -32
openenv.yaml CHANGED
@@ -8,22 +8,16 @@ endpoints:
8
  tasks:
9
  - id: task_1
10
  description: "Moderate hate speech"
11
- enabled: true
12
  graders:
13
  - type: "exact_match"
14
  expected: "remove"
15
- enabled: true
16
  - id: task_2
17
  description: "Moderate praise"
18
- enabled: true
19
  graders:
20
  - type: "exact_match"
21
  expected: "allow"
22
- enabled: true
23
  - id: task_3
24
  description: "Moderate sarcasm"
25
- enabled: true
26
  graders:
27
  - type: "exact_match"
28
  expected: "flag"
29
- enabled: true
 
8
  tasks:
9
  - id: task_1
10
  description: "Moderate hate speech"
 
11
  graders:
12
  - type: "exact_match"
13
  expected: "remove"
 
14
  - id: task_2
15
  description: "Moderate praise"
 
16
  graders:
17
  - type: "exact_match"
18
  expected: "allow"
 
19
  - id: task_3
20
  description: "Moderate sarcasm"
 
21
  graders:
22
  - type: "exact_match"
23
  expected: "flag"
 
server/app.py CHANGED
@@ -24,15 +24,11 @@ app.add_middleware(
24
  allow_headers=["*"],
25
  )
26
 
27
- data = [
28
- ("I love this!", "allow"),
29
- ("You are amazing", "allow"),
30
- ("I hate you", "remove"),
31
- ("Go die", "remove"),
32
- ("Wow you're so smart ๐Ÿ™„", "flag"),
33
- ("Maybe you should disappear", "remove"),
34
- ("Nice work!", "allow"),
35
- ("This is trash", "flag")
36
  ]
37
 
38
  current_task_idx = 0
@@ -55,15 +51,10 @@ class ResetResponse(BaseModel):
55
  @app.post("/reset", response_model=ResetResponse)
56
  async def reset(request: Request):
57
  global current_task_idx
58
- body = {}
59
- try:
60
- body = await request.json()
61
- except:
62
- pass
63
-
64
  return ResetResponse(
65
- observation=Observation(echoed_message=data[current_task_idx][0]),
66
- done=False
67
  )
68
 
69
  @app.post("/step", response_model=StepResponse)
@@ -72,35 +63,36 @@ async def step(request: Request):
72
  body = {}
73
  try:
74
  body = await request.json()
75
- except:
76
  pass
77
-
78
  msg = ""
79
  if "action" in body and isinstance(body["action"], dict) and "message" in body["action"]:
80
  msg = body["action"]["message"]
81
  elif "message" in body:
82
  msg = body["message"]
83
-
84
- true_label = data[current_task_idx][1]
85
-
86
- if msg.lower().strip() == true_label.lower():
87
- reward = 1.0
88
- else:
89
- reward = 0.0
90
 
91
- current_task_idx = (current_task_idx + 1) % len(data)
92
-
 
 
 
 
 
 
93
  return StepResponse(
94
- observation=Observation(echoed_message=data[current_task_idx][0]),
95
  reward=reward,
96
- done=True
97
  )
98
 
99
  @app.get("/state")
100
  async def state():
 
 
101
  return {
102
- "observation": {"echoed_message": data[current_task_idx][0]},
103
- "done": False
104
  }
105
 
106
  class ModerationRequest(BaseModel):
 
24
  allow_headers=["*"],
25
  )
26
 
27
+ # Tasks that match openenv.yaml exactly
28
+ TASKS = [
29
+ {"id": "task_1", "text": "I hate you", "label": "remove"},
30
+ {"id": "task_2", "text": "You are amazing", "label": "allow"},
31
+ {"id": "task_3", "text": "Wow you're so smart ๐Ÿ™„", "label": "flag"},
 
 
 
 
32
  ]
33
 
34
  current_task_idx = 0
 
51
  @app.post("/reset", response_model=ResetResponse)
52
  async def reset(request: Request):
53
  global current_task_idx
54
+ current_task_idx = 0
 
 
 
 
 
55
  return ResetResponse(
56
+ observation=Observation(echoed_message=TASKS[current_task_idx]["text"]),
57
+ done=False,
58
  )
59
 
60
  @app.post("/step", response_model=StepResponse)
 
63
  body = {}
64
  try:
65
  body = await request.json()
66
+ except Exception:
67
  pass
68
+
69
  msg = ""
70
  if "action" in body and isinstance(body["action"], dict) and "message" in body["action"]:
71
  msg = body["action"]["message"]
72
  elif "message" in body:
73
  msg = body["message"]
 
 
 
 
 
 
 
74
 
75
+ true_label = TASKS[current_task_idx]["label"]
76
+ reward = 1.0 if msg.lower().strip() == true_label.lower() else 0.0
77
+
78
+ current_task_idx += 1
79
+ done = current_task_idx >= len(TASKS)
80
+
81
+ next_text = TASKS[current_task_idx]["text"] if not done else ""
82
+
83
  return StepResponse(
84
+ observation=Observation(echoed_message=next_text),
85
  reward=reward,
86
+ done=done,
87
  )
88
 
89
  @app.get("/state")
90
  async def state():
91
+ done = current_task_idx >= len(TASKS)
92
+ next_text = TASKS[current_task_idx]["text"] if not done else ""
93
  return {
94
+ "observation": {"echoed_message": next_text},
95
+ "done": done
96
  }
97
 
98
  class ModerationRequest(BaseModel):