-
Notifications
You must be signed in to change notification settings - Fork 25
/
Groupchat.py
85 lines (71 loc) · 2.82 KB
/
Groupchat.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
import sys
import os
base_dir = os.path.dirname(os.path.abspath(__file__))
venv_site_packages = os.path.join(base_dir, 'venv', 'Lib', 'site-packages')
sys.path.append(venv_site_packages)
try:
import autogen
except ImportError:
import sys
import os
# Determine the correct path based on the operating system
if os.name == 'posix':
site_packages = os.path.join(sys.prefix, 'lib', 'python{}.{}/site-packages'.format(sys.version_info.major, sys.version_info.minor))
else: # For Windows
site_packages = os.path.join(sys.prefix, 'Lib', 'site-packages')
sys.path.append(site_packages)
import autogen
class GroupChat:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"LLM": ("LLM",),
"User": ("User",),
"Agent": ("Agent",),
"Agent2": ("Agent",)
},
"optional": {
"Agent3": ("Agent",),
"Agent4": ("Agent",),
"Agent5": ("Agent",),
"max_round": ("INT", {"default": 50}),
"Seed": ("INT", {"default": "42"}),
"Temp": ("INT", {"default": "0"}),
"request_timeout": ("INT", {"default": 120})
}
}
RETURN_TYPES = ("Agent",)
FUNCTION = "execute"
CATEGORY = "AutoGen"
def execute(self, LLM, User, Agent, Agent2, Seed, Temp, request_timeout, Agent3=None, Agent4=None, Agent5=None, max_round=50):
Agents = [User['User']]
# Function to handle agent input
def handle_agent_input(agent_input):
if agent_input:
if isinstance(agent_input['Agent'], list):
Agents.extend(agent_input['Agent'])
else:
Agents.append(agent_input['Agent'])
# Handle each agent input
handle_agent_input(Agent)
handle_agent_input(Agent2)
handle_agent_input(Agent3)
handle_agent_input(Agent4)
handle_agent_input(Agent5)
groupchat = autogen.GroupChat(agents=Agents, messages=[],
max_round=max_round)
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config={ #THIS has to be HERE for some reason??!!?!
"seed": Seed, # seed for caching and reproducibility
"config_list": LLM['LLM'], # a list of OpenAI API configurations
"temperature": Temp, # temperature for sampling
"timeout": request_timeout,
}, # configuration for autogen's enhanced inference API which is compatible with OpenAI API
)
return ({"Agent": manager},)
NODE_CLASS_MAPPINGS = {
"GroupChat": GroupChat,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"GroupChat": "GroupChat with Manager"
}