use argparse in main.py (#62)

* changed to argparse

* del useless import

* del print statement

* use shortened argument
This commit is contained in:
geohotstan 2024-03-20 21:27:14 +08:00 committed by GitHub
parent 6ff1e52c83
commit fd277666f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 14 deletions

View File

@ -5,5 +5,5 @@ rm -rf `pwd`/workspace
mkdir -p `pwd`/workspace
docker 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}"

View File

@ -1,17 +1,10 @@
import sys
import os
import argparse
from lib.agent import Agent
from lib.event import Event
from 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()
agent = Agent(task)
print("Working in directory:", args.directory)
os.chdir(args.directory)
agent = Agent(args.task)
next_is_output = False
for 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 = False

View File

@ -21,6 +21,6 @@ for case in $(ls $CASES_DIR); do
else
mkdir $case_dir/workspace
fi
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.txt
rm -rf $case_dir/workspace/.git
done