Spaces:
Sleeping
Sleeping
Commit ·
507c5df
1
Parent(s): f3181c1
feat: enhance main function with improved API key handling and detailed logging for task execution
Browse files- inference.py +14 -5
inference.py
CHANGED
|
@@ -6,6 +6,9 @@ import urllib.request
|
|
| 6 |
from env import TutorEnv
|
| 7 |
from schemas import Action
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def load_tasks():
|
| 11 |
tasks = []
|
|
@@ -84,7 +87,7 @@ def main():
|
|
| 84 |
# Hackathon validator injects API_BASE_URL + API_KEY.
|
| 85 |
# Prefer those names first to ensure calls are routed through the required proxy.
|
| 86 |
api_base_url = os.getenv("API_BASE_URL") or os.getenv("OPENAI_BASE_URL")
|
| 87 |
-
api_key = os.getenv("API_KEY") or os.getenv("OPENAI_API_KEY")
|
| 88 |
model_name = (
|
| 89 |
os.getenv("MODEL_NAME")
|
| 90 |
or os.getenv("OPENAI_MODEL")
|
|
@@ -93,7 +96,7 @@ def main():
|
|
| 93 |
)
|
| 94 |
|
| 95 |
mock_inference = os.getenv("MOCK_INFERENCE", "").lower() in {"1", "true", "yes", "on"}
|
| 96 |
-
proxy_mode = bool(os.getenv("API_BASE_URL") and os.getenv("API_KEY"))
|
| 97 |
missing = [k for k, v in {
|
| 98 |
"API_BASE_URL": api_base_url,
|
| 99 |
"API_KEY": api_key,
|
|
@@ -125,7 +128,7 @@ def main():
|
|
| 125 |
|
| 126 |
for task in tasks:
|
| 127 |
task_id = task["task_id"]
|
| 128 |
-
print(f"[START] task={task_id}
|
| 129 |
|
| 130 |
state = env.reset(task)
|
| 131 |
|
|
@@ -166,13 +169,19 @@ def main():
|
|
| 166 |
res = env.step(action)
|
| 167 |
score = float(res.reward)
|
| 168 |
results[task_id] = score
|
|
|
|
| 169 |
|
| 170 |
step_count = res.observation.step_count
|
| 171 |
print(
|
| 172 |
-
f"[STEP]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
flush=True,
|
| 174 |
)
|
| 175 |
-
print(f"[END] task={task_id} score={score:.6f} steps={step_count}", flush=True)
|
| 176 |
|
| 177 |
# print results (required)
|
| 178 |
print("Baseline Results:", flush=True)
|
|
|
|
| 6 |
from env import TutorEnv
|
| 7 |
from schemas import Action
|
| 8 |
|
| 9 |
+
BENCHMARK = "tutor_progress"
|
| 10 |
+
SUCCESS_SCORE_THRESHOLD = 0.5
|
| 11 |
+
|
| 12 |
|
| 13 |
def load_tasks():
|
| 14 |
tasks = []
|
|
|
|
| 87 |
# Hackathon validator injects API_BASE_URL + API_KEY.
|
| 88 |
# Prefer those names first to ensure calls are routed through the required proxy.
|
| 89 |
api_base_url = os.getenv("API_BASE_URL") or os.getenv("OPENAI_BASE_URL")
|
| 90 |
+
api_key = os.getenv("API_KEY") or os.getenv("HF_TOKEN") or os.getenv("OPENAI_API_KEY")
|
| 91 |
model_name = (
|
| 92 |
os.getenv("MODEL_NAME")
|
| 93 |
or os.getenv("OPENAI_MODEL")
|
|
|
|
| 96 |
)
|
| 97 |
|
| 98 |
mock_inference = os.getenv("MOCK_INFERENCE", "").lower() in {"1", "true", "yes", "on"}
|
| 99 |
+
proxy_mode = bool(os.getenv("API_BASE_URL") and (os.getenv("API_KEY") or os.getenv("HF_TOKEN")))
|
| 100 |
missing = [k for k, v in {
|
| 101 |
"API_BASE_URL": api_base_url,
|
| 102 |
"API_KEY": api_key,
|
|
|
|
| 128 |
|
| 129 |
for task in tasks:
|
| 130 |
task_id = task["task_id"]
|
| 131 |
+
print(f"[START] task={task_id} env={BENCHMARK} model={model_name}", flush=True)
|
| 132 |
|
| 133 |
state = env.reset(task)
|
| 134 |
|
|
|
|
| 169 |
res = env.step(action)
|
| 170 |
score = float(res.reward)
|
| 171 |
results[task_id] = score
|
| 172 |
+
rewards = [score]
|
| 173 |
|
| 174 |
step_count = res.observation.step_count
|
| 175 |
print(
|
| 176 |
+
f"[STEP] step={step_count} action=final_answer reward={score:.2f} done={str(res.done).lower()} error=null",
|
| 177 |
+
flush=True,
|
| 178 |
+
)
|
| 179 |
+
success = score >= SUCCESS_SCORE_THRESHOLD
|
| 180 |
+
rewards_str = ",".join(f"{r:.2f}" for r in rewards)
|
| 181 |
+
print(
|
| 182 |
+
f"[END] task={task_id} success={str(success).lower()} steps={step_count} score={score:.3f} rewards={rewards_str}",
|
| 183 |
flush=True,
|
| 184 |
)
|
|
|
|
| 185 |
|
| 186 |
# print results (required)
|
| 187 |
print("Baseline Results:", flush=True)
|