forked from agiresearch/AIOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
93 lines (69 loc) · 2.44 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import sys
import json
from src.scheduler.fifo_scheduler import FIFOScheduler
from src.scheduler.rr_scheduler import RRScheduler
from src.utils.utils import (
parse_global_args,
)
from src.agents.agent_factory import AgentFactory
from src.agents.agent_process import AgentProcessFactory
import warnings
from src.llm_kernel import llms
from concurrent.futures import ThreadPoolExecutor, as_completed
def main():
warnings.filterwarnings("ignore")
parser = parse_global_args()
args = parser.parse_args()
llm_name = args.llm_name
max_gpu_memory = args.max_gpu_memory
eval_device = args.eval_device
max_new_tokens = args.max_new_tokens
scheduler_log_mode = args.scheduler_log_mode
agent_log_mode = args.agent_log_mode
llm = llms.LLMKernel(
llm_name,
max_gpu_memory,
eval_device,
max_new_tokens
)
# start the scheduler
# scheduler = FIFOScheduler(
# llm = llm,
# log_mode = scheduler_log_mode
# )
scheduler = RRScheduler(
llm = llm,
log_mode = scheduler_log_mode
)
agent_process_factory = AgentProcessFactory()
agent_factory = AgentFactory(
llm = llm,
agent_process_queue = scheduler.agent_process_queue,
agent_process_factory = agent_process_factory,
agent_log_mode = agent_log_mode
)
agent_thread_pool = ThreadPoolExecutor(max_workers=64)
scheduler.start()
# construct agents
math_agent = agent_thread_pool.submit(
agent_factory.run_agent,
"MathAgent",
"Solve the problem that Albert is wondering how much pizza he can eat in one day. He buys 2 large pizzas and 2 small pizzas. A large pizza has 16 slices and a small pizza has 8 slices. If he eats it all, how many pieces does he eat that day?"
)
narrative_agent = agent_thread_pool.submit(
agent_factory.run_agent,
"NarrativeAgent",
"Craft a tale about a valiant warrior on a quest to uncover priceless treasures hidden within a mystical island."
)
rec_agent = agent_thread_pool.submit(
agent_factory.run_agent,
"RecAgent", "I want to take a tour to New York during the spring break, recommend some restaurants around for me."
)
agent_tasks = [math_agent, narrative_agent, rec_agent]
# agent_tasks = [math_agent]
for r in as_completed(agent_tasks):
res = r.result()
scheduler.stop()
if __name__ == "__main__":
main()