基于 Qwen 2.5 Coder 模型的智能代码生成、补全、解释、优化和调试工具。
- 🎯 代码生成: 根据自然语言描述生成高质量代码
- 🔧 代码补全: 智能补全未完成的代码片段
- 📖 代码解释: 详细解释代码的功能和实现原理
- ⚡ 代码优化: 提升代码性能和可读性
- 🐛 代码调试: 自动修复代码错误
- 🌍 多语言支持: 支持 20+ 种编程语言
- 💬 交互模式: 实时对话式代码生成
- 🚀 流式输出: 实时查看生成过程
Python, JavaScript, TypeScript, Java, C++, C, C#, Go, Rust, PHP, Ruby, Swift, Kotlin, Scala, R, SQL, HTML, CSS, Bash, PowerShell 等
chmod +x setup.sh
./setup.sh# 创建虚拟环境
python3 -m venv venv
source venv/bin/activate # Linux/Mac
# 或 venv\Scripts\activate # Windows
# 安装依赖
pip install -r requirements.txtpython demo.pypython qwen_code.py --interactive在交互模式中,你可以使用以下命令:
generate <需求>- 生成代码complete <代码>- 代码补全explain <代码>- 代码解释optimize <代码>- 代码优化debug <代码> [错误信息]- 代码调试lang <语言>- 设置编程语言quit- 退出
# 代码生成
python qwen_code.py --mode generate --prompt "写一个快速排序算法" --language python
# 代码补全
python qwen_code.py --mode complete --code "def fibonacci(n):" --language python
# 代码解释
python qwen_code.py --mode explain --code "你的代码" --language python
# 代码优化
python qwen_code.py --mode optimize --code "你的代码" --language python
# 代码调试
python qwen_code.py --mode debug --code "有问题的代码" --error "错误信息" --language pythonfrom qwen_code import QwenCodeGenerator
# 初始化
generator = QwenCodeGenerator()
generator.load_model()
# 生成代码
code = generator.generate_code("写一个计算器类", "python")
print(code)
# 代码补全
completed = generator.complete_code("def hello_world():", "python")
print(completed)
# 代码解释
explanation = generator.explain_code("print('Hello, World!')", "python")
print(explanation)编辑 config.json 文件来自定义配置:
{
"model_config": {
"default_model": "Qwen/Qwen2.5-Coder-7B-Instruct",
"device": "auto"
},
"generation_config": {
"temperature": 0.7,
"top_p": 0.8,
"max_new_tokens": 2048
}
}输入: "写一个计算两个数最大公约数的函数"
输出:
def gcd(a, b):
"""
计算两个数的最大公约数(欧几里得算法)
Args:
a (int): 第一个数
b (int): 第二个数
Returns:
int: 最大公约数
"""
while b:
a, b = b, a % b
return a
# 使用示例
print(gcd(48, 18)) # 输出: 6输入代码:
def find_max(numbers):
max_num = numbers[0]
for i in range(len(numbers)):
if numbers[i] > max_num:
max_num = numbers[i]
return max_num优化后:
def find_max(numbers):
"""
找到列表中的最大值
Args:
numbers (list): 数字列表
Returns:
数字: 最大值
"""
if not numbers:
raise ValueError("列表不能为空")
return max(numbers) # 使用内置函数,更简洁高效python qwen_code.py --mode generate --prompt "你的需求" --streampython qwen_code.py --model "Qwen/Qwen2.5-Coder-14B-Instruct" --interactivepython qwen_code.py --device cuda --interactive # 使用 GPU
python qwen_code.py --device cpu --interactive # 使用 CPU- Python 3.8+
- 8GB+ RAM(推荐 16GB+)
- GPU(可选,但强烈推荐用于更快的推理)
- NVIDIA GPU with CUDA 11.8+
- Apple Silicon (M1/M2) with MPS
- AMD GPU with ROCm(实验性支持)
- 首次运行: 首次运行时会自动下载模型文件(约 4-15GB),请确保网络连接稳定
- 内存需求: 7B 模型需要至少 8GB RAM,14B+ 模型需要 16GB+ RAM
- GPU 加速: 使用 GPU 可以显著提升生成速度
- 模型选择: 可以根据硬件配置选择合适的模型大小
-
内存不足
# 使用更小的模型 python qwen_code.py --model "Qwen/Qwen2.5-Coder-1.5B-Instruct"
-
CUDA 错误
# 强制使用 CPU python qwen_code.py --device cpu -
网络问题
# 设置代理(如果需要) export HF_ENDPOINT=https://hf-mirror.com
本项目基于 MIT 许可证开源。
欢迎提交 Issue 和 Pull Request!
如果遇到问题,请:
- 查看本 README 的故障排除部分
- 提交 Issue 描述问题
- 加入社区讨论
享受智能编程的乐趣! 🎉
- 更改默认下载目录
- Edge → Settings → Downloads → Location → Change
- 建议选择
~/Downloads或~/Documents/Downloads
- 每次下载前询问保存位置
- Edge → Settings → Downloads → 打开 “Ask me where to save each file”
- 关闭自动打开下载
- Edge → Settings → Downloads → 关闭 “Automatically open downloads”
- 设为默认浏览器(可选)
- macOS 设置 → 桌面与程序坞 → 默认网页浏览器 → Microsoft Edge
- 命令行快速打开(macOS)
-
open -a "Microsoft Edge"
-