{"id":25799315,"url":"https://github.com/felixoder/felix-detect-fix","last_synced_at":"2025-02-27T15:42:31.582Z","repository":{"id":279656820,"uuid":"939486986","full_name":"felixoder/felix-detect-fix","owner":"felixoder","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-26T18:03:11.000Z","size":111,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-26T18:27:22.242Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/felixoder.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-26T16:08:38.000Z","updated_at":"2025-02-26T18:03:14.000Z","dependencies_parsed_at":"2025-02-26T18:38:12.549Z","dependency_job_id":null,"html_url":"https://github.com/felixoder/felix-detect-fix","commit_stats":null,"previous_names":["felixoder/felix-detect-fix"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixoder%2Ffelix-detect-fix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixoder%2Ffelix-detect-fix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixoder%2Ffelix-detect-fix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixoder%2Ffelix-detect-fix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/felixoder","download_url":"https://codeload.github.com/felixoder/felix-detect-fix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241030023,"owners_count":19897011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-27T15:42:30.907Z","updated_at":"2025-02-27T15:42:31.566Z","avatar_url":"https://github.com/felixoder.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Felix Detect \u0026 Fix - VS Code Extension\n\n![Felix Detect \u0026 Fix](https://img.shields.io/badge/VS%20Code-Extension-blue.svg)\n![License](https://img.shields.io/badge/license-MIT-green.svg)\n\nA powerful VS Code extension that detects and fixes code bugs using **machine learning**. This extension integrates with a **bug detection model** and a **bug-fixing model** hosted on Hugging Face, allowing developers to improve code quality efficiently.\n\n## Features ✨\n\n- 🚀 **Detect Bugs**: Classifies code as \"buggy\" or \"bug-free.\"\n- 🔧 **Fix Bugs**: Automatically suggests fixes for detected issues.\n- 💡 **Manual Control**: Users decide when to run the detection and fixing functions.\n- ⚡ **Fast \u0026 Local Processing**: Uses Hugging Face models **locally**, avoiding API calls.\n\n## Installation 🛠️\n\n1. Download and install the extension from the [VS Code Marketplace](https://marketplace.visualstudio.com/vscode).\n2. Ensure you have **Node.js** and **VS Code** installed.\n3. Open VS Code and enable the extension.\n\n## Usage 🚀\n\n1. project structure\n   |_ your_code.py\n   |_ bug*detector_model [download from ```huggingface-cli download felixoder/bug_detector_model --local-dir ./bug_detector_model\\n```]\n   |_ bug*fixer_model [download from ```huggingface-cli download felixoder/bug_fixer_model --local-dir ./bug_fixer_model```]\n   |_run_model.py [see ## run_model.py]\n\n## run_model.py script:\n\n```sh\npip install torch\npip install transformers\n```\n\n```sh\nimport sys\n\nimport torch\nfrom transformers import (\n    AutoModelForCausalLM,\n    AutoModelForSequenceClassification,\n    AutoTokenizer,\n)\n\ndetector_name = \"./bug_detector_model\"\nfixer_name = \"./bug_fixer_model\"\n\n# Automatically select the best available device (GPU \u003e MPS \u003e CPU)\ndevice = (\n    torch.device(\"cuda\")\n    if torch.cuda.is_available()\n    else torch.device(\"mps\")\n    if torch.backends.mps.is_available()\n    else torch.device(\"cpu\")\n)\n\n# Use FP16 if on GPU, else FP32\ntorch_dtype = torch.float16 if device.type == \"cuda\" else torch.float32\n\ntokenizer = AutoTokenizer.from_pretrained(detector_name)\nmodel = AutoModelForSequenceClassification.from_pretrained(\n    detector_name, torch_dtype=torch_dtype\n).to(device)\n\nfixer_tokenizer = AutoTokenizer.from_pretrained(fixer_name)\nfixer_model = AutoModelForCausalLM.from_pretrained(\n    fixer_name, torch_dtype=torch_dtype, low_cpu_mem_usage=True\n).to(device)\n\n\ndef classify_code(code):\n    inputs = tokenizer(\n        code, return_tensors=\"pt\", padding=True, truncation=True, max_length=512\n    ).to(device)\n    with torch.no_grad():\n        outputs = model(**inputs)\n    predicted_label = torch.argmax(outputs.logits, dim=1).item()\n    return \"bug-free\" if predicted_label == 0 else \"buggy\"\n\n\ndef fix_buggy_code(code):\n    prompt = f\"### Fix this buggy Python code:\\n{code}\\n### Fixed Python code:\\n\"\n    inputs = fixer_tokenizer(prompt, return_tensors=\"pt\").to(device)\n\n    with torch.no_grad():\n        outputs = fixer_model.generate(\n            **inputs, max_length=256, do_sample=False, num_return_sequences=1\n        )\n\n    fixed_code = fixer_tokenizer.decode(outputs[0], skip_special_tokens=True)\n    return (\n        fixed_code.split(\"### Fixed Python code:\")[1].strip()\n        if \"### Fixed Python code:\" in fixed_code\n        else fixed_code\n    )\n\n\nif __name__ == \"__main__\":\n    command = sys.argv[1]\n    code = sys.argv[2]\n\n    if command == \"classify\":\n        print(classify_code(code))\n    elif command == \"fix\":\n        print(fix_buggy_code(code))\n\n\n```\n\n2. **Detect Bugs**:\n\n   - Open a python code file.\n   - Run the command: `Detect Bugs`\n   - The extension highlights buggy code sections.\n\n3. **Use a build template**:\n\n   - Paste this in your terminal\n\n   ```sh\n    wget -O setup_and_run.sh https://raw.githubusercontent.com/felixoder/felix-detect-fix/master/setup_and_run.sh\n   ```\n\n   ```sh\n       chmod +x setup_and_run.sh\n   ```\n\n   ```sh\n       ./setup_and_run.sh\n\n   ```\n\n4. **Fix Bugs**:\n   - After detecting bugs, run `Fix Bugs`\n   - The model suggests code fixes.\n\n## Installation from Source 🏗️\n\n1. Clone the repository:\n   ```sh\n   git clone https://github.com/felixoder/felix-detect-fix.git\n   cd felix-detect-fix\n   ```\n2. Install dependencies:\n   ```sh\n   npm install\n   ```\n3. Package the extension:\n   ```sh\n   vsce package\n   ```\n4. Install the packaged `.vsix` file in VS Code.\n\n## Requirements 📦\n\n- VS Code **1.70+**\n- Node.js **18+**\n- Hugging Face models:\n  - [Bug Detector](https://huggingface.co/felixoder/bug_detector_model)\n  - [Bug Fixer](https://huggingface.co/felixoder/bug_fixer_model)\n\n## Contributing 🤝\n\n1. Fork the repo \u0026 create a new branch.\n2. Make your changes \u0026 commit.\n3. Open a Pull Request!\n\n## License 📜\n\nThis project is licensed under the MIT License.\n\n---\n\nMade with ❤️ by [Debayan Ghosh](https://github.com/felixoder).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixoder%2Ffelix-detect-fix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelixoder%2Ffelix-detect-fix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixoder%2Ffelix-detect-fix/lists"}