Spaces:
Sleeping
Sleeping
tested file
Browse files- inference.py +29 -18
- test_inference.py +26 -0
inference.py
CHANGED
|
@@ -6,16 +6,18 @@ from env.environment import DataCleaningEnv
|
|
| 6 |
# ------------------ ENV VARIABLES ------------------
|
| 7 |
API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
|
| 8 |
MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
|
| 9 |
-
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 10 |
|
| 11 |
-
if HF_TOKEN is None:
|
| 12 |
-
raise ValueError("HF_TOKEN environment variable is required")
|
| 13 |
|
| 14 |
# ------------------ OPENAI CLIENT ------------------
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
MAX_STEPS = 6
|
| 21 |
|
|
@@ -77,21 +79,27 @@ Do NOT explain anything.
|
|
| 77 |
Only return the action.
|
| 78 |
"""
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
temperature=0.3,
|
| 84 |
-
max_tokens=50
|
| 85 |
-
)
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
-
try:
|
| 90 |
action_type, column = output.split(",")
|
| 91 |
return {"type": action_type.strip(), "column": column.strip()}
|
| 92 |
-
except:
|
| 93 |
-
return {"type": "fill_nulls", "column": "city"} # fallback
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# ------------------ MAIN ------------------
|
| 96 |
def main():
|
| 97 |
env = DataCleaningEnv(task=1)
|
|
@@ -152,4 +160,7 @@ def main():
|
|
| 152 |
log_end(success, steps_taken, score, rewards)
|
| 153 |
|
| 154 |
if __name__ == "__main__":
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# ------------------ ENV VARIABLES ------------------
|
| 7 |
API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")
|
| 8 |
MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")
|
| 9 |
+
HF_TOKEN = os.getenv("HF_TOKEN","")
|
| 10 |
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# ------------------ OPENAI CLIENT ------------------
|
| 13 |
+
try:
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
base_url=os.getenv("API_BASE_URL", "https://router.huggingface.co/v1"),
|
| 16 |
+
api_key=os.getenv("HF_TOKEN", "")
|
| 17 |
+
)
|
| 18 |
+
except Exception as e:
|
| 19 |
+
print("Client init failed:", e)
|
| 20 |
+
client = None
|
| 21 |
|
| 22 |
MAX_STEPS = 6
|
| 23 |
|
|
|
|
| 79 |
Only return the action.
|
| 80 |
"""
|
| 81 |
|
| 82 |
+
try:
|
| 83 |
+
if client is None:
|
| 84 |
+
raise Exception("Client not initialized")
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
+
response = client.chat.completions.create(
|
| 87 |
+
model=MODEL_NAME,
|
| 88 |
+
messages=[{"role": "user", "content": prompt}],
|
| 89 |
+
temperature=0.3,
|
| 90 |
+
max_tokens=50
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
output = response.choices[0].message.content.strip()
|
| 94 |
|
|
|
|
| 95 |
action_type, column = output.split(",")
|
| 96 |
return {"type": action_type.strip(), "column": column.strip()}
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
except Exception as e:
|
| 99 |
+
print("LLM error:", e)
|
| 100 |
+
|
| 101 |
+
# ✅ SAFE FALLBACK (VERY IMPORTANT)
|
| 102 |
+
return {"type": "deduplicate", "column": "customer_id"}
|
| 103 |
# ------------------ MAIN ------------------
|
| 104 |
def main():
|
| 105 |
env = DataCleaningEnv(task=1)
|
|
|
|
| 160 |
log_end(success, steps_taken, score, rewards)
|
| 161 |
|
| 162 |
if __name__ == "__main__":
|
| 163 |
+
try:
|
| 164 |
+
main()
|
| 165 |
+
except Exception as e:
|
| 166 |
+
print("Fatal error:", e)
|
test_inference.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
|
| 3 |
+
print("🚀 Running inference.py test...\n")
|
| 4 |
+
|
| 5 |
+
try:
|
| 6 |
+
result = subprocess.run(
|
| 7 |
+
["python", "inference.py"],
|
| 8 |
+
capture_output=True,
|
| 9 |
+
text=True,
|
| 10 |
+
timeout=60
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
print("✅ STDOUT:\n")
|
| 14 |
+
print(result.stdout)
|
| 15 |
+
|
| 16 |
+
if result.stderr:
|
| 17 |
+
print("\n⚠️ STDERR:\n")
|
| 18 |
+
print(result.stderr)
|
| 19 |
+
|
| 20 |
+
if result.returncode == 0:
|
| 21 |
+
print("\n🎉 TEST PASSED: inference.py ran successfully")
|
| 22 |
+
else:
|
| 23 |
+
print(f"\n❌ TEST FAILED: Exit code {result.returncode}")
|
| 24 |
+
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print("💥 Test crashed:", e)
|