| """Quick test of all OpenEnv endpoints.""" |
| import requests |
| import json |
|
|
| BASE = "http://localhost:7860" |
|
|
| |
| print("=== /health ===") |
| r = requests.get(f"{BASE}/health") |
| print(f" Status: {r.status_code} -> {r.json()}") |
|
|
| |
| print("\n=== /reset (quick_pick) ===") |
| r = requests.post(f"{BASE}/reset", json={"task": "quick_pick"}) |
| data = r.json() |
| info = data["info"] |
| print(f" Task: {info['task']}, Difficulty: {info['difficulty']}") |
| print(f" Products: {info['product_count']}, Max steps: {info['max_steps']}") |
| print(f" Ideal product: {info['ideal_product']} (score: {info['ideal_score']:.2f})") |
| products = data["observation"]["candidate_products"] |
| pids = [p["id"] for p in products] |
| print(f" Product IDs: {pids}") |
|
|
| |
| print("\n=== /step (view_item) ===") |
| r = requests.post(f"{BASE}/step", json={"action_type": "view_item", "item_ids": pids[:2]}) |
| d = r.json() |
| print(f" Reward: {d['reward']}, Done: {d['done']}, Step: {d['info']['step_count']}") |
|
|
| |
| print("\n=== /step (compare) ===") |
| r = requests.post(f"{BASE}/step", json={"action_type": "compare", "item_ids": pids[:3]}) |
| d = r.json() |
| print(f" Reward: {d['reward']}, Done: {d['done']}") |
|
|
| |
| print("\n=== /step (buy) ===") |
| r = requests.post(f"{BASE}/step", json={"action_type": "buy", "item_ids": [pids[0]]}) |
| d = r.json() |
| print(f" Reward: {d['reward']}, Done: {d['done']}") |
| print(f" Cumulative: {d['info']['cumulative_reward']}") |
|
|
| |
| print("\n=== /state ===") |
| r = requests.get(f"{BASE}/state") |
| d = r.json() |
| print(f" Task: {d['task_name']}, Steps: {d['step_count']}, Done: {d['done']}") |
| print(f" Cumulative reward: {d['cumulative_reward']}") |
|
|
| |
| print("\n=== /reset (smart_shop) ===") |
| r = requests.post(f"{BASE}/reset", json={"task": "smart_shop"}) |
| data = r.json() |
| info = data["info"] |
| print(f" Task: {info['task']}, Products: {info['product_count']}, Max steps: {info['max_steps']}") |
|
|
| |
| print("\n=== /reset (expert_deal) ===") |
| r = requests.post(f"{BASE}/reset", json={"task": "expert_deal"}) |
| data = r.json() |
| info = data["info"] |
| print(f" Task: {info['task']}, Products: {info['product_count']}, Max steps: {info['max_steps']}") |
|
|
| print("\n" + "=" * 50) |
| print("ALL OPENENV ENDPOINTS WORKING ✓") |
| print("=" * 50) |
|
|