From 51425faff6d76e142577b309f992c3ee4d749247 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 3 Nov 2023 14:24:33 -0700 Subject: [PATCH] added scripting docs --- docs/faq.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index e429e4d56..20d41f02b 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -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) +```