-
Notifications
You must be signed in to change notification settings - Fork 0
/
91_group_chat_arithmetic_operations.py
83 lines (71 loc) · 3.06 KB
/
91_group_chat_arithmetic_operations.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
import os
from dotenv import load_dotenv
from autogen import ConversableAgent, GroupChat, GroupChatManager
load_dotenv()
# For some reason I need proxyman running and OPENAI_BASE_URL set to http://localhost:10800/v1 for this to work 🤷♂️
llm_config = {
'model': 'gpt-4',
'api_key': os.getenv('OPENAI_API_KEY'),
'base_url': os.getenv('OPENAI_BASE_URL') if os.getenv('OPENAI_BASE_URL') else None,
}
# The Number Agent always returns the same numbers.
number_agent = ConversableAgent(
name="Number_Agent",
# GroupChatManager uses description to select the next agent when selection strategy is 'auto' (the default)
description="Return the numbers given.",
system_message="You return me the numbers I give you, one number each line.",
llm_config=llm_config,
human_input_mode="NEVER",
)
# The Adder Agent adds 1 to each number it receives.
adder_agent = ConversableAgent(
name="Adder_Agent",
# GroupChatManager uses description to select the next agent when selection strategy is 'auto' (the default)
description="Add 1 to each input number.",
system_message="You add 1 to each number I give you and return me the new numbers, one number each line.",
llm_config=llm_config,
human_input_mode="NEVER",
)
# The Multiplier Agent multiplies each number it receives by 2.
multiplier_agent = ConversableAgent(
name="Multiplier_Agent",
# GroupChatManager uses description to select the next agent when selection strategy is 'auto' (the default)
description="Multiply each input number by 2.",
system_message="You multiply each number I give you by 2 and return me the new numbers, one number each line.",
llm_config=llm_config,
human_input_mode="NEVER",
)
# The Subtracter Agent subtracts 1 from each number it receives.
subtracter_agent = ConversableAgent(
name="Subtracter_Agent",
# GroupChatManager uses description to select the next agent when selection strategy is 'auto' (the default)
description="Subtract 1 from each input number.",
system_message="You subtract 1 from each number I give you and return me the new numbers, one number each line.",
llm_config=llm_config,
human_input_mode="NEVER",
)
# The Divider Agent divides each number it receives by 2.
divider_agent = ConversableAgent(
name="Divider_Agent",
# GroupChatManager uses description to select the next agent when selection strategy is 'auto' (the default)
description="Divide each input number by 2.",
system_message="You divide each number I give you by 2 and return me the new numbers, one number each line.",
llm_config=llm_config,
human_input_mode="NEVER",
)
group_chat = GroupChat(
agents=[adder_agent, multiplier_agent,
subtracter_agent, divider_agent, number_agent],
messages=[],
max_round=6,
)
group_chat_manager = GroupChatManager(
groupchat=group_chat,
llm_config=llm_config,
)
chat_result = number_agent.initiate_chat(
group_chat_manager,
message="My number is 3, I want to turn it into 13.",
summary_method="reflection_with_llm",
)
print(chat_result.summary)