Spaces:
Sleeping
Sleeping
Upload inference.py
Browse files- inference.py +7 -9
inference.py
CHANGED
|
@@ -195,7 +195,7 @@ Generate your next action (SQL or action name):"""
|
|
| 195 |
return text.upper()
|
| 196 |
else:
|
| 197 |
# Try to extract SQL from response
|
| 198 |
-
sql_match = re.search(r'(SELECT
|
| 199 |
if sql_match:
|
| 200 |
return sql_match.group(1).strip()
|
| 201 |
return 'QUERY' # Default fallback
|
|
@@ -234,6 +234,10 @@ Generate your next action (SQL or action name):"""
|
|
| 234 |
action_type = 'submit'
|
| 235 |
sql = None
|
| 236 |
column_name = None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
elif action_text.upper().startswith('PROFILE'):
|
| 238 |
action_type = 'profile'
|
| 239 |
sql = None
|
|
@@ -272,6 +276,8 @@ Generate your next action (SQL or action name):"""
|
|
| 272 |
except Exception as e:
|
| 273 |
error_msg = str(e)
|
| 274 |
current_action = f"{action_type}:{sql or column_name or 'N/A'}"
|
|
|
|
|
|
|
| 275 |
log_step(step=step, action=current_action, reward=0.0, done=False, error=error_msg)
|
| 276 |
break
|
| 277 |
|
|
@@ -293,14 +299,6 @@ def main():
|
|
| 293 |
print("Please set HF_TOKEN or ensure .env file exists with the token", flush=True)
|
| 294 |
return
|
| 295 |
|
| 296 |
-
if not API_BASE_URL:
|
| 297 |
-
print("Error: API_BASE_URL environment variable is required", flush=True)
|
| 298 |
-
return
|
| 299 |
-
|
| 300 |
-
if not MODEL_NAME:
|
| 301 |
-
print("Error: MODEL_NAME environment variable is required", flush=True)
|
| 302 |
-
return
|
| 303 |
-
|
| 304 |
# Initialize agent
|
| 305 |
agent = SQLQualityAgent(API_BASE_URL, MODEL_NAME, HF_TOKEN, ENV_BASE_URL)
|
| 306 |
|
|
|
|
| 195 |
return text.upper()
|
| 196 |
else:
|
| 197 |
# Try to extract SQL from response
|
| 198 |
+
sql_match = re.search(r'((?:SELECT|INSERT|UPDATE|DELETE|CREATE|ALTER|DROP)[\s\S]*?(?:;|$))', text, re.IGNORECASE | re.DOTALL)
|
| 199 |
if sql_match:
|
| 200 |
return sql_match.group(1).strip()
|
| 201 |
return 'QUERY' # Default fallback
|
|
|
|
| 234 |
action_type = 'submit'
|
| 235 |
sql = None
|
| 236 |
column_name = None
|
| 237 |
+
elif action_text.upper() == 'FIX' or action_text.upper().startswith('FIX'):
|
| 238 |
+
action_type = 'fix'
|
| 239 |
+
sql = action_text
|
| 240 |
+
column_name = None
|
| 241 |
elif action_text.upper().startswith('PROFILE'):
|
| 242 |
action_type = 'profile'
|
| 243 |
sql = None
|
|
|
|
| 276 |
except Exception as e:
|
| 277 |
error_msg = str(e)
|
| 278 |
current_action = f"{action_type}:{sql or column_name or 'N/A'}"
|
| 279 |
+
steps_taken = step
|
| 280 |
+
rewards.append(0.0)
|
| 281 |
log_step(step=step, action=current_action, reward=0.0, done=False, error=error_msg)
|
| 282 |
break
|
| 283 |
|
|
|
|
| 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)
|
| 304 |
|