ronbell commited on
Commit
7447420
Β·
1 Parent(s): 9a02839
Files changed (4) hide show
  1. .dockerignore +24 -0
  2. Dockerfile +7 -3
  3. inference.py +17 -3
  4. openenv.yaml +3 -1
.dockerignore ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Never bake local credentials or dev overrides into the image.
2
+ # The validator injects API_KEY, API_BASE_URL, and MODEL_NAME at runtime.
3
+ .env
4
+ .env.*
5
+
6
+ # Dev/tooling artifacts β€” not needed in the container
7
+ .venv
8
+ __pycache__
9
+ *.pyc
10
+ *.pyo
11
+ .git
12
+ .gitignore
13
+ .gitattributes
14
+ *.md
15
+ Docs/
16
+ tests/
17
+ diagnose*.py
18
+ diagnose*.txt
19
+ diagnose*.md
20
+ engine_debug.py
21
+ engine_debug.txt
22
+ test_api.py
23
+ validate-submission.sh
24
+ openenv_src.txt
Dockerfile CHANGED
@@ -8,9 +8,13 @@ RUN pip install --no-cache-dir uv && uv pip install --system -e .
8
 
9
  EXPOSE 7860
10
 
11
- # HF Spaces injects secrets as environment variables at runtime.
12
- # API_BASE_URL and API_KEY are injected by the validator / runner.
13
- # Do NOT hardcode API_BASE_URL here β€” the validator provides its own proxy URL.
14
  ENV MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
15
 
 
 
 
 
16
  CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
 
8
 
9
  EXPOSE 7860
10
 
11
+ # ── Runtime config ────────────────────────────────────────────────────────────
12
+ # MODEL_NAME has a safe default; all other secrets (API_KEY, API_BASE_URL)
13
+ # are injected by the validator / HF Spaces at runtime β€” never hardcode them.
14
  ENV MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
15
 
16
+ # ── Entrypoint ────────────────────────────────────────────────────────────────
17
+ # Runs the OpenEnv-compliant web server (reset / step / state / health).
18
+ # The validator also runs inference.py as a separate process β€” it does NOT
19
+ # need to be the CMD; it is executed with the same injected env vars.
20
  CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
inference.py CHANGED
@@ -55,7 +55,8 @@ def _resolve_api_key() -> str:
55
  """Return the API key from whichever env var the runner provided.
56
 
57
  Priority order: API_KEY > OPENAI_API_KEY > HF_TOKEN
58
- The validator injects API_KEY, so it MUST be checked first.
 
59
  """
60
  for var in ("API_KEY", "OPENAI_API_KEY", "HF_TOKEN"):
61
  val = os.environ.get(var)
@@ -67,7 +68,18 @@ def _resolve_api_key() -> str:
67
  )
68
 
69
 
70
- API_BASE_URL = os.environ.get("API_BASE_URL", "https://router.huggingface.co/v1")
 
 
 
 
 
 
 
 
 
 
 
71
  API_KEY = _resolve_api_key()
72
  MODEL_NAME = os.environ.get("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
73
  TASK_NAME = os.getenv("PROCUREMENT_TASK", "easy")
@@ -242,8 +254,10 @@ def log_step(step: int, action: str, reward: float, done: bool, error: Optional[
242
 
243
  def log_end(success: bool, steps: int, rewards: List[float]) -> None:
244
  rewards_str = ",".join(f"{r:.2f}" for r in rewards)
 
 
245
  print(
246
- f"[END] success={str(success).lower()} steps={steps} rewards={rewards_str}",
247
  flush=True,
248
  )
249
 
 
55
  """Return the API key from whichever env var the runner provided.
56
 
57
  Priority order: API_KEY > OPENAI_API_KEY > HF_TOKEN
58
+ The validator injects API_KEY; it MUST be checked first and is the
59
+ only key that routes through the LiteLLM proxy.
60
  """
61
  for var in ("API_KEY", "OPENAI_API_KEY", "HF_TOKEN"):
62
  val = os.environ.get(var)
 
68
  )
69
 
70
 
71
+ # API_BASE_URL MUST come from the environment β€” the validator injects its own
72
+ # LiteLLM proxy URL here. We provide the HF router ONLY as a last-resort
73
+ # local-dev fallback; production runs will always have this injected.
74
+ _raw_base_url = os.environ.get("API_BASE_URL", "")
75
+ if not _raw_base_url:
76
+ print(
77
+ "[WARNING] API_BASE_URL not set β€” falling back to HF router for local dev. "
78
+ "The validator must inject API_BASE_URL for proxy routing to work.",
79
+ flush=True,
80
+ )
81
+ _raw_base_url = "https://router.huggingface.co/v1"
82
+ API_BASE_URL = _raw_base_url
83
  API_KEY = _resolve_api_key()
84
  MODEL_NAME = os.environ.get("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
85
  TASK_NAME = os.getenv("PROCUREMENT_TASK", "easy")
 
254
 
255
  def log_end(success: bool, steps: int, rewards: List[float]) -> None:
256
  rewards_str = ",".join(f"{r:.2f}" for r in rewards)
257
+ # score is the total cumulative reward clamped to [0.0, 1.0] as required
258
+ score = min(1.0, max(0.0, sum(rewards)))
259
  print(
260
+ f"[END] success={str(success).lower()} steps={steps} score={score:.2f} rewards={rewards_str}",
261
  flush=True,
262
  )
263
 
openenv.yaml CHANGED
@@ -6,7 +6,9 @@ app: server/app.py
6
  port: 7860
7
 
8
  config:
9
- API_BASE_URL: https://router.huggingface.co/v1
 
 
10
  MODEL_NAME: Qwen/Qwen2.5-72B-Instruct
11
 
12
  tasks:
 
6
  port: 7860
7
 
8
  config:
9
+ # API_BASE_URL is intentionally omitted β€” the validator injects its own
10
+ # LiteLLM proxy URL via the API_BASE_URL environment variable at runtime.
11
+ # Hardcoding it here would bypass the proxy and fail the LLM criteria check.
12
  MODEL_NAME: Qwen/Qwen2.5-72B-Instruct
13
 
14
  tasks: