Pranjal Parashar commited on
Commit
fed29a8
·
unverified ·
1 Parent(s): b75cdc6
Files changed (2) hide show
  1. baseline.py +29 -19
  2. inference.py +1 -0
baseline.py CHANGED
@@ -5,6 +5,7 @@ from __future__ import annotations
5
  import json
6
  import os
7
  import re
 
8
  import sys
9
  import textwrap
10
  from typing import Any, List, Optional
@@ -40,6 +41,8 @@ SYSTEM_PROMPT = textwrap.dedent(
40
  ).strip()
41
 
42
  DEBUG_LOGGING = os.getenv("DEVELOPER_CONTROL_ROOM_DEBUG", "false").lower() == "true"
 
 
43
 
44
 
45
  def debug_log(message: str) -> None:
@@ -115,25 +118,32 @@ def get_model_action(
115
  episode_memory: str = "",
116
  ) -> Optional[dict[str, Any]]:
117
  user_prompt = build_user_prompt(step, observation, history, episode_memory)
118
- try:
119
- if os.getenv("DEVELOPER_CONTROL_ROOM_FORCE_MODEL_TIMEOUT", "false").lower() == "true":
120
- raise TimeoutError("Forced model timeout for fallback-path validation.")
121
- completion = client.chat.completions.create(
122
- model=model_name,
123
- messages=[
124
- {"role": "system", "content": SYSTEM_PROMPT},
125
- {"role": "user", "content": user_prompt},
126
- ],
127
- temperature=temperature,
128
- max_tokens=max_tokens,
129
- timeout=timeout_seconds,
130
- stream=False,
131
- )
132
- text = (completion.choices[0].message.content or "").strip()
133
- return parse_model_action(text)
134
- except Exception as exc:
135
- debug_log(f"[DEBUG] Model request failed: {exc}")
136
- raise
 
 
 
 
 
 
 
137
 
138
 
139
  def action_is_valid(action: Optional[dict[str, Any]], observation: Any) -> bool:
 
5
  import json
6
  import os
7
  import re
8
+ import time
9
  import sys
10
  import textwrap
11
  from typing import Any, List, Optional
 
41
  ).strip()
42
 
43
  DEBUG_LOGGING = os.getenv("DEVELOPER_CONTROL_ROOM_DEBUG", "false").lower() == "true"
44
+ MODEL_RETRY_COUNT = int(os.getenv("DEVELOPER_CONTROL_ROOM_MODEL_RETRY_COUNT", "3"))
45
+ MODEL_RETRY_DELAY_SECONDS = float(os.getenv("DEVELOPER_CONTROL_ROOM_MODEL_RETRY_DELAY_SECONDS", "2"))
46
 
47
 
48
  def debug_log(message: str) -> None:
 
118
  episode_memory: str = "",
119
  ) -> Optional[dict[str, Any]]:
120
  user_prompt = build_user_prompt(step, observation, history, episode_memory)
121
+ last_exc: Exception | None = None
122
+ attempts = max(1, MODEL_RETRY_COUNT)
123
+ for attempt in range(1, attempts + 1):
124
+ try:
125
+ if os.getenv("DEVELOPER_CONTROL_ROOM_FORCE_MODEL_TIMEOUT", "false").lower() == "true":
126
+ raise TimeoutError("Forced model timeout for fallback-path validation.")
127
+ completion = client.chat.completions.create(
128
+ model=model_name,
129
+ messages=[
130
+ {"role": "system", "content": SYSTEM_PROMPT},
131
+ {"role": "user", "content": user_prompt},
132
+ ],
133
+ temperature=temperature,
134
+ max_tokens=max_tokens,
135
+ timeout=timeout_seconds,
136
+ stream=False,
137
+ )
138
+ text = (completion.choices[0].message.content or "").strip()
139
+ return parse_model_action(text)
140
+ except Exception as exc:
141
+ last_exc = exc
142
+ debug_log(f"[DEBUG] Model request failed on attempt {attempt}/{attempts}: {exc}")
143
+ if attempt < attempts:
144
+ time.sleep(MODEL_RETRY_DELAY_SECONDS)
145
+ assert last_exc is not None
146
+ raise RuntimeError(f"Model request failed after {attempts} attempts") from last_exc
147
 
148
 
149
  def action_is_valid(action: Optional[dict[str, Any]], observation: Any) -> bool:
inference.py CHANGED
@@ -281,6 +281,7 @@ async def run_task(
281
  debug_log(f"[DEBUG] task run failed: {exc}")
282
  success = False
283
  score = 0.0
 
284
 
285
  finally:
286
  try:
 
281
  debug_log(f"[DEBUG] task run failed: {exc}")
282
  success = False
283
  score = 0.0
284
+ raise
285
 
286
  finally:
287
  try: