Spaces:
Runtime error
Runtime error
Commit
·
7b262a7
1
Parent(s):
1929d8a
first commit
Browse files
agentverse_command/__init__.py
ADDED
|
File without changes
|
agentverse_command/benchmark.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
import shutil
|
| 5 |
+
|
| 6 |
+
# from agentverse.agentverse import AgentVerse
|
| 7 |
+
from agentverse.tasksolving import TaskSolving
|
| 8 |
+
from agentverse.logging import get_logger
|
| 9 |
+
from argparse import ArgumentParser
|
| 10 |
+
import asyncio
|
| 11 |
+
from dataloader import dataloader_registry
|
| 12 |
+
|
| 13 |
+
parser = ArgumentParser()
|
| 14 |
+
|
| 15 |
+
parser.add_argument("--task", type=str, default="tasksolving/responsegen")
|
| 16 |
+
parser.add_argument(
|
| 17 |
+
"--tasks_dir",
|
| 18 |
+
type=str,
|
| 19 |
+
default=os.path.join(os.path.dirname(__file__), "..", "agentverse", "tasks"),
|
| 20 |
+
)
|
| 21 |
+
parser.add_argument("--dataset_path", type=str, required=True)
|
| 22 |
+
parser.add_argument("--output_path", type=str, default=None)
|
| 23 |
+
parser.add_argument("--has_tools", action="store_true")
|
| 24 |
+
parser.add_argument("--tool_tmp_path", type=str)
|
| 25 |
+
parser.add_argument("--overwrite", action="store_true")
|
| 26 |
+
parser.add_argument("--debug", action="store_true")
|
| 27 |
+
args = parser.parse_args()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
logger = get_logger()
|
| 31 |
+
logger.set_level(logging.DEBUG if args.debug else logging.INFO)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def get_dataloader(task, dataset_path):
|
| 35 |
+
return dataloader_registry.build(task, path=dataset_path)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def cli_main():
|
| 39 |
+
dataloader = get_dataloader(args.task, args.dataset_path)
|
| 40 |
+
if args.output_path is None:
|
| 41 |
+
os.makedirs(f"./results/{args.task}", exist_ok=True)
|
| 42 |
+
args.output_path = f"./results/{args.task}"
|
| 43 |
+
else:
|
| 44 |
+
os.makedirs(args.output_path, exist_ok=True)
|
| 45 |
+
shutil.copyfile(
|
| 46 |
+
f"{args.tasks_dir}/{args.task}/config.yaml",
|
| 47 |
+
f"{args.output_path}/config.yaml",
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
skip_cnt = 0
|
| 51 |
+
if not args.overwrite and os.path.exists(f"{args.output_path}/results.jsonl"):
|
| 52 |
+
with open(f"{args.output_path}/results.jsonl", "r") as f:
|
| 53 |
+
for line in f:
|
| 54 |
+
if line.strip():
|
| 55 |
+
skip_cnt += 1
|
| 56 |
+
f = open(f"{args.output_path}/results.jsonl", "w" if args.overwrite else "a")
|
| 57 |
+
for i, example in enumerate(dataloader):
|
| 58 |
+
if i < skip_cnt:
|
| 59 |
+
continue
|
| 60 |
+
logger.info(f"Input: {example['input']}\nAnswer: {example['answer']}")
|
| 61 |
+
if args.has_tools:
|
| 62 |
+
assert args.tool_tmp_path is not None
|
| 63 |
+
with open(args.tool_tmp_path, "w") as f:
|
| 64 |
+
f.write(json.dumps(example["tools"]))
|
| 65 |
+
agentverse = TaskSolving.from_task(args.task, args.tasks_dir)
|
| 66 |
+
agentverse.environment.set_task_description(example["input"])
|
| 67 |
+
# print(args.single_agent)
|
| 68 |
+
# print(args.discussion_mode)
|
| 69 |
+
# exit()
|
| 70 |
+
plan, result, logs = agentverse.run()
|
| 71 |
+
f.write(
|
| 72 |
+
json.dumps(
|
| 73 |
+
{
|
| 74 |
+
"input": example["input"],
|
| 75 |
+
"response": plan,
|
| 76 |
+
"label": example["answer"],
|
| 77 |
+
"logs": logs,
|
| 78 |
+
}
|
| 79 |
+
)
|
| 80 |
+
+ "\n"
|
| 81 |
+
)
|
| 82 |
+
f.flush()
|
| 83 |
+
f.close()
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
cli_main()
|
agentverse_command/main_simulation_cli.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import logging
|
| 3 |
+
from argparse import ArgumentParser
|
| 4 |
+
|
| 5 |
+
from agentverse.logging import logger
|
| 6 |
+
from agentverse.simulation import Simulation
|
| 7 |
+
|
| 8 |
+
parser = ArgumentParser()
|
| 9 |
+
parser.add_argument("--task", type=str, default="simulation/prisoner_dilemma")
|
| 10 |
+
parser.add_argument(
|
| 11 |
+
"--tasks_dir",
|
| 12 |
+
type=str,
|
| 13 |
+
default=os.path.join(os.path.dirname(__file__), "..", "agentverse", "tasks"),
|
| 14 |
+
)
|
| 15 |
+
parser.add_argument("--debug", action="store_true")
|
| 16 |
+
args = parser.parse_args()
|
| 17 |
+
|
| 18 |
+
logger.set_level(logging.DEBUG if args.debug else logging.INFO)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def cli_main():
|
| 22 |
+
agentverse = Simulation.from_task(args.task, args.tasks_dir)
|
| 23 |
+
agentverse.run()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
cli_main()
|
agentverse_command/main_simulation_gui.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from agentverse.gui import GUI
|
| 3 |
+
from argparse import ArgumentParser
|
| 4 |
+
|
| 5 |
+
parser = ArgumentParser()
|
| 6 |
+
parser.add_argument("--task", type=str, default="simulation/nlp_classroom_9players")
|
| 7 |
+
parser.add_argument(
|
| 8 |
+
"--tasks_dir",
|
| 9 |
+
type=str,
|
| 10 |
+
default=os.path.join(os.path.dirname(__file__), "..", "agentverse", "tasks"),
|
| 11 |
+
)
|
| 12 |
+
args = parser.parse_args()
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def cli_main():
|
| 16 |
+
ui = GUI(args.task, args.tasks_dir)
|
| 17 |
+
ui.launch()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
cli_main()
|
agentverse_command/main_tasksolving_cli.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import logging
|
| 3 |
+
|
| 4 |
+
# from agentverse.agentverse import AgentVerse
|
| 5 |
+
from agentverse.tasksolving import TaskSolving
|
| 6 |
+
from agentverse.gui import GUI
|
| 7 |
+
from agentverse.logging import logger
|
| 8 |
+
from argparse import ArgumentParser
|
| 9 |
+
|
| 10 |
+
parser = ArgumentParser()
|
| 11 |
+
|
| 12 |
+
parser.add_argument(
|
| 13 |
+
"--task",
|
| 14 |
+
type=str,
|
| 15 |
+
default="tasksolving/brainstorming",
|
| 16 |
+
)
|
| 17 |
+
parser.add_argument("--debug", action="store_true")
|
| 18 |
+
parser.add_argument(
|
| 19 |
+
"--tasks_dir",
|
| 20 |
+
type=str,
|
| 21 |
+
default=os.path.join(os.path.dirname(__file__), "..", "agentverse", "tasks"),
|
| 22 |
+
)
|
| 23 |
+
args = parser.parse_args()
|
| 24 |
+
|
| 25 |
+
logger.set_level(logging.DEBUG if args.debug else logging.INFO)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def cli_main():
|
| 29 |
+
agentversepipeline = TaskSolving.from_task(args.task, args.tasks_dir)
|
| 30 |
+
agentversepipeline.run()
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
cli_main()
|