Spaces:
Sleeping
Sleeping
Remove print message
Browse files
app.py
CHANGED
|
@@ -34,25 +34,42 @@ def get_description_text():
|
|
| 34 |
"""
|
| 35 |
|
| 36 |
|
| 37 |
-
template.main.append(
|
|
|
|
|
|
|
| 38 |
|
| 39 |
txt_model = TextInput(
|
| 40 |
-
name="Model Name",
|
|
|
|
|
|
|
|
|
|
| 41 |
)
|
| 42 |
pwd_openai_key = PasswordInput(
|
| 43 |
-
name="OpenAI API Key",
|
|
|
|
|
|
|
| 44 |
)
|
| 45 |
pwd_openai_url = PasswordInput(
|
| 46 |
-
name="OpenAI Base Url",
|
|
|
|
|
|
|
| 47 |
)
|
| 48 |
pwd_aoai_key = PasswordInput(
|
| 49 |
-
name="Azure OpenAI API Key",
|
|
|
|
|
|
|
| 50 |
)
|
| 51 |
pwd_aoai_url = PasswordInput(
|
| 52 |
-
name="Azure OpenAI Base Url",
|
|
|
|
|
|
|
| 53 |
)
|
| 54 |
file_cfg = pn.widgets.FileInput(filename="OAI_CONFIG_LIST", sizing_mode="stretch_width")
|
| 55 |
-
template.main.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
|
| 58 |
def get_config(tmpfilename="OAI_CONFIG_LIST"):
|
|
@@ -106,7 +123,9 @@ def get_config(tmpfilename="OAI_CONFIG_LIST"):
|
|
| 106 |
|
| 107 |
btn_add = Button(name="+", button_type="success")
|
| 108 |
btn_remove = Button(name="-", button_type="danger")
|
| 109 |
-
switch_code = Switch(
|
|
|
|
|
|
|
| 110 |
template.main.append(
|
| 111 |
pn.Row(
|
| 112 |
pn.pane.Markdown("## Add or Remove Agents: "),
|
|
@@ -155,7 +174,7 @@ btn_remove.on_click(remove_agent)
|
|
| 155 |
|
| 156 |
|
| 157 |
async def send_messages(recipient, messages, sender, config):
|
| 158 |
-
print(f"{sender.name} -> {recipient.name}: {messages[-1]['content']}")
|
| 159 |
chatiface.send(messages[-1]["content"], user=sender.name, respond=False)
|
| 160 |
return False, None # required to ensure the agent communication flow continues
|
| 161 |
|
|
@@ -173,7 +192,8 @@ class myGroupChatManager(autogen.GroupChatManager):
|
|
| 173 |
content = autogen.OpenAIWrapper.instantiate(
|
| 174 |
content,
|
| 175 |
message["context"],
|
| 176 |
-
self.llm_config
|
|
|
|
| 177 |
)
|
| 178 |
if "function_call" in message:
|
| 179 |
function_call = dict(message["function_call"])
|
|
@@ -220,13 +240,24 @@ def init_groupchat(event, collection_name):
|
|
| 220 |
else False
|
| 221 |
)
|
| 222 |
agent = initialize_agents(
|
| 223 |
-
llm_config,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
)
|
| 225 |
-
agent.register_reply([autogen.Agent, None], reply_func=send_messages, config={"callback": None})
|
| 226 |
agents.append(agent)
|
| 227 |
if len(agents) >= 3:
|
| 228 |
groupchat = autogen.GroupChat(
|
| 229 |
-
agents=agents,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
)
|
| 231 |
manager = myGroupChatManager(groupchat=groupchat, llm_config=llm_config)
|
| 232 |
else:
|
|
@@ -235,7 +266,13 @@ def init_groupchat(event, collection_name):
|
|
| 235 |
|
| 236 |
|
| 237 |
async def agents_chat(init_sender, manager, contents, agents):
|
| 238 |
-
recipient =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
if isinstance(init_sender, (RetrieveUserProxyAgent, MathUserProxyAgent)):
|
| 240 |
await init_sender.a_initiate_chat(recipient, problem=contents)
|
| 241 |
else:
|
|
@@ -250,7 +287,10 @@ async def reply_chat(contents, user, instance):
|
|
| 250 |
instance.collection_name = collection_name
|
| 251 |
|
| 252 |
column_agents_list = [agent[0][0].value for agent in column_agents]
|
| 253 |
-
if
|
|
|
|
|
|
|
|
|
|
| 254 |
agents, manager = init_groupchat(None, collection_name)
|
| 255 |
instance.manager = manager
|
| 256 |
instance.agents = agents
|
|
@@ -321,10 +361,18 @@ btn_msg2.on_click(load_message)
|
|
| 321 |
btn_msg3.on_click(load_message)
|
| 322 |
|
| 323 |
|
| 324 |
-
btn_example1 = Button(
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
template.main.append(
|
| 329 |
pn.Row(
|
| 330 |
pn.pane.Markdown("## Agent Examples: ", sizing_mode="stretch_width"),
|
|
@@ -492,7 +540,9 @@ btn_example2.on_click(load_example)
|
|
| 492 |
btn_example3.on_click(load_example)
|
| 493 |
btn_example4.on_click(load_example)
|
| 494 |
|
| 495 |
-
code_editor = CodeEditor(
|
|
|
|
|
|
|
| 496 |
template.main.append(code_editor)
|
| 497 |
|
| 498 |
template.servable(title=TITLE)
|
|
|
|
| 34 |
"""
|
| 35 |
|
| 36 |
|
| 37 |
+
template.main.append(
|
| 38 |
+
pn.pane.Markdown(get_description_text(), sizing_mode="stretch_width")
|
| 39 |
+
)
|
| 40 |
|
| 41 |
txt_model = TextInput(
|
| 42 |
+
name="Model Name",
|
| 43 |
+
placeholder="Enter your model name here...",
|
| 44 |
+
value="gpt-35-turbo",
|
| 45 |
+
sizing_mode="stretch_width",
|
| 46 |
)
|
| 47 |
pwd_openai_key = PasswordInput(
|
| 48 |
+
name="OpenAI API Key",
|
| 49 |
+
placeholder="Enter your OpenAI API Key here...",
|
| 50 |
+
sizing_mode="stretch_width",
|
| 51 |
)
|
| 52 |
pwd_openai_url = PasswordInput(
|
| 53 |
+
name="OpenAI Base Url",
|
| 54 |
+
placeholder="Enter your OpenAI Base Url here...",
|
| 55 |
+
sizing_mode="stretch_width",
|
| 56 |
)
|
| 57 |
pwd_aoai_key = PasswordInput(
|
| 58 |
+
name="Azure OpenAI API Key",
|
| 59 |
+
placeholder="Enter your Azure OpenAI API Key here...",
|
| 60 |
+
sizing_mode="stretch_width",
|
| 61 |
)
|
| 62 |
pwd_aoai_url = PasswordInput(
|
| 63 |
+
name="Azure OpenAI Base Url",
|
| 64 |
+
placeholder="Enter your Azure OpenAI Base Url here...",
|
| 65 |
+
sizing_mode="stretch_width",
|
| 66 |
)
|
| 67 |
file_cfg = pn.widgets.FileInput(filename="OAI_CONFIG_LIST", sizing_mode="stretch_width")
|
| 68 |
+
template.main.append(
|
| 69 |
+
pn.Row(
|
| 70 |
+
txt_model, pwd_openai_key, pwd_openai_url, pwd_aoai_key, pwd_aoai_url, file_cfg
|
| 71 |
+
)
|
| 72 |
+
)
|
| 73 |
|
| 74 |
|
| 75 |
def get_config(tmpfilename="OAI_CONFIG_LIST"):
|
|
|
|
| 123 |
|
| 124 |
btn_add = Button(name="+", button_type="success")
|
| 125 |
btn_remove = Button(name="-", button_type="danger")
|
| 126 |
+
switch_code = Switch(
|
| 127 |
+
name="Run Code", sizing_mode="fixed", width=50, height=30, align="end"
|
| 128 |
+
)
|
| 129 |
template.main.append(
|
| 130 |
pn.Row(
|
| 131 |
pn.pane.Markdown("## Add or Remove Agents: "),
|
|
|
|
| 174 |
|
| 175 |
|
| 176 |
async def send_messages(recipient, messages, sender, config):
|
| 177 |
+
# print(f"{sender.name} -> {recipient.name}: {messages[-1]['content']}")
|
| 178 |
chatiface.send(messages[-1]["content"], user=sender.name, respond=False)
|
| 179 |
return False, None # required to ensure the agent communication flow continues
|
| 180 |
|
|
|
|
| 192 |
content = autogen.OpenAIWrapper.instantiate(
|
| 193 |
content,
|
| 194 |
message["context"],
|
| 195 |
+
self.llm_config
|
| 196 |
+
and self.llm_config.get("allow_format_str_template", False),
|
| 197 |
)
|
| 198 |
if "function_call" in message:
|
| 199 |
function_call = dict(message["function_call"])
|
|
|
|
| 240 |
else False
|
| 241 |
)
|
| 242 |
agent = initialize_agents(
|
| 243 |
+
llm_config,
|
| 244 |
+
agent_name,
|
| 245 |
+
system_msg,
|
| 246 |
+
agent_type,
|
| 247 |
+
retrieve_config,
|
| 248 |
+
code_execution_config,
|
| 249 |
+
)
|
| 250 |
+
agent.register_reply(
|
| 251 |
+
[autogen.Agent, None], reply_func=send_messages, config={"callback": None}
|
| 252 |
)
|
|
|
|
| 253 |
agents.append(agent)
|
| 254 |
if len(agents) >= 3:
|
| 255 |
groupchat = autogen.GroupChat(
|
| 256 |
+
agents=agents,
|
| 257 |
+
messages=[],
|
| 258 |
+
max_round=12,
|
| 259 |
+
speaker_selection_method="auto",
|
| 260 |
+
allow_repeat_speaker=False,
|
| 261 |
)
|
| 262 |
manager = myGroupChatManager(groupchat=groupchat, llm_config=llm_config)
|
| 263 |
else:
|
|
|
|
| 266 |
|
| 267 |
|
| 268 |
async def agents_chat(init_sender, manager, contents, agents):
|
| 269 |
+
recipient = (
|
| 270 |
+
manager
|
| 271 |
+
if len(agents) > 2
|
| 272 |
+
else agents[1]
|
| 273 |
+
if agents[1] != init_sender
|
| 274 |
+
else agents[0]
|
| 275 |
+
)
|
| 276 |
if isinstance(init_sender, (RetrieveUserProxyAgent, MathUserProxyAgent)):
|
| 277 |
await init_sender.a_initiate_chat(recipient, problem=contents)
|
| 278 |
else:
|
|
|
|
| 287 |
instance.collection_name = collection_name
|
| 288 |
|
| 289 |
column_agents_list = [agent[0][0].value for agent in column_agents]
|
| 290 |
+
if (
|
| 291 |
+
not hasattr(instance, "agent_list")
|
| 292 |
+
or instance.agents_list != column_agents_list
|
| 293 |
+
):
|
| 294 |
agents, manager = init_groupchat(None, collection_name)
|
| 295 |
instance.manager = manager
|
| 296 |
instance.agents = agents
|
|
|
|
| 361 |
btn_msg3.on_click(load_message)
|
| 362 |
|
| 363 |
|
| 364 |
+
btn_example1 = Button(
|
| 365 |
+
name="General 2 agents", button_type="primary", sizing_mode="stretch_width"
|
| 366 |
+
)
|
| 367 |
+
btn_example2 = Button(
|
| 368 |
+
name="RAG 2 agents", button_type="primary", sizing_mode="stretch_width"
|
| 369 |
+
)
|
| 370 |
+
btn_example3 = Button(
|
| 371 |
+
name="Software Dev 3 agents", button_type="primary", sizing_mode="stretch_width"
|
| 372 |
+
)
|
| 373 |
+
btn_example4 = Button(
|
| 374 |
+
name="Research 6 agents", button_type="primary", sizing_mode="stretch_width"
|
| 375 |
+
)
|
| 376 |
template.main.append(
|
| 377 |
pn.Row(
|
| 378 |
pn.pane.Markdown("## Agent Examples: ", sizing_mode="stretch_width"),
|
|
|
|
| 540 |
btn_example3.on_click(load_example)
|
| 541 |
btn_example4.on_click(load_example)
|
| 542 |
|
| 543 |
+
code_editor = CodeEditor(
|
| 544 |
+
value="", sizing_mode="stretch_width", language="python", height=300
|
| 545 |
+
)
|
| 546 |
template.main.append(code_editor)
|
| 547 |
|
| 548 |
template.servable(title=TITLE)
|