forked from modelscope/agentscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-discussion.py
69 lines (60 loc) · 1.97 KB
/
auto-discussion.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
# -*- coding: utf-8 -*-
"""A simple example for auto discussion: the agent builder automatically\
set up the agents participating the discussion ."""
from tools import load_txt, extract_scenario_and_participants
import agentscope
from agentscope.agents import DialogAgent
from agentscope.pipelines.functional import sequentialpipeline
from agentscope.message import Msg
model_configs = [
{
"model_type": "openai_chat",
"config_name": "gpt-3.5-turbo",
"model_name": "gpt-3.5-turbo",
"api_key": "xxx", # Load from env if not provided
"organization": "xxx", # Load from env if not provided
"generate_args": {
"temperature": 0.5,
},
},
{
"model_type": "post_api_chat",
"config_name": "my_post_api",
"api_url": "https://xxx",
"headers": {},
"json_args": {},
},
]
agentscope.init(model_configs=model_configs)
# init the self-organizing conversation
agent_builder = DialogAgent(
name="agent_builder",
sys_prompt="You're a helpful assistant.",
model_config_name="my_post_api",
)
max_round = 2
query = "Say the pupil of your eye has a diameter of 5 mm and you have a \
telescope with an aperture of 50 cm. How much more light can the \
telescope gather than your eye?"
# get the discussion scenario and participant agents
x = load_txt(
"examples/conversation_self_organizing/agent_builder_instruct.txt",
).format(
question=query,
)
x = Msg("user", x, role="user")
settings = agent_builder(x)
scenario_participants = extract_scenario_and_participants(settings["content"])
# set the agents that participant the discussion
agents = [
DialogAgent(
name=key,
sys_prompt=val,
model_config_name="my_post_api",
)
for key, val in scenario_participants["Participants"].items()
]
# begin discussion
msg = Msg("user", f"let's discuss to solve the question: {query}", role="user")
for i in range(max_round):
msg = sequentialpipeline(agents, msg)