added scripting docs

This commit is contained in:
Paul Gauthier 2023-11-03 14:24:33 -07:00
parent 1fe48fd161
commit 51425faff6

View file

@ -9,6 +9,7 @@
- [Can I change the system prompts that aider uses?](#can-i-change-the-system-prompts-that-aider-uses)
- [Can I run aider in Google Colab?](#can-i-run-aider-in-google-colab)
- [How can I run aider locally from source code?](#how-can-i-run-aider-locally-from-source-code)
- [Can I script aider?](#can-i-script-aider)
## How does aider use git?
@ -244,3 +245,48 @@ pip install -r requirements.txt
# Run the local version of Aider:
python -m aider.main
```
# Can I script aider?
You can script aider via the command line or python.
## Command line
Aider takes a `--message` argument, where you can give it a natural language instruction.
It will do that one thing, apply the edits to the files and then exit.
So you could do:
```bash
aider --message "make a script that prints hello" hello.js
```
Or you can write simple shell scripts to apply the same instruction to many files:
```bash
for FILE in *.py ; do
aider --message "add descriptive docstrings to all the functions" $FILE
done
```
## Python
You can also script aider from python:
```python
from aider.io import InputOutput
from aider.coders import Coder
from aider.models import GPT4
# This is a list of files to add to the chat
fnames = ['foo.py']
# This is the instruction to give to GPT
message = 'make a script that prints hello world!'
io = InputOutput()
coder = Coder.create(GPT4, None, io, fnames=fnames)
# This will execute that one instruction on those files and then return
coder.run(with_message=message)
```