ncncomplete commited on
Commit
9e31281
·
verified ·
1 Parent(s): ad432a3

chore: align inference.py with hackathon checklist

Browse files
Files changed (1) hide show
  1. inference.py +16 -9
inference.py CHANGED
@@ -23,9 +23,14 @@ except Exception:
23
  # Configuration
24
  # ---------------------------------------------------------------------------
25
 
26
- BASE_URL = os.getenv("BASE_URL", "http://localhost:8000")
27
- API_KEY = os.getenv("API_KEY") or os.getenv("HF_TOKEN")
28
- MODEL = "gpt-4o-mini"
 
 
 
 
 
29
 
30
  # List of task IDs to evaluate
31
  TASKS = os.getenv("TASKS", "task_1,task_2,task_3").split(",")
@@ -44,13 +49,13 @@ def _build_action(task_description: str, code_snippet: str) -> Dict[str, Any]:
44
  "confidence": 0.0,
45
  }
46
 
47
- if not API_KEY:
48
  return fallback_action
49
 
50
  try:
51
  from openai import OpenAI # Lazy import to avoid failing at module import time
52
 
53
- client = OpenAI(api_key=API_KEY)
54
  except Exception:
55
  return fallback_action
56
 
@@ -71,7 +76,7 @@ Respond ONLY with valid JSON, no markdown:
71
 
72
  try:
73
  response = client.chat.completions.create(
74
- model=MODEL,
75
  messages=[{"role": "user", "content": prompt}],
76
  temperature=0.0,
77
  )
@@ -114,7 +119,7 @@ def run_task(task_id: str) -> float:
114
  score = 0.0
115
  steps = 1
116
 
117
- reset_data = _safe_post_json(f"{BASE_URL}/reset", {"task_id": task_id}) or {}
118
  obs = reset_data.get("observation", {}) if isinstance(reset_data, dict) else {}
119
 
120
  code_snippet = obs.get("code_snippet", "")
@@ -122,9 +127,11 @@ def run_task(task_id: str) -> float:
122
  action = _build_action(str(task_description), str(code_snippet))
123
 
124
  # If stepping fails, we still emit structured output with reward=0.0
125
- _safe_post_json(f"{BASE_URL}/step", {"action": action})
126
 
127
- grader_data = _safe_get_json(f"{BASE_URL}/grader?task_id={task_id}&episode_id=baseline") or {}
 
 
128
  if isinstance(grader_data, dict):
129
  try:
130
  score = float(grader_data.get("score", 0.0))
 
23
  # Configuration
24
  # ---------------------------------------------------------------------------
25
 
26
+ # Required checklist variables:
27
+ # - API_BASE_URL and MODEL_NAME have defaults
28
+ # - HF_TOKEN has no default
29
+ # - LOCAL_IMAGE_NAME is optional
30
+ API_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:8000")
31
+ MODEL_NAME = os.getenv("MODEL_NAME", "gpt-4o-mini")
32
+ HF_TOKEN = os.getenv("HF_TOKEN")
33
+ LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME")
34
 
35
  # List of task IDs to evaluate
36
  TASKS = os.getenv("TASKS", "task_1,task_2,task_3").split(",")
 
49
  "confidence": 0.0,
50
  }
51
 
52
+ if not HF_TOKEN:
53
  return fallback_action
54
 
55
  try:
56
  from openai import OpenAI # Lazy import to avoid failing at module import time
57
 
58
+ client = OpenAI(base_url=API_BASE_URL, api_key=HF_TOKEN)
59
  except Exception:
60
  return fallback_action
61
 
 
76
 
77
  try:
78
  response = client.chat.completions.create(
79
+ model=MODEL_NAME,
80
  messages=[{"role": "user", "content": prompt}],
81
  temperature=0.0,
82
  )
 
119
  score = 0.0
120
  steps = 1
121
 
122
+ reset_data = _safe_post_json(f"{API_BASE_URL}/reset", {"task_id": task_id}) or {}
123
  obs = reset_data.get("observation", {}) if isinstance(reset_data, dict) else {}
124
 
125
  code_snippet = obs.get("code_snippet", "")
 
127
  action = _build_action(str(task_description), str(code_snippet))
128
 
129
  # If stepping fails, we still emit structured output with reward=0.0
130
+ _safe_post_json(f"{API_BASE_URL}/step", {"action": action})
131
 
132
+ grader_data = _safe_get_json(
133
+ f"{API_BASE_URL}/grader?task_id={task_id}&episode_id=baseline"
134
+ ) or {}
135
  if isinstance(grader_data, dict):
136
  try:
137
  score = float(grader_data.get("score", 0.0))