π OpenHands: AI-Driven Development
use argparse in main.py (#62)
geohotstanfd277666f686
diff --git a/agent/build-and-run.sh b/agent/build-and-run.shindex f2fe4e76ff..8e29d82025 100755--- a/agent/build-and-run.sh+++ b/agent/build-and-run.sh@@ -5,5 +5,5 @@ rm -rf `pwd`/workspacemkdir -p `pwd`/workspacedocker build -t control-loop .-docker run -e DEBUG=$DEBUG -e OPENAI_API_KEY=$OPENAI_API_KEY -v `pwd`/workspace:/workspace control-loop python /app/main.py /workspace "${1}"+docker run -e DEBUG=$DEBUG -e OPENAI_API_KEY=$OPENAI_API_KEY -v `pwd`/workspace:/workspace control-loop python /app/main.py -d /workspace -t "${1}"diff --git a/agent/main.py b/agent/main.pyindex 0f66c49ee0..a8c34f92ef 100644--- a/agent/main.py+++ b/agent/main.py@@ -1,17 +1,10 @@-import sysimport os+import argparsefrom lib.agent import Agentfrom lib.event import Eventfrom lib.controlloop import run_loop-if len(sys.argv) < 3:- print("Usage: python main.py <working_directory> <task>")- sys.exit(1)--working_directory = sys.argv[1]-task = sys.argv[2]-INITIAL_THOUGHTS = ["I exist!","Hmm...looks like I can type in a command line prompt",@@ -51,13 +44,18 @@ INITIAL_THOUGHTS = []def main():- print("Working in directory:", sys.argv[1])- os.chdir(working_directory)+ parser = argparse.ArgumentParser(description="Run an agent with a specific task")+ parser.add_argument("-d", "--directory", required=True, type=str, help="The working directory for the agent")+ parser.add_argument("-t", "--task", required=True, type=str, help="The task for the agent to perform")+ args = parser.parse_args()++ print("Working in directory:", args.directory)+ os.chdir(args.directory)- agent = Agent(task)+ agent = Agent(args.task)next_is_output = Falsefor thought in INITIAL_THOUGHTS:- thought = thought.replace("$TASK", task)+ thought = thought.replace("$TASK", args.task)if next_is_output:event = Event('output', {'output': thought})next_is_output = Falsediff --git a/agent/regression/run.sh b/agent/regression/run.shindex dd2b74cb22..715f2a65eb 100755--- a/agent/regression/run.sh+++ b/agent/regression/run.sh@@ -21,6 +21,6 @@ for case in $(ls $CASES_DIR); doelsemkdir $case_dir/workspacefi- docker run -e DEBUG=$DEBUG -e OPENAI_API_KEY=$OPENAI_API_KEY -v $case_dir/workspace:/workspace control-loop python /app/main.py /workspace "${task}" | tee $case_dir/logs.txt+ docker run -e DEBUG=$DEBUG -e OPENAI_API_KEY=$OPENAI_API_KEY -v $case_dir/workspace:/workspace control-loop python /app/main.py -d /workspace -t "${task}" | tee $case_dir/logs.txtrm -rf $case_dir/workspace/.gitdone