update
This commit is contained in:
2
2025.11.09_autogen/.env
Normal file
2
2025.11.09_autogen/.env
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
OPENAI_API_KEY=xxx
|
||||||
|
DASHSCOPE_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
|
||||||
67
2025.11.09_autogen/autogen_example.py
Normal file
67
2025.11.09_autogen/autogen_example.py
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/48024
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import autogen
|
||||||
|
import dotenv
|
||||||
|
|
||||||
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
|
config_list = [
|
||||||
|
{
|
||||||
|
"model": "qwen-plus",
|
||||||
|
"api_key": os.getenv("DASHSCOPE_API_KEY"),
|
||||||
|
"base_url": os.getenv("DASHSCOPE_BASE_URL"),
|
||||||
|
"price": [0.0008, 0.002],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
# 数学专家
|
||||||
|
math_expert = autogen.AssistantAgent(
|
||||||
|
name="MathExpert",
|
||||||
|
system_message="你是一个数学专家,擅长解决各种数学问题。",
|
||||||
|
llm_config={"config_list": config_list},
|
||||||
|
)
|
||||||
|
|
||||||
|
# 物理专家
|
||||||
|
physics_expert = autogen.AssistantAgent(
|
||||||
|
name="PhysicsExpert",
|
||||||
|
system_message="你是一个物理专家,擅长解决各种物理问题。",
|
||||||
|
llm_config={"config_list": config_list},
|
||||||
|
)
|
||||||
|
|
||||||
|
# 人工智能专家
|
||||||
|
AI_expert = autogen.AssistantAgent(
|
||||||
|
name="AIExpert",
|
||||||
|
system_message="你是一个人工智能专家,擅长解决各种人工智能问题。",
|
||||||
|
llm_config={"config_list": config_list},
|
||||||
|
)
|
||||||
|
|
||||||
|
# 用户代理
|
||||||
|
user_proxy = autogen.UserProxyAgent(
|
||||||
|
name="User",
|
||||||
|
human_input_mode="NEVER",
|
||||||
|
max_consecutive_auto_reply=10,
|
||||||
|
code_execution_config={"work_dir": "coding", "use_docker": False},
|
||||||
|
)
|
||||||
|
|
||||||
|
# 简单群聊
|
||||||
|
groupchat = autogen.GroupChat(
|
||||||
|
agents=[math_expert, physics_expert, AI_expert, user_proxy],
|
||||||
|
messages=[],
|
||||||
|
max_round=10,
|
||||||
|
speaker_selection_method="round_robin", # 轮流发言
|
||||||
|
)
|
||||||
|
|
||||||
|
manager = autogen.GroupChatManager(
|
||||||
|
groupchat=groupchat,
|
||||||
|
llm_config={"config_list": config_list},
|
||||||
|
)
|
||||||
|
|
||||||
|
# 启动任务
|
||||||
|
user_proxy.initiate_chat(
|
||||||
|
manager,
|
||||||
|
message="随便讨论一个话题,多相互讨论,每个人每次发言不超过200字。"
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user