Afifa Kureshi commited on
Commit
4ed4736
·
1 Parent(s): 943b390

Fix inference format and runtime errors for Phase 2

Browse files
__pycache__/config.cpython-310.pyc ADDED
Binary file (1.15 kB). View file
 
actions/__pycache__/file_actions.cpython-310.pyc ADDED
Binary file (2.02 kB). View file
 
environment/__pycache__/cloud_env.cpython-310.pyc ADDED
Binary file (2.31 kB). View file
 
environment/__pycache__/file_system.cpython-310.pyc ADDED
Binary file (5.03 kB). View file
 
grader/__pycache__/grader.cpython-310.pyc ADDED
Binary file (7.39 kB). View file
 
inference.py CHANGED
@@ -1,63 +1,124 @@
1
- import os
2
  import json
3
- from openai import OpenAI
 
4
  from environment.cloud_env import CloudDataJanitorEnv
 
5
 
6
- # 1. PULL THE EXACT VARIABLES INJECTED BY THE JUDGES
7
- API_BASE_URL = os.environ.get("API_BASE_URL", "https://router.huggingface.co/v1")
8
- API_KEY = os.environ.get("API_KEY", "dummy-key")
9
- MODEL_NAME = os.environ.get("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
10
- TASK_NAME = os.environ.get("MY_ENV_V4_TASK", "easy")
11
- MAX_STEPS = 10
12
 
13
- # 2. INITIALIZE THE CLIENT EXACTLY AS REQUESTED
14
- client = OpenAI(
15
- base_url=API_BASE_URL,
16
- api_key=API_KEY
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  )
18
 
19
- # 3. REPLACE THE RULE-BASED AGENT WITH A REAL LLM AGENT
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  class BaselineLLMAgent:
 
21
  def choose_action(self, state):
 
 
 
 
22
  prompt = f"""
23
- You are a Data Janitor managing a cloud drive.
24
- Current State: {state}
25
-
26
- Choose one action. You MUST reply with ONLY raw, valid JSON. Do not use markdown blocks.
27
- Valid actions formats:
28
- {{"action_type": "move", "file_id": "f1", "destination_folder": "Images"}}
29
- {{"action_type": "delete", "file_id": "f2"}}
30
- {{"action_type": "zip", "file_id": "f3"}}
31
- {{"action_type": "done"}}
32
- """
 
 
 
 
 
 
33
 
34
  try:
35
- # This is the API call the proxy is waiting to see!
36
  response = client.chat.completions.create(
37
  model=MODEL_NAME,
38
- messages=[{"role": "user", "content": prompt}],
 
 
 
 
 
39
  temperature=0.1
40
  )
41
-
42
- # Clean up the response and parse it
43
- raw_output = response.choices[0].message.content.strip("` \n")
 
 
 
 
 
 
44
  if raw_output.startswith("json"):
45
  raw_output = raw_output[4:]
46
-
47
  return json.loads(raw_output)
48
-
49
- except Exception as e:
50
- # If the LLM breaks or hallucinates, safely end the loop
51
- return {"action_type": "done"}
52
 
53
- # Initialize the environment and the NEW agent
54
- env = CloudDataJanitorEnv(task_name=TASK_NAME)
 
 
 
 
 
 
 
55
  agent = BaselineLLMAgent()
56
 
57
  rewards = []
58
  success = False
59
 
60
- # ... KEEP YOUR EXISTING try/except LOOP EXACTLY THE SAME BELOW THIS LINE ...
61
 
62
  try:
63
 
@@ -65,7 +126,7 @@ try:
65
  "[START] "
66
  f"task={TASK_NAME} "
67
  "env=cloud-data-janitor "
68
- "model=rule-agent"
69
  )
70
 
71
  state = env.reset()
@@ -73,11 +134,14 @@ try:
73
  for step in range(1, MAX_STEPS + 1):
74
 
75
  action = agent.choose_action(state)
 
76
  state, reward, done, info = env.step(action)
77
 
78
  rewards.append(reward)
79
 
80
- error = info.get("last_action_error")
 
 
81
 
82
  print(
83
  "[STEP] "
@@ -89,18 +153,14 @@ try:
89
  )
90
 
91
  if done:
92
-
93
  success = True
94
  break
95
 
96
- # If loop ended without done
97
  if not success and rewards:
98
-
99
  success = done
100
 
101
- except Exception as e:
102
-
103
 
 
104
 
105
  print(
106
  "[STEP] "
@@ -111,6 +171,7 @@ except Exception as e:
111
  f"error={str(e)}"
112
  )
113
 
 
114
  finally:
115
 
116
  env.close()
@@ -120,7 +181,8 @@ finally:
120
  score = rewards[-1]
121
 
122
  rewards_str = ",".join(
123
- f"{r:.2f}" for r in rewards
 
124
  )
125
 
126
  else:
@@ -129,9 +191,9 @@ finally:
129
  rewards_str = "0.00"
130
 
131
  print(
132
- "[END] "
133
- f"success={str(success).lower()} "
134
- f"steps={len(rewards)} "
135
- f"score={score:.2f} "
136
- f"rewards={rewards_str}"
137
- )
 
 
1
  import json
2
+ import os
3
+
4
  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", "")
12
+ base_url = os.getenv(
13
+ "API_BASE_URL",
14
+ "https://router.huggingface.co/v1"
15
+ )
16
+
17
+ return OpenAI(
18
+ api_key=api_key,
19
+ base_url=base_url
20
+ )
21
+
22
+ except Exception as e:
23
+ print("OpenAI initialization failed:", str(e))
24
+ return None
25
+
26
+
27
+
28
+ API_BASE_URL = os.environ.get(
29
+ "API_BASE_URL",
30
+ "https://router.huggingface.co/v1"
31
  )
32
 
33
+ API_KEY = os.environ.get(
34
+ "API_KEY",
35
+ ""
36
+ )
37
+
38
+ MODEL_NAME = os.environ.get(
39
+ "MODEL_NAME",
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.
65
+
66
+ Current State:
67
+ {state}
68
+
69
+ Choose ONE action.
70
+
71
+ Reply with ONLY valid JSON.
72
+
73
+ Valid formats:
74
+
75
+ {{"action": "move_file", "filename": "report_q1.pdf", "destination": "Documents"}}
76
+ {{"action": "delete_file", "filename": "duplicate.pdf"}}
77
+ {{"action": "zip_folder", "folder_name": "OldFiles"}}
78
+ {{"action": "done"}}
79
+ """
80
 
81
  try:
82
+
83
  response = client.chat.completions.create(
84
  model=MODEL_NAME,
85
+ messages=[
86
+ {
87
+ "role": "user",
88
+ "content": prompt
89
+ }
90
+ ],
91
  temperature=0.1
92
  )
93
+
94
+ raw_output = (
95
+ response
96
+ .choices[0]
97
+ .message
98
+ .content
99
+ .strip("` \n")
100
+ )
101
+
102
  if raw_output.startswith("json"):
103
  raw_output = raw_output[4:]
104
+
105
  return json.loads(raw_output)
 
 
 
 
106
 
107
+ except Exception:
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
 
 
126
  "[START] "
127
  f"task={TASK_NAME} "
128
  "env=cloud-data-janitor "
129
+ "model=baseline-llm"
130
  )
131
 
132
  state = env.reset()
 
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] "
 
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] "
 
171
  f"error={str(e)}"
172
  )
173
 
174
+
175
  finally:
176
 
177
  env.close()
 
181
  score = rewards[-1]
182
 
183
  rewards_str = ",".join(
184
+ f"{r:.2f}"
185
+ for r in rewards
186
  )
187
 
188
  else:
 
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
+ )
requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
- fastapi==0.110.1
2
- uvicorn==0.29.0
3
- pydantic==2.6.4
4
- typer==0.12.3
5
- openenv-core==0.1.0
6
- openai==1.14.3
 
1
+ openenv-core
2
+ openai==1.30.5
3
+ httpx==0.27.0
4
+ fastapi==0.111.0
5
+ uvicorn==0.30.1
6
+ pydantic==2.7.1
utils/__pycache__/helpers.cpython-310.pyc ADDED
Binary file (6.25 kB). View file