mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
use argparse in main.py (#62)
* changed to argparse * del useless import * del print statement * use shortened argument
This commit is contained in:
parent
6ff1e52c83
commit
fd277666f6
@ -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}"
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user