mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 01:04:59 +00:00

# Context: USER: we need to pass those into InputOutput and to prompt_toolkit right? ASSISTANT: Yes, you're right. We need to pass the `input` and `output` arguments to the `InputOutput` class and then to the `prompt_toolkit.prompt()` function. Here's how to modify the `aider/getinput.py` and `aider/main.py` files: In `aider/getinput.py`, update the `InputOutput` class to accept `input` and `output` arguments: ```python aider/getinput.py <<<<<<< ORIGINAL class InputOutput: def __init__(self, pretty, yes, input_history_file, chat_history_file): ======= class InputOutput: def __init__(self, pretty, yes, input_history_file, chat_history_file, input=None, output=None): self.input = input self.output = output >>>>>>> UPDATED ``` Now, update the `prompt()` function calls in the `get_input()` method to use the `input` and `output` arguments: ```python aider/getinput.py <<<<<<< ORIGINAL line = prompt( show, completer=completer_instance, history=FileHistory(self.input_history_file), style=style, reserve_space_for_menu=4, complete_style=CompleteStyle.MULTI_COLUMN, ) ======= line = prompt( show, completer=completer_instance, history=FileHistory(self.input_history_file), style=style, reserve_space_for_menu=4, complete_style=CompleteStyle.MULTI_COLUMN, input=self.input, output=self.output, ) >>>>>>> UPDATED ``` In `aider/main.py`, pass the `input` and `output` arguments to the `InputOutput` class: ```python aider/main.py <<<<<<< ORIGINAL io = InputOutput(args.pretty, args.yes, args.input_history_file, args.chat_history_file) ======= io = InputOutput(args.pretty, args.yes, args.input_history_file, args.chat_history_file, input=input, output=output) >>>>>>> UPDATED ``` These changes will ensure that the `input` and `output` arguments are passed to the `InputOutput` class and then to the `prompt_toolkit.prompt()` function.
109 lines
3.4 KiB
Python
109 lines
3.4 KiB
Python
import os
|
|
import sys
|
|
import argparse
|
|
from dotenv import load_dotenv
|
|
from aider.coder import Coder
|
|
from aider.getinput import InputOutput
|
|
|
|
def main(args=None, input=None, output=None):
|
|
if args is None:
|
|
args = sys.argv[1:]
|
|
if input is None:
|
|
input = sys.stdin
|
|
if output is None:
|
|
output = sys.stdout
|
|
|
|
load_dotenv()
|
|
env_prefix = "AIDER_"
|
|
parser = argparse.ArgumentParser(description="aider - chat with GPT about your code")
|
|
parser.add_argument(
|
|
"files",
|
|
metavar="FILE",
|
|
nargs="*",
|
|
help="a list of source code files (optional)",
|
|
)
|
|
parser.add_argument(
|
|
"--input-history-file",
|
|
metavar="INPUT_HISTORY_FILE",
|
|
default=os.environ.get(f"{env_prefix}INPUT_HISTORY_FILE", ".aider.input.history"),
|
|
help=(
|
|
"Specify the chat input history file (default: .aider.input.history,"
|
|
f" ${env_prefix}INPUT_HISTORY_FILE)"
|
|
),
|
|
)
|
|
parser.add_argument(
|
|
"--chat-history-file",
|
|
metavar="CHAT_HISTORY_FILE",
|
|
default=os.environ.get(f"{env_prefix}CHAT_HISTORY_FILE", ".aider.chat.history.md"),
|
|
help=(
|
|
"Specify the chat history file (default: .aider.chat.history.md,"
|
|
f" ${env_prefix}CHAT_HISTORY_FILE)"
|
|
),
|
|
)
|
|
parser.add_argument(
|
|
"--model",
|
|
metavar="MODEL",
|
|
default=os.environ.get(f"{env_prefix}MODEL", "gpt-4"),
|
|
help=f"Specify the model to use for the main chat (default: gpt-4, ${env_prefix}MODEL)",
|
|
)
|
|
parser.add_argument(
|
|
"-3",
|
|
action="store_const",
|
|
dest="model",
|
|
const="gpt-3.5-turbo",
|
|
help="Use gpt-3.5-turbo model for the main chat (basically won't work)",
|
|
)
|
|
parser.add_argument(
|
|
"--no-pretty",
|
|
action="store_false",
|
|
dest="pretty",
|
|
help=f"Disable pretty, colorized output (${env_prefix}PRETTY)",
|
|
default=bool(int(os.environ.get(f"{env_prefix}PRETTY", 1))),
|
|
)
|
|
parser.add_argument(
|
|
"--apply",
|
|
metavar="FILE",
|
|
help="Apply the changes from the given file instead of running the chat (debug)",
|
|
)
|
|
parser.add_argument(
|
|
"--no-auto-commits",
|
|
action="store_false",
|
|
dest="auto_commits",
|
|
help=f"Disable auto commit of changes (${env_prefix}AUTO_COMMITS)",
|
|
default=bool(int(os.environ.get(f"{env_prefix}AUTO_COMMITS", 1))),
|
|
)
|
|
parser.add_argument(
|
|
"--show-diffs",
|
|
action="store_true",
|
|
help=f"Show diffs when committing changes (default: False, ${env_prefix}SHOW_DIFFS)",
|
|
default=bool(int(os.environ.get(f"{env_prefix}SHOW_DIFFS", 0))),
|
|
)
|
|
parser.add_argument(
|
|
"--yes",
|
|
action="store_true",
|
|
help="Always say yes to every confirmation",
|
|
default=False,
|
|
)
|
|
args = parser.parse_args(args)
|
|
fnames = args.files
|
|
pretty = args.pretty
|
|
|
|
io = InputOutput(args.pretty, args.yes, args.input_history_file, args.chat_history_file, input=input, output=output)
|
|
|
|
coder = Coder(
|
|
args.model, fnames, pretty, args.show_diffs, args.auto_commits, io,
|
|
)
|
|
coder.commit(ask=True, prefix="wip: ", which="repo_files")
|
|
|
|
if args.apply:
|
|
with open(args.apply, "r") as f:
|
|
content = f.read()
|
|
coder.update_files(content, inp="")
|
|
return
|
|
|
|
coder.run()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
status = main()
|
|
sys.exit(status)
|