{ "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 }