Deadman922 commited on
Commit
780f109
·
verified ·
1 Parent(s): f6d6695

Upload 15 files

Browse files
Files changed (2) hide show
  1. inference.py +11 -4
  2. server/main.py +3 -7
inference.py CHANGED
@@ -31,7 +31,10 @@ except ImportError:
31
  # Defaults are set only for API_BASE_URL and MODEL_NAME
32
  # (and should reflect your active inference setup):
33
  API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
34
- MODEL_NAME = os.getenv("MODEL_NAME", "meta-llama/Llama-3.3-70B-Instruct")
 
 
 
35
  HF_TOKEN = os.getenv("HF_TOKEN")
36
  LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME")
37
 
@@ -201,7 +204,7 @@ Generate your next action (SQL or action name):"""
201
  return 'QUERY' # Default fallback
202
 
203
  except Exception as e:
204
- print(f"[DEBUG] LLM generation failed: {e}", flush=True)
205
  return 'SELECT 1;' # Safe fallback
206
 
207
  def run_task(self, task_id: str, seed: int = None):
@@ -244,6 +247,10 @@ Generate your next action (SQL or action name):"""
244
  # Extract column name from response
245
  column_match = re.search(r'PROFILE\s+(\w+)', action_text, re.IGNORECASE)
246
  column_name = column_match.group(1) if column_match else None
 
 
 
 
247
  else:
248
  # Assume SQL query
249
  action_type = 'query'
@@ -282,7 +289,7 @@ Generate your next action (SQL or action name):"""
282
  break
283
 
284
  except Exception as e:
285
- print(f"[DEBUG] Task execution failed: {e}", flush=True)
286
 
287
  return success, steps_taken, score, rewards
288
 
@@ -297,7 +304,7 @@ def main():
297
  if not HF_TOKEN:
298
  print("Error: HF_TOKEN environment variable is required", flush=True)
299
  print("Please set HF_TOKEN or ensure .env file exists with the token", flush=True)
300
- return
301
 
302
  # Initialize agent
303
  agent = SQLQualityAgent(API_BASE_URL, MODEL_NAME, HF_TOKEN, ENV_BASE_URL)
 
31
  # Defaults are set only for API_BASE_URL and MODEL_NAME
32
  # (and should reflect your active inference setup):
33
  API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
34
+ MODEL_NAME = os.getenv("MODEL_NAME")
35
+ if MODEL_NAME is None:
36
+ print("MODEL_NAME environment variable is required", file=sys.stderr, flush=True)
37
+ sys.exit(1)
38
  HF_TOKEN = os.getenv("HF_TOKEN")
39
  LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME")
40
 
 
204
  return 'QUERY' # Default fallback
205
 
206
  except Exception as e:
207
+ print(f"[DEBUG] LLM generation failed: {e}", flush=True, file=sys.stderr)
208
  return 'SELECT 1;' # Safe fallback
209
 
210
  def run_task(self, task_id: str, seed: int = None):
 
247
  # Extract column name from response
248
  column_match = re.search(r'PROFILE\s+(\w+)', action_text, re.IGNORECASE)
249
  column_name = column_match.group(1) if column_match else None
250
+ elif re.match(r'^\s*(UPDATE|INSERT|DELETE|ALTER)\b', action_text, re.IGNORECASE):
251
+ action_type = 'fix'
252
+ sql = action_text
253
+ column_name = None
254
  else:
255
  # Assume SQL query
256
  action_type = 'query'
 
289
  break
290
 
291
  except Exception as e:
292
+ print(f"[DEBUG] Task execution failed: {e}", flush=True, file=sys.stderr)
293
 
294
  return success, steps_taken, score, rewards
295
 
 
304
  if not HF_TOKEN:
305
  print("Error: HF_TOKEN environment variable is required", flush=True)
306
  print("Please set HF_TOKEN or ensure .env file exists with the token", flush=True)
307
+ sys.exit(1)
308
 
309
  # Initialize agent
310
  agent = SQLQualityAgent(API_BASE_URL, MODEL_NAME, HF_TOKEN, ENV_BASE_URL)
server/main.py CHANGED
@@ -190,14 +190,10 @@ def load_static_html() -> str:
190
 
191
  # Validate LLM configuration at startup
192
  runtime = _resolve_llm_runtime()
193
- if not runtime["configured"]:
 
194
  missing_vars = ", ".join(runtime["missing"])
195
- print(f"FATAL: Missing required LLM environment variables: {missing_vars}")
196
- print("Please set the following environment variables:")
197
- for var in runtime["missing"]:
198
- print(f" - {var}")
199
- import sys
200
- sys.exit(1)
201
 
202
 
203
  @app.get("/", response_class=HTMLResponse)
 
190
 
191
  # Validate LLM configuration at startup
192
  runtime = _resolve_llm_runtime()
193
+ LLM_AVAILABLE = runtime["configured"]
194
+ if not LLM_AVAILABLE:
195
  missing_vars = ", ".join(runtime["missing"])
196
+ print(f"[WARNING] LLM env vars not set: {missing_vars}. Server starting in mock mode.", flush=True)
 
 
 
 
 
197
 
198
 
199
  @app.get("/", response_class=HTMLResponse)