Mridul Jain commited on
Commit
6475c9b
·
1 Parent(s): 8c8e9ae

Sovereign Injection Efficiency: Universal credential synchronization for effortless judge onboarding (v3.9)

Browse files
Files changed (2) hide show
  1. server/app.py +16 -21
  2. server/static/app.js +5 -1
server/app.py CHANGED
@@ -128,30 +128,25 @@ async def policy_trace_socket(websocket: WebSocket):
128
  continue
129
 
130
  cmd = msg.get("action")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  if cmd == "reset":
132
  env = ContentGuardEnv()
133
  try:
134
- # Capture session-specific credentials (v3.3)
135
- cfg = msg.get("config", {})
136
- if cfg.get("api_key"):
137
- api_key = cfg["api_key"]
138
- base_url = cfg.get("base_url") or "https://api.openai.com/v1"
139
-
140
- # Elite v3.5: Intelligent Router logic
141
- if api_key.startswith("hf_") and "openai.com" in base_url:
142
- print(f"🔄 [ROUTER] HF Token detected. Routing to Hugging Face Inference API.")
143
- base_url = "https://api-inference.huggingface.co/v1"
144
-
145
- print(f"🔑 [SECURITY] Session key detected. Initializing temporary judge client.")
146
- session_client = AsyncOpenAI(
147
- api_key=api_key,
148
- base_url=base_url
149
- )
150
- session_model = cfg.get("model") or (MODEL_NAME if "openai.com" in base_url else "meta-llama/Llama-3-70b-instruct")
151
- else:
152
- session_client = aclient
153
- session_model = MODEL_NAME
154
-
155
  obs = env.reset(task_id=msg.get("task_id", "easy"))
156
  # Explicitly dump Pydantic model for WebSocket JSON serialization
157
  await websocket.send_json({"type": "reset", "observation": obs.model_dump()})
 
128
  continue
129
 
130
  cmd = msg.get("action")
131
+ # Elite v3.9: Universal Credential Injector
132
+ cfg = msg.get("config", {})
133
+ if cfg.get("api_key"):
134
+ api_key = cfg["api_key"]
135
+ base_url = cfg.get("base_url") or "https://api.openai.com/v1"
136
+
137
+ # Intelligent Router logic
138
+ if api_key.startswith("hf_") and "openai.com" in base_url:
139
+ base_url = "https://api-inference.huggingface.co/v1"
140
+
141
+ session_client = AsyncOpenAI(api_key=api_key, base_url=base_url)
142
+ session_model = cfg.get("model") or (MODEL_NAME if "openai.com" in base_url else "meta-llama/Llama-3-70b-instruct")
143
+ elif session_client is None:
144
+ session_client = aclient
145
+ session_model = MODEL_NAME
146
+
147
  if cmd == "reset":
148
  env = ContentGuardEnv()
149
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  obs = env.reset(task_id=msg.get("task_id", "easy"))
151
  # Explicitly dump Pydantic model for WebSocket JSON serialization
152
  await websocket.send_json({"type": "reset", "observation": obs.model_dump()})
server/static/app.js CHANGED
@@ -184,7 +184,11 @@ const app = {
184
  document.getElementById('btn-run-agent').style.opacity = '0.5';
185
  document.getElementById('btn-auto-loop').disabled = true;
186
 
187
- this.ws.send(JSON.stringify({ action: "run_agent" }));
 
 
 
 
188
  },
189
 
190
  handleStreamChunk: function(content) {
 
184
  document.getElementById('btn-run-agent').style.opacity = '0.5';
185
  document.getElementById('btn-auto-loop').disabled = true;
186
 
187
+ const config = JSON.parse(sessionStorage.getItem('env_config') || '{}');
188
+ this.ws.send(JSON.stringify({
189
+ action: "run_agent",
190
+ config: config
191
+ }));
192
  },
193
 
194
  handleStreamChunk: function(content) {