From e2c2f0c2b9517266e779f33b66be149985f68dfe Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 9 May 2023 00:11:45 -0700 Subject: [PATCH] Initial commit: Added new files to the git repo. --- main.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 000000000..7be62510e --- /dev/null +++ b/main.py @@ -0,0 +1,80 @@ +import os +import sys +import argparse +from pathlib import Path +from dotenv import load_dotenv +from coder import Coder + +def main(): + load_dotenv() + env_prefix = "CODER_" + parser = argparse.ArgumentParser(description="Chat with GPT about code") + parser.add_argument( + "files", + metavar="FILE", + nargs="+", + help="a list of source code files", + ) + parser.add_argument( + "--history-file", + metavar="HISTORY_FILE", + default=os.environ.get("CODER_HISTORY_FILE", ".coder.history"), + help="Specify the history file (default: .coder.history or value from CODER_HISTORY_FILE environment variable)", + ) + parser.add_argument( + "--model", + metavar="MODEL", + default="gpt-4", + help="Specify the model to use for the main chat (default: gpt-4)", + ) + 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", + ) + parser.add_argument( + "-4", + action="store_const", + dest="model", + const="gpt-4", + help="Use gpt-4 model for the main chat", + ) + parser.add_argument( + "--no-pretty", + action="store_false", + dest="pretty", + help="Disable prettyd output of GPT responses", + default=bool(int(os.environ.get(env_prefix + "PRETTY", 1))), + ) + parser.add_argument( + "--apply", + metavar="FILE", + help="Apply the changes from the given file instead of running the chat", + ) + parser.add_argument( + "--commit-dirty", + action="store_true", + help="Commit dirty files without confirmation", + default=bool(int(os.environ.get(env_prefix + "COMMIT_DIRTY", 0))), + ) + args = parser.parse_args() + + fnames = args.files + pretty = args.pretty + + coder = Coder(args.model, fnames, pretty, args.history_file) + coder.commit(ask=not args.commit_dirty, prefix="WIP: ") + + 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)