amanmurari commited on
Commit
63990c5
·
verified ·
1 Parent(s): b5f279b

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. inference.py +17 -16
inference.py CHANGED
@@ -91,10 +91,10 @@ def _parse_phase(raw: str) -> int:
91
  return int(m.group(1)) if m else 0
92
 
93
 
94
- def get_llm_action(client: OpenAI, obs: TrafficObservation, step: int) -> TrafficAction:
95
  """Call LLM for decision."""
96
  resp = client.chat.completions.create(
97
- model=MODEL_NAME,
98
  messages=[
99
  {"role": "system", "content": SYSTEM_PROMPT},
100
  {"role": "user", "content": _build_prompt(obs, step)},
@@ -107,9 +107,9 @@ def get_llm_action(client: OpenAI, obs: TrafficObservation, step: int) -> Traffi
107
  return TrafficAction(light_phase=phase)
108
 
109
 
110
- def run_task(task: str, client: OpenAI) -> dict:
111
  """Run a single task episode."""
112
- print(f'[START] task={task} env=traffic_control model={MODEL_NAME}', flush=True)
113
 
114
  rewards: List[float] = []
115
  step = 0
@@ -122,7 +122,7 @@ def run_task(task: str, client: OpenAI) -> dict:
122
 
123
  while not obs.done:
124
  step += 1
125
- action = get_llm_action(client, obs, step)
126
  action_str = f"light_phase={action.light_phase}"
127
 
128
  try:
@@ -169,22 +169,23 @@ def run_task(task: str, client: OpenAI) -> dict:
169
  # ---------------------------------------------------------------------------
170
 
171
  def main():
172
- """Main entry point."""
173
- # Debug: Log environment variable status
174
- print(f"[INIT] API_BASE_URL={API_BASE_URL[:30]}..." if API_BASE_URL else "[INIT] API_BASE_URL=MISSING", flush=True)
175
- print(f"[INIT] API_KEY={API_KEY[:10]}..." if API_KEY else "[INIT] API_KEY=MISSING", flush=True)
176
- print(f"[INIT] MODEL_NAME={MODEL_NAME}", flush=True)
177
 
178
- # Initialize OpenAI client per spec
179
- client = OpenAI(
180
- base_url=API_BASE_URL,
181
- api_key=API_KEY
182
- )
 
183
  print(f"[INIT] Client ready", flush=True)
184
 
185
  tasks = ["basic_flow", "emergency_priority", "dynamic_scenarios"]
186
  for task in tasks:
187
- run_task(task, client)
188
 
189
 
190
  if __name__ == "__main__":
 
91
  return int(m.group(1)) if m else 0
92
 
93
 
94
+ def get_llm_action(client: OpenAI, obs: TrafficObservation, step: int, model: str) -> TrafficAction:
95
  """Call LLM for decision."""
96
  resp = client.chat.completions.create(
97
+ model=model,
98
  messages=[
99
  {"role": "system", "content": SYSTEM_PROMPT},
100
  {"role": "user", "content": _build_prompt(obs, step)},
 
107
  return TrafficAction(light_phase=phase)
108
 
109
 
110
+ def run_task(task: str, client: OpenAI, model: str) -> dict:
111
  """Run a single task episode."""
112
+ print(f'[START] task={task} env=traffic_control model={model}', flush=True)
113
 
114
  rewards: List[float] = []
115
  step = 0
 
122
 
123
  while not obs.done:
124
  step += 1
125
+ action = get_llm_action(client, obs, step, model)
126
  action_str = f"light_phase={action.light_phase}"
127
 
128
  try:
 
169
  # ---------------------------------------------------------------------------
170
 
171
  def main():
172
+ """Main entry point - reads env vars directly as validator requires."""
173
+ # CRITICAL: Read environment variables directly here for validator detection
174
+ api_base = os.environ["API_BASE_URL"]
175
+ api_key = os.environ["API_KEY"]
176
+ model = os.getenv("MODEL_NAME", "gpt-4o-mini")
177
 
178
+ print(f"[INIT] API_BASE_URL={api_base[:30]}...", flush=True)
179
+ print(f"[INIT] API_KEY present={bool(api_key)}", flush=True)
180
+ print(f"[INIT] MODEL_NAME={model}", flush=True)
181
+
182
+ # Initialize OpenAI client with directly-read env vars
183
+ client = OpenAI(base_url=api_base, api_key=api_key)
184
  print(f"[INIT] Client ready", flush=True)
185
 
186
  tasks = ["basic_flow", "emergency_priority", "dynamic_scenarios"]
187
  for task in tasks:
188
+ run_task(task, client, model)
189
 
190
 
191
  if __name__ == "__main__":