Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- baseline/run_baseline.py +4 -4
- server/app.py +10 -2
baseline/run_baseline.py
CHANGED
|
@@ -20,7 +20,7 @@ from code_debug_env.models import Action
|
|
| 20 |
try:
|
| 21 |
from openai import AsyncOpenAI
|
| 22 |
except ImportError:
|
| 23 |
-
print("Please install openai: pip install openai")
|
| 24 |
sys.exit(1)
|
| 25 |
|
| 26 |
BASE_URL = os.getenv("OPENENV_URL", "http://127.0.0.1:8000")
|
|
@@ -102,10 +102,10 @@ async def main(output_format: str = "table"):
|
|
| 102 |
if output_format == "json":
|
| 103 |
print(json.dumps({"baseline_results": results, "agent": "openai_api"}))
|
| 104 |
else:
|
| 105 |
-
print("\n=== Baseline Results ===")
|
| 106 |
for r in results:
|
| 107 |
-
print(f" {r['task_id']:15s} score={r['best_score']:.3f} steps={r['steps']}")
|
| 108 |
-
print(f"\n avg score: {sum(r['best_score'] for r in results) / len(results):.3f}")
|
| 109 |
|
| 110 |
if __name__ == "__main__":
|
| 111 |
output = "json" if "json" in sys.argv else "table"
|
|
|
|
| 20 |
try:
|
| 21 |
from openai import AsyncOpenAI
|
| 22 |
except ImportError:
|
| 23 |
+
print("Please install openai: pip install openai", file=sys.stderr)
|
| 24 |
sys.exit(1)
|
| 25 |
|
| 26 |
BASE_URL = os.getenv("OPENENV_URL", "http://127.0.0.1:8000")
|
|
|
|
| 102 |
if output_format == "json":
|
| 103 |
print(json.dumps({"baseline_results": results, "agent": "openai_api"}))
|
| 104 |
else:
|
| 105 |
+
print("\n=== Baseline Results ===", file=sys.stderr)
|
| 106 |
for r in results:
|
| 107 |
+
print(f" {r['task_id']:15s} score={r['best_score']:.3f} steps={r['steps']}", file=sys.stderr)
|
| 108 |
+
print(f"\n avg score: {sum(r['best_score'] for r in results) / len(results):.3f}", file=sys.stderr)
|
| 109 |
|
| 110 |
if __name__ == "__main__":
|
| 111 |
output = "json" if "json" in sys.argv else "table"
|
server/app.py
CHANGED
|
@@ -124,13 +124,21 @@ def run_baseline() -> dict:
|
|
| 124 |
Run the baseline agent on all tasks and return scores.
|
| 125 |
This endpoint triggers the baseline inference script.
|
| 126 |
"""
|
| 127 |
-
import subprocess, sys, json
|
| 128 |
try:
|
| 129 |
result = subprocess.run(
|
| 130 |
[sys.executable, "baseline/run_baseline.py", "--output", "json"],
|
| 131 |
capture_output=True, text=True, timeout=120,
|
| 132 |
)
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
except Exception as e:
|
| 135 |
raise HTTPException(status_code=500, detail=str(e))
|
| 136 |
|
|
|
|
| 124 |
Run the baseline agent on all tasks and return scores.
|
| 125 |
This endpoint triggers the baseline inference script.
|
| 126 |
"""
|
| 127 |
+
import subprocess, sys, json, re
|
| 128 |
try:
|
| 129 |
result = subprocess.run(
|
| 130 |
[sys.executable, "baseline/run_baseline.py", "--output", "json"],
|
| 131 |
capture_output=True, text=True, timeout=120,
|
| 132 |
)
|
| 133 |
+
|
| 134 |
+
# Robustly find JSON in potentially noisy stdout
|
| 135 |
+
stdout = result.stdout.strip()
|
| 136 |
+
match = re.search(r'(\{.*\})', stdout, re.DOTALL)
|
| 137 |
+
if match:
|
| 138 |
+
return json.loads(match.group(1))
|
| 139 |
+
|
| 140 |
+
raise ValueError(f"No JSON found in baseline output. Stdout: {stdout[:200]}")
|
| 141 |
+
|
| 142 |
except Exception as e:
|
| 143 |
raise HTTPException(status_code=500, detail=str(e))
|
| 144 |
|