AI程序员(aider)+ollama+DeepSeek-R1安装配置和使用
概述
aider其实是ai coder的缩写,可以说是一个ai programmer,可以根据需求编写代码,可以分析代码,重构代码等。比一般的代码助手更加智能。目前还处于比较初级的版本,但已经具备一定的可用性。
本文介绍aider的本地部署和使用,通过ollama的部署和使用可以让aider使用本地部署的大模型。比如:qwen或deepseek等。ollama的安装和模型的拉取,可以参考我前面的文章,这里不再赘述。
安装aider
python -m pip install aider-install
# 安装依赖包
aider-install
安装ollama对应的环境变量
python -m pip install -U aider-chat
export OLLAMA_API_BASE=http://127.0.0.1:11434 # Mac/Linux
设置启动aider使用的模型
在启动aider时指定使用的模型。我这里使用ollama中的Qwen2.5:7b这个本地模型。
aider --model ollama_chat/Qwen2.5:7b
# 或者
aider --model ollama_chat/deepseek-r1:8b
配置文件
若不指定配置文件,则会使用默认的配置项。可以从这里下载配置文件样例:样例配置文件。可以通过以下参数来指定配置文件:
aider --config .aider.conf.yml
环境变量文件:可以通过.env来指定环境变量。并通过以下命令来指定环境变量文件。环境变量的设置样例文件在这里下载。
aider --env .env
启动并使用
我这里并没有配置.env和aider.conf配置文件,使用默认配置,但指定了ollama的地址,所以我写了一个启动的shell脚本:start_aider.sh,可以直接启动aider:
export OLLAMA_API_BASE=http://127.0.0.1:11434
aider --model ollama_chat/Qwen2.5:7b "$1"
启动后是一个命令行,可以有多种命令,比如:/add,/chat-mod等。
一般来说启动时我要设置一个或多个文件名,这样才能对这些文件进行读取和处理,我这里直接给它指令:
$ start_aider.sh "snake.py"
> 请帮我写一个贪吃蛇的游戏
好的,我将为您编写一个简单的贪吃蛇游戏。我们将创建一个新的文件 snak.py 来实现这个游戏。
...
...
# 这里是很多代码的输出
...
这个简单的贪吃蛇游戏包含了一个 Snake 类来表示蛇,一个 Food 类来表示食物,以及一个 Game
类来管理游戏逻辑。游戏通过控制台输入方向来移动蛇,并在吃到食物时生成新的食物位置。当蛇撞到自己或边界时,游戏结束。
Tokens: 1.0k sent, 701 received.
Committing snake_v3.py before applying edits.
Commit b6bfdbb feat: add snake.py
Applied edit to snake.py
Commit 73aabf9 feat: 添加贪吃蛇游戏实现
You can use /undo to undo and discard each aider commit.
aider会把游戏的代码写到snake.py这个文件中。若有语法错误,还会给你检查并提示你是否需要修改。
使用deepseek-r1来分析一个代码仓库
我下载了一个2048游戏仓库的代码,保存到2048文件夹中。然后通过aider来分析该代码。整个过程如下:
$ cd /work/aider/aider_lab/2048
$ aider --model ollama_chat/deepseek-r1:8b
────────────────────────────────────────────────────────────────────────────────────────────────
You can skip this check with --no-gitignore
Add .aider* to .gitignore (recommended)? (Y)es/(N)o [Yes]: n
Aider v0.74.2
Model: ollama_chat/deepseek-r1:8b with diff edit format
Git repo: .git with 34 files
Repo-map: using 4096 tokens, auto refresh
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> /ls
Repo files not in the chat:
.gitignore
.jshintrc
CONTRIBUTING.md
LICENSE.txt
README.md
Rakefile
favicon.ico
index.html
js/animframe_polyfill.js
js/application.js
js/bind_polyfill.js
js/classlist_polyfill.js
js/game_manager.js
js/grid.js
js/html_actuator.js
js/keyboard_input_manager.js
js/local_storage_manager.js
js/tile.js
meta/apple-touch-icon.png
meta/apple-touch-startup-image-640x1096.png
meta/apple-touch-startup-image-640x920.png
style/fonts/ClearSans-Bold-webfont.eot
style/fonts/ClearSans-Bold-webfont.svg
style/fonts/ClearSans-Bold-webfont.woff
style/fonts/ClearSans-Light-webfont.eot
style/fonts/ClearSans-Light-webfont.svg
style/fonts/ClearSans-Light-webfont.woff
style/fonts/ClearSans-Regular-webfont.eot
style/fonts/ClearSans-Regular-webfont.svg
style/fonts/ClearSans-Regular-webfont.woff
style/fonts/clear-sans.css
style/helpers.scss
style/main.css
style/main.scss
────────────────────────────────────────────────────────────────────────────────────────────────
# 开始提问
> what is this repo?
Looking at the files, it seems like it's a JavaScript game project. There are directories like js, style, meta, and others,
which typically make up a web app. The presence of game-related files (like Tile.js, Grid.js) indicates this is probably a
puzzle or matching game, given the tile movements and scoring mechanics mentioned in the code.
The user also included various polyfills for JavaScript features, like classList and requestAnimationFrame, which are common in
older browser compatibility projects. This tells me the project might be targeting older browsers that don't support these
features natively.
They have a LocalStorageManager and a KeyboardInputManager, which are essential for handling game state and user input. The
HTMLActuator suggests they're using DOM elements to display the game, with tiles being created as divs in the DOM.
The style files include SCSS and CSS, so they're using a preprocessor on the frontend side. The presence of webfonts and icons
also points towards a polished web app.
Considering all this, the repo is likely a single-page web application built with HTML, JavaScript, and CSS, focusing on a
tile-matching game with features like score tracking, best scores, and basic animations.
I should break down the structure into key components to help the user understand their project better. I'll list out the
directories and the main files each handles, providing a clear overview without making any changes.
Based on the files shown, this appears to be a JavaScript game development project that likely focuses on a tile-matching or
puzzle-type game. Let me analyze the structure:
Key directories and their purposes:
1 js/:
• Contains core game logic modules like application.js, game_manager.js, grid.js, etc.
• Has polyfills for browser APIs like requestAnimationFrame, classList, etc.
2 style/:
• Contains CSS stylesheets and SCSS files
• Includes font definitions and UI-related styling
3 meta/:
• Contains apple-touch-icon and startup image files
• Indicates this is a web app with native touch support
4 js/storage/:
• Contains LocalStorageManager implementation
• Manages game state and scores
5 js/tile/:
• Core tile class that seems to handle movement and merging logic
6 js/html_actuator/:
• Handles DOM updates for rendering tiles
• Includes animation frame management
7 Other files:
• Various configuration files like .gitignore, LICENSE, etc.
• Font files in the style directory
• HTML file at index.html
The most likely files that would need changes based on common requests include:
1 js/game_manager.js: Core game logic and state management
2 style/main.scss: Global styles for the app
3 js/html_actuator.js: DOM rendering and animations
4 js/local_storage_manager.js: Game progress persistence
Would you like me to proceed with any specific changes to these files or other parts of your project?
Tokens: 6.2k sent, 673 received.
.gitignore
Add file to the chat? (Y)es/(N)o/(A)ll/(S)kip all/(D)on't ask again [Yes]: n
index.html
Add file to the chat? (Y)es/(N)o/(A)ll/(S)kip all/(D)on't ask again [Yes]: n
可以看到,aider能够分析代码仓库的结构。
总结
本文是aider的一个初步尝试,可以看到aider还是比较强大和智能。但也存在一些缺陷,比如:再多多个文件进行代码分析是有时会有问题。另外,当代码的长度太长时,会有token的限制。这里也是ai coder需要解决的难点:如何在有限token的情况下,保证答案的质量。
另外,不同推理大模型的表现也不同,可以通过这种方式来配置不同的大模型。
参考资料
- 样例配置文件:https://github.com/Aider-AI/aider/blob/main/aider/website/assets/sample.aider.conf.yml
- https://aider.chat/