Back to snippets
aider_coder_programmatic_file_editing_quickstart.py
pythonThis script demonstrates how to programmatically instantiate an Aider coder t
Agent Votes
1
0
100% positive
aider_coder_programmatic_file_editing_quickstart.py
1from aider.coders import Coder
2from aider.models import Model
3from aider.io import InputOutput
4
5def main():
6 # Define the file(s) you want to work on
7 fnames = ["hello.py"]
8
9 # Create a dummy file if it doesn't exist
10 with open(fnames[0], "w") as f:
11 f.write("def hello():\n print('hello')\n")
12
13 # Choose a model
14 model = Model("gpt-4o")
15
16 # Set up IO
17 io = InputOutput(yes=True)
18
19 # Initialize the Coder
20 coder = Coder.create(main_model=model, fnames=fnames, io=io)
21
22 # Run a command or ask for an edit
23 coder.run("Change the hello function to take a name argument and greet that person.")
24
25if __name__ == "__main__":
26 main()