Skip to content

Commit

Permalink
added scripting docs
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-gauthier committed Nov 3, 2023
1 parent 1fe48fd commit 51425fa
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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)
```

0 comments on commit 51425fa

Please sign in to comment.