File size: 1,599 Bytes
99d2ff3 e2284e6 99d2ff3 e2284e6 99d2ff3 e2284e6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import requests
import json
def test():
# Use the correct port 7860 as defined in app.py
base_url = "http://localhost:7860"
print(f"Resetting the environment (easy task) via {base_url}/reset...")
try:
resp = requests.post(f"{base_url}/reset", json={"task": "easy"})
resp.raise_for_status()
data = resp.json()
# New API returns a wrapped object: {"observation": ..., "state": ...}
obs = data["observation"]
episode_id = data["state"]["episode_id"]
print(f"Initial Observation (Episode: {episode_id}):")
print(json.dumps(obs, indent=2))
except (requests.exceptions.RequestException, KeyError) as e:
print(f"Error during reset: {e}")
return
print("\nTaking an action: 'follow_prompt'...")
try:
resp = requests.post(f"{base_url}/step", json={
"action": {"action_type": "follow_prompt"},
"episode_id": episode_id
})
resp.raise_for_status()
result = resp.json()
print("Step Result:")
print(json.dumps(result, indent=2))
print("\nTaking an action: 'minor_hallucination'...")
resp = requests.post(f"{base_url}/step", json={
"action": {"action_type": "minor_hallucination"},
"episode_id": episode_id
})
resp.raise_for_status()
result = resp.json()
print("Step Result:")
print(json.dumps(result, indent=2))
except Exception as e:
print(f"Error during steps: {e}")
if __name__ == "__main__":
test()
|