Lishika commited on
Commit
6abb093
·
unverified ·
2 Parent(s): b26bc99832f81c

Merge pull request #1 from lishhh06/test

Browse files
Files changed (7) hide show
  1. .env.example +11 -2
  2. .gitattributes +35 -0
  3. Dockerfile +1 -1
  4. README.md +51 -4
  5. inference.py +5 -3
  6. requirements.txt +5 -1
  7. server/app.py +8 -0
.env.example CHANGED
@@ -1,7 +1,16 @@
 
1
  API_BASE_URL=https://router.huggingface.co/v1
2
  MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
3
- OPENAI_API_KEY=<your_openai_compatible_api_key>
4
- HF_TOKEN=<optional_fallback_token>
 
 
 
 
 
 
 
 
5
 
6
  # Optional runtime knobs
7
  LOCAL_IMAGE_NAME=
 
1
+ # Default profile: Hugging Face Router (OpenAI-compatible API)
2
  API_BASE_URL=https://router.huggingface.co/v1
3
  MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
4
+ HF_TOKEN=<your_openai_or_router_api_key>
5
+
6
+ # Optional alias. If both are set, OPENAI_API_KEY is used first by inference.py.
7
+ OPENAI_API_KEY=
8
+
9
+ # OpenAI direct profile (uncomment for OpenAI access token usage):
10
+ # API_BASE_URL=https://api.openai.com/v1
11
+ # MODEL_NAME=gpt-4o-mini
12
+ # HF_TOKEN=<your_openai_access_token>
13
+ # OPENAI_API_KEY=<optional_same_token_as_hf_token>
14
 
15
  # Optional runtime knobs
16
  LOCAL_IMAGE_NAME=
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Dockerfile CHANGED
@@ -10,4 +10,4 @@ COPY . .
10
  ENV PORT=7860
11
  EXPOSE 7860
12
 
13
- CMD ["python", "-m", "uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
 
10
  ENV PORT=7860
11
  EXPOSE 7860
12
 
13
+ CMD ["python", "-m", "server.app"]
README.md CHANGED
@@ -213,13 +213,23 @@ Environment variables:
213
  ```bash
214
  export API_BASE_URL="https://router.huggingface.co/v1"
215
  export MODEL_NAME="Qwen/Qwen2.5-72B-Instruct"
216
- export OPENAI_API_KEY="<your_openai_compatible_api_key>"
217
- # Optional backward-compatible fallback variable used if OPENAI_API_KEY is not set:
218
- export HF_TOKEN="<your_token>"
219
  # Optional, only if your inference spins environments from local images.
220
  export LOCAL_IMAGE_NAME="<local_env_image_name>"
221
  ```
222
 
 
 
 
 
 
 
 
 
 
 
223
  ## 8. Run Inference
224
 
225
  Offline/local mode:
@@ -330,6 +340,43 @@ Server endpoints used by validators:
330
  - `GET /state`
331
  - `GET /health`
332
 
333
- ## 12. One-line Presentation Summary
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
334
 
335
  We built an OpenEnv-compliant reinforcement learning environment where AI agents learn to debug real CI/CD pipelines using multi-step reasoning, hybrid grading, anti-hacking safeguards, and robust reward shaping.
 
213
  ```bash
214
  export API_BASE_URL="https://router.huggingface.co/v1"
215
  export MODEL_NAME="Qwen/Qwen2.5-72B-Instruct"
216
+ export HF_TOKEN="<your_openai_compatible_api_key>"
217
+ # Optional alias; if set, this takes precedence over HF_TOKEN in inference.py
218
+ export OPENAI_API_KEY="<same_token_optional>"
219
  # Optional, only if your inference spins environments from local images.
220
  export LOCAL_IMAGE_NAME="<local_env_image_name>"
221
  ```
222
 
223
+ If you want to use an OpenAI access token directly:
224
+
225
+ ```bash
226
+ export API_BASE_URL="https://api.openai.com/v1"
227
+ export MODEL_NAME="gpt-4o-mini"
228
+ export HF_TOKEN="<your_openai_access_token>"
229
+ # Optional alias:
230
+ export OPENAI_API_KEY="<same_token_optional>"
231
+ ```
232
+
233
  ## 8. Run Inference
234
 
235
  Offline/local mode:
 
340
  - `GET /state`
341
  - `GET /health`
342
 
343
+ ## 12. Deploy to Hugging Face Space (OpenAI Token)
344
+
345
+ This repository is already configured for Docker Spaces (`sdk: docker` in this README front matter).
346
+
347
+ 1. Create a new Hugging Face Space with SDK set to `Docker`.
348
+ 2. Push this repository to the Space git remote.
349
+ 3. In Space Settings -> Variables and secrets, add these Secrets:
350
+
351
+ ```text
352
+ OPENAI_API_KEY=<your_openai_access_token>
353
+ API_BASE_URL=https://api.openai.com/v1
354
+ MODEL_NAME=gpt-4o-mini
355
+ ```
356
+
357
+ 4. Optional Secrets:
358
+
359
+ ```text
360
+ HF_TOKEN=<optional_fallback_token>
361
+ OFFLINE_INFERENCE=0
362
+ MAX_STEPS=8
363
+ TEMPERATURE=0.2
364
+ MAX_TOKENS=120
365
+ ```
366
+
367
+ 5. Keep the app port as `7860` (already configured).
368
+ 6. Wait for build completion, then verify:
369
+
370
+ ```bash
371
+ curl -sS https://<your-space-name>.hf.space/health
372
+ curl -sS -X POST https://<your-space-name>.hf.space/reset -H 'Content-Type: application/json' -d '{}'
373
+ ```
374
+
375
+ Notes:
376
+
377
+ - `.env.example` is for local development reference only. Hugging Face Spaces use Secrets/Variables from Space Settings.
378
+ - Runtime code reads `OPENAI_API_KEY` first and falls back to `HF_TOKEN` when `OPENAI_API_KEY` is not provided.
379
+
380
+ ## 13. One-line Presentation Summary
381
 
382
  We built an OpenEnv-compliant reinforcement learning environment where AI agents learn to debug real CI/CD pipelines using multi-step reasoning, hybrid grading, anti-hacking safeguards, and robust reward shaping.
inference.py CHANGED
@@ -16,7 +16,9 @@ from inference.visualize import save_metrics_json, save_reward_curve, save_succe
16
 
17
  API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
18
  MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
19
- OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") or os.getenv("HF_TOKEN")
 
 
20
  LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME")
21
  DEFAULT_TASK_ID = os.getenv("MY_ENV_V4_TASK", "easy-command-typo")
22
  DEFAULT_BENCHMARK = os.getenv("MY_ENV_V4_BENCHMARK", "cicd_debugger_env")
@@ -172,11 +174,11 @@ async def run_episode(args: argparse.Namespace) -> int:
172
 
173
  env = CICDDebuggerEnvironment(max_steps=max(1, int(args.max_steps)))
174
 
175
- offline_mode = bool(args.offline or not OPENAI_API_KEY)
176
  client: OpenAI | None = None
177
  if not offline_mode:
178
  try:
179
- client = OpenAI(base_url=API_BASE_URL, api_key=OPENAI_API_KEY)
180
  except Exception:
181
  client = None
182
  offline_mode = True
 
16
 
17
  API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
18
  MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
19
+ HF_TOKEN = os.getenv("HF_TOKEN")
20
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
21
+ API_KEY = OPENAI_API_KEY or HF_TOKEN
22
  LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME")
23
  DEFAULT_TASK_ID = os.getenv("MY_ENV_V4_TASK", "easy-command-typo")
24
  DEFAULT_BENCHMARK = os.getenv("MY_ENV_V4_BENCHMARK", "cicd_debugger_env")
 
174
 
175
  env = CICDDebuggerEnvironment(max_steps=max(1, int(args.max_steps)))
176
 
177
+ offline_mode = bool(args.offline or not API_KEY)
178
  client: OpenAI | None = None
179
  if not offline_mode:
180
  try:
181
+ client = OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
182
  except Exception:
183
  client = None
184
  offline_mode = True
requirements.txt CHANGED
@@ -1,5 +1,9 @@
1
  pyyaml
2
  fastapi
3
- uvicorn
4
  openenv-core
5
  openai
 
 
 
 
 
1
  pyyaml
2
  fastapi
3
+ uvicorn[standard]
4
  openenv-core
5
  openai
6
+ pydantic>=2.0.0
7
+ transformers>=4.30.0
8
+ torch>=2.0.0
9
+ pytest>=7.0.0
server/app.py CHANGED
@@ -100,6 +100,14 @@ def _build_step_response(session: RuntimeSession) -> StepResponse:
100
  )
101
 
102
 
 
 
 
 
 
 
 
 
103
  @app.get("/health")
104
  def health() -> dict[str, str]:
105
  return {"status": "ok"}
 
100
  )
101
 
102
 
103
+ @app.get("/")
104
+ def root() -> dict[str, Any]:
105
+ return {
106
+ "message": "CI/CD Debugger Environment is running 🚀",
107
+ "endpoints": ["/health", "/reset", "/step", "/state"],
108
+ }
109
+
110
+
111
  @app.get("/health")
112
  def health() -> dict[str, str]:
113
  return {"status": "ok"}