|
|
|
|
|
|
|
|
import asyncio |
|
|
import argparse |
|
|
import sys |
|
|
import signal |
|
|
import re |
|
|
import logging |
|
|
from autoagents.roles import Manager, ObserverAgents, ObserverPlans |
|
|
from autoagents.explorer import Explorer |
|
|
import startup |
|
|
import cfg |
|
|
import ws_service |
|
|
|
|
|
|
|
|
|
|
|
from autoagents.system.logs import logger |
|
|
import json |
|
|
import os |
|
|
|
|
|
def signal_handler(signal, frame): |
|
|
sys.exit(1) |
|
|
|
|
|
async def commanline(investment: float = 10.0, n_round: int = 3, proxy: str = None, llm_api_key: str = None, serpapi_key: str=None, idea: str=None): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open(args.input_file, 'r') as f: |
|
|
tasks = [json.loads(line.strip()) for line in f] |
|
|
|
|
|
finished_tasks = [] |
|
|
if os.path.exists(args.output_file): |
|
|
with open(args.output_file, 'r') as f: |
|
|
finished_tasks = [json.loads(line.strip())['id'] for line in f] |
|
|
|
|
|
cfg.OUTPUT_FILE = args.output_file |
|
|
|
|
|
for task in tasks: |
|
|
if task['id'] in finished_tasks: |
|
|
logger.info(f"######################### Task {task['id']} already finished, skip. #########################") |
|
|
continue |
|
|
logger.info(f"######################### Starting task {task['id']}: {task['question']} #########################") |
|
|
cfg.TASK_ID = task['id'] |
|
|
await startup.startup(task['question'], investment, n_round, llm_api_key=llm_api_key, serpapi_key=serpapi_key, proxy=proxy) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
signal.signal(signal.SIGINT, signal_handler) |
|
|
|
|
|
parser = argparse.ArgumentParser(description="AutoAgents") |
|
|
|
|
|
parser.add_argument("--proxy", default=None, type=str, help="http proxy, example: http://127.0.0.1:8080") |
|
|
parser.add_argument("--llm_api_key", default=None, type=str, help="OpenAI API key") |
|
|
parser.add_argument("--serpapi_key", default=None, type=str, help="SerpAPI key") |
|
|
parser.add_argument("--input_file", default=None, type=str, help="Input file with tasks in JSONL format") |
|
|
parser.add_argument("--output_file", default=None, type=str, help="output file with tasks in JSONL format") |
|
|
args = parser.parse_args() |
|
|
|
|
|
proxy = None |
|
|
proxy_regex = r'(http|https|socks|socks5):\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{2,5}' |
|
|
if args.proxy and re.match(proxy_regex, args.proxy): |
|
|
proxy = args.proxy |
|
|
|
|
|
asyncio.run(commanline(proxy=proxy, llm_api_key=args.llm_api_key, serpapi_key=args.serpapi_key)) |
|
|
|