Afifa Kureshi commited on
Commit
f754bbb
·
1 Parent(s): c2cba45

Run all tasks automatically for validator

Browse files
Files changed (1) hide show
  1. inference.py +65 -73
inference.py CHANGED
@@ -5,7 +5,6 @@ from environment.cloud_env import CloudDataJanitorEnv
5
  from openai import OpenAI
6
 
7
 
8
-
9
  def create_client():
10
  try:
11
  api_key = os.getenv("API_KEY", "")
@@ -24,7 +23,6 @@ def create_client():
24
  return None
25
 
26
 
27
-
28
  API_BASE_URL = os.environ.get(
29
  "API_BASE_URL",
30
  "https://router.huggingface.co/v1"
@@ -40,25 +38,20 @@ MODEL_NAME = os.environ.get(
40
  "Qwen/Qwen2.5-72B-Instruct"
41
  )
42
 
43
- TASK_NAME = os.environ.get(
44
- "MY_ENV_V4_TASK",
45
- "easy"
46
- )
47
-
48
  MAX_STEPS = 10
49
 
50
-
 
51
 
52
  client = create_client()
53
 
54
 
55
-
56
  class BaselineLLMAgent:
57
 
58
  def choose_action(self, state):
59
 
60
  if client is None:
61
- return {"action_type": "done"}
62
 
63
  prompt = f"""
64
  You are a Data Janitor managing a cloud drive.
@@ -108,92 +101,91 @@ Valid formats:
108
  return {"action": "done"}
109
 
110
 
111
-
112
- env = CloudDataJanitorEnv(
113
- task_name=TASK_NAME
114
- )
115
-
116
  agent = BaselineLLMAgent()
117
 
118
- rewards = []
119
- success = False
120
-
121
-
122
 
123
- try:
 
124
 
125
- print(
126
- "[START] "
127
- f"task={TASK_NAME} "
128
- "env=cloud-data-janitor "
129
- "model=baseline-llm"
130
  )
131
 
132
- state = env.reset()
 
133
 
134
- for step in range(1, MAX_STEPS + 1):
 
 
 
 
 
 
 
135
 
136
- action = agent.choose_action(state)
137
 
138
- state, reward, done, info = env.step(action)
139
 
140
- rewards.append(reward)
141
 
142
- error = info.get(
143
- "last_action_error"
144
- )
145
 
146
- print(
147
- "[STEP] "
148
- f"step={step} "
149
- f"action={action} "
150
- f"reward={reward:.2f} "
151
- f"done={str(done).lower()} "
152
- f"error={error if error else 'null'}"
153
- )
154
 
155
- if done:
156
- success = True
157
- break
158
 
159
- if not success and rewards:
160
- success = done
 
 
 
 
 
 
161
 
 
 
 
162
 
163
- except Exception as e:
 
164
 
165
- print(
166
- "[STEP] "
167
- "step=0 "
168
- "action=error "
169
- "reward=0.00 "
170
- "done=true "
171
- f"error={str(e)}"
172
- )
173
 
 
 
 
 
 
 
 
 
174
 
175
- finally:
176
 
177
- env.close()
178
 
179
- if rewards:
180
 
181
- score = rewards[-1]
182
 
183
- rewards_str = ",".join(
184
- f"{r:.2f}"
185
- for r in rewards
186
- )
187
 
188
- else:
189
 
190
- score = 0.0
191
- rewards_str = "0.00"
192
 
193
- print(
194
- "[END] "
195
- f"success={str(success).lower()} "
196
- f"steps={len(rewards)} "
197
- f"score={score:.2f} "
198
- f"rewards={rewards_str}"
199
- )
 
5
  from openai import OpenAI
6
 
7
 
 
8
  def create_client():
9
  try:
10
  api_key = os.getenv("API_KEY", "")
 
23
  return None
24
 
25
 
 
26
  API_BASE_URL = os.environ.get(
27
  "API_BASE_URL",
28
  "https://router.huggingface.co/v1"
 
38
  "Qwen/Qwen2.5-72B-Instruct"
39
  )
40
 
 
 
 
 
 
41
  MAX_STEPS = 10
42
 
43
+ # IMPORTANT — run ALL tasks automatically
44
+ TASKS = ["easy", "medium", "hard"]
45
 
46
  client = create_client()
47
 
48
 
 
49
  class BaselineLLMAgent:
50
 
51
  def choose_action(self, state):
52
 
53
  if client is None:
54
+ return {"action": "done"}
55
 
56
  prompt = f"""
57
  You are a Data Janitor managing a cloud drive.
 
101
  return {"action": "done"}
102
 
103
 
 
 
 
 
 
104
  agent = BaselineLLMAgent()
105
 
 
 
 
 
106
 
107
+ # RUN ALL TASKS
108
+ for TASK_NAME in TASKS:
109
 
110
+ env = CloudDataJanitorEnv(
111
+ task_name=TASK_NAME
 
 
 
112
  )
113
 
114
+ rewards = []
115
+ success = False
116
 
117
+ try:
118
+
119
+ print(
120
+ "[START] "
121
+ f"task={TASK_NAME} "
122
+ "env=cloud-data-janitor "
123
+ "model=baseline-llm"
124
+ )
125
 
126
+ state = env.reset()
127
 
128
+ for step in range(1, MAX_STEPS + 1):
129
 
130
+ action = agent.choose_action(state)
131
 
132
+ state, reward, done, info = env.step(action)
 
 
133
 
134
+ rewards.append(reward)
 
 
 
 
 
 
 
135
 
136
+ error = info.get(
137
+ "last_action_error"
138
+ )
139
 
140
+ print(
141
+ "[STEP] "
142
+ f"step={step} "
143
+ f"action={action} "
144
+ f"reward={reward:.2f} "
145
+ f"done={str(done).lower()} "
146
+ f"error={error if error else 'null'}"
147
+ )
148
 
149
+ if done:
150
+ success = True
151
+ break
152
 
153
+ if not success and rewards:
154
+ success = done
155
 
156
+ except Exception as e:
 
 
 
 
 
 
 
157
 
158
+ print(
159
+ "[STEP] "
160
+ "step=0 "
161
+ "action=error "
162
+ "reward=0.00 "
163
+ "done=true "
164
+ f"error={str(e)}"
165
+ )
166
 
167
+ finally:
168
 
169
+ env.close()
170
 
171
+ if rewards:
172
 
173
+ score = rewards[-1]
174
 
175
+ rewards_str = ",".join(
176
+ f"{r:.2f}"
177
+ for r in rewards
178
+ )
179
 
180
+ else:
181
 
182
+ score = 0.0
183
+ rewards_str = "0.00"
184
 
185
+ print(
186
+ "[END] "
187
+ f"success={str(success).lower()} "
188
+ f"steps={len(rewards)} "
189
+ f"score={score:.2f} "
190
+ f"rewards={rewards_str}"
191
+ )