This repository is the official repository of "HapRepair: Learn to Repair OpenHarmony Apps".
This is an automated ArkTS code defect repair system based on large language models. The system uses Retrieval-Augmented Generation (RAG) technology combined with multiple large language models to detect and fix performance defects in ArkTS code.
Here's the framework of the system:
- Code defect detection
- RAG-based code repair suggestion generation
- Multi-round code repair
- Code functionality verification
- Multi-model support (GPT, Deepseek, Qwen, etc.)
The system consists of the following main modules:
- Code Repair Module (
fix.py
,fix_projects.py
) - Vector Retrieval Module (
save_defects_to_database.py
) - Prompt Generation Module (
get_prompt.py
) - Output Processing Module (
output_handler.py
) - Context Extraction Module (
get_surrounding_context.py
)
The control flow graph is generated by ArkAnalyzer.
You can get the CFG of the projects by running the script arkanalyzer/tests/CFGTest.ts
.
- OpenAI GPT Series
- Deepseek Chat
- Qwen
- Ollama
- LLaMA
- GPTGod
- Configure environment variables:
OPENAI_API_KEY=<your_key>
OPENAI_API_BASE=<api_base>
DEEPSEEK_API_KEY=<your_key>
DEEPSEEK_API_BASE=<api_base>
PINECONE_API_KEY=<your_key>
- Install dependencies:
pip install -r requirements.txt
- Run defect detection:
python RQ1.py
- Run code repair:
python fix.py
Besides, you can use CodeLinter in Huawei DevEco Studio to detect code defects.
And use ArkAnalyzer to obtain the CFG of the code to check the functionality of the code.
The project includes a data visualization module (draw.ipynb
) that can generate:
- Defect detection accuracy analysis charts
- Multi-round repair effectiveness comparison charts
- Uses RAG to improve repair quality
- Supports multiple large language models
- Multi-round iterative repair mechanism
- Code functionality verification ensures repair quality
- Context-aware code repair
- Requires configuration of relevant API keys
- Recommended Python version: 3.10+
- Requires sufficient GPU memory for running large language models
- Recommended to backup code before repair
Issues and Pull Requests are welcome to help improve the project.
This project is licensed under the MIT License - see the LICENSE file for details.