sumit989 commited on
Commit
6baaf59
Β·
verified Β·
1 Parent(s): 2110529

Update env.py

Browse files
Files changed (1) hide show
  1. env.py +50 -9
env.py CHANGED
@@ -1,3 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  class CodeEnv:
2
  def __init__(self):
3
  self.tasks = [
@@ -33,14 +69,19 @@ class CodeEnv:
33
 
34
  def step(self, action):
35
  fixed = action.get("fixed_code", "")
36
- if self.current["solution"] in fixed:
37
- reward = 1.0
38
- elif len(fixed.strip()) > 0:
39
- reward = 0.5
40
- else:
41
- reward = 0.0
42
-
43
- reward = float(reward)
 
44
  done = True
45
 
46
- return self.state(), reward, done, {}
 
 
 
 
 
1
+ # env.py β€” loads and validates all environment variables for CodeRescue
2
+ import os
3
+ from dotenv import load_dotenv
4
+
5
+ load_dotenv()
6
+
7
+ # ── API / Model ────────────────────────────────────────────────────────────────
8
+ API_BASE_URL: str = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
9
+ MODEL_NAME: str = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-Coder-7B-Instruct")
10
+ API_KEY: str = os.getenv("API_KEY") or os.getenv("HF_TOKEN") or ""
11
+
12
+ # ── CORS ───────────────────────────────────────────────────────────────────────
13
+ ALLOWED_ORIGINS: list[str] = os.getenv(
14
+ "ALLOWED_ORIGINS",
15
+ "https://sumit989bishnoi-crypto.github.io"
16
+ ).split(",")
17
+
18
+ # ── Server ─────────────────────────────────────────────────────────────────────
19
+ PORT: int = int(os.getenv("PORT", 7860))
20
+
21
+ # ── Validation ─────────────────────────────────────────────────────────────────
22
+ def validate() -> None:
23
+ """Call once at startup. Warns about missing critical variables."""
24
+ if not API_KEY:
25
+ print("[env] WARNING: No API_KEY or HF_TOKEN set β€” AI calls will fail.")
26
+ else:
27
+ print(f"[env] API_KEY : {'*' * 6}{API_KEY[-4:]}")
28
+
29
+ print(f"[env] API_BASE_URL: {API_BASE_URL}")
30
+ print(f"[env] MODEL_NAME : {MODEL_NAME}")
31
+ print(f"[env] ALLOWED_ORIGINS: {ALLOWED_ORIGINS}")
32
+ print(f"[env] PORT : {PORT}")
33
+
34
+
35
+ # ── CodeEnv ────────────────────────────────────────────────────────────────────
36
+
37
  class CodeEnv:
38
  def __init__(self):
39
  self.tasks = [
 
69
 
70
  def step(self, action):
71
  fixed = action.get("fixed_code", "")
72
+
73
+ if self.current["solution"] in fixed:
74
+ reward = 1.0
75
+ elif len(fixed.strip()) > 0:
76
+ reward = 0.5
77
+ else:
78
+ reward = 0.0
79
+
80
+ reward = float(reward)
81
  done = True
82
 
83
+ return self.state(), reward, done, {}
84
+
85
+
86
+ if __name__ == "__main__":
87
+ validate()