Spaces:
Sleeping
Sleeping
File size: 3,144 Bytes
684f052 | 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | {
"cells": [
{
"cell_type": "markdown",
"id": "f35f9b9f",
"metadata": {},
"source": [
"# Explore Code Review Environment\n",
"Interactive walkthrough for reset/step/state/tasks/score endpoints and reward plotting."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b7fdb1b5",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import matplotlib.pyplot as plt\n",
"\n",
"BASE_URL = \"http://127.0.0.1:7860\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "67c4198b",
"metadata": {},
"outputs": [],
"source": [
"root = requests.get(f\"{BASE_URL}/\").json()\n",
"tasks = requests.get(f\"{BASE_URL}/tasks\").json()\n",
"health = requests.get(f\"{BASE_URL}/health\").json()\n",
"root, health, tasks['count']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a4c4ee88",
"metadata": {},
"outputs": [],
"source": [
"reset = requests.get(f\"{BASE_URL}/reset\", params={\"task_id\": \"bug_detection_easy_1\"}).json()\n",
"reset['observation']['task_description']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "09904e44",
"metadata": {},
"outputs": [],
"source": [
"actions = [\n",
" {\n",
" \"action\": {\n",
" \"action_type\": \"add_comment\",\n",
" \"comments\": [{\"line_number\": 3, \"content\": \"Potential division_by_zero issue\", \"is_issue\": True, \"severity\": \"high\"}],\n",
" \"suggestions\": []\n",
" }\n",
" },\n",
" {\n",
" \"action\": {\n",
" \"action_type\": \"suggest_fix\",\n",
" \"comments\": [],\n",
" \"suggestions\": [{\"original_line\": 3, \"suggested_code\": \"return total / len(numbers) if numbers else 0\", \"explanation\": \"guard empty input\"}]\n",
" }\n",
" },\n",
" {\n",
" \"action\": {\n",
" \"action_type\": \"request_changes\",\n",
" \"comments\": [],\n",
" \"suggestions\": [],\n",
" \"final_decision\": \"changes_requested\"\n",
" }\n",
" }\n",
"]\n",
"\n",
"rewards = []\n",
"for payload in actions:\n",
" result = requests.post(f\"{BASE_URL}/step\", json=payload).json()\n",
" rewards.append(result['reward'])\n",
"\n",
"score = requests.get(f\"{BASE_URL}/score\").json()\n",
"state = requests.get(f\"{BASE_URL}/state\").json()\n",
"rewards, score, state['current_step']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23a8c51f",
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(6, 3))\n",
"plt.plot(range(1, len(rewards) + 1), rewards, marker='o')\n",
"plt.title('Reward per Step')\n",
"plt.xlabel('Step')\n",
"plt.ylabel('Reward')\n",
"plt.grid(True, alpha=0.3)\n",
"plt.show()"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|