python+qwen-agent实现多角色agent群聊代码
代码语言:python
所属分类:其他
代码描述:python+qwen-agent实现多角色agent群聊代码,将不同的角色agent放在一起群聊。
代码标签: python qwen-agent 多角色 agent 群聊 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/usr/local/python3/bin/python3 # -*- coding: utf-8 -* #pip install -U "qwen-agent[rag,code_interpreter,gui,mcp]" # 或者,使用 `pip install -U qwen-agent` 来安装最小依赖。 import json import json5 from qwen_agent.agents import GroupChat, GroupChatCreator from qwen_agent.agents.user_agent import PENDING_USER_INPUT from qwen_agent.gui.gradio_dep import gr, mgr, ms from qwen_agent.llm.schema import ContentItem, Message def init_agent_service(cfgs): llm_cfg = {'model': 'qwen-max','model_server': 'dashscope', 'api_key': 'sk-自己申请'} bot = GroupChat(agents=cfgs, llm=llm_cfg) return bot def init_agent_service_create(): llm_cfg = {'model': 'qwen-max'} bot = GroupChatCreator(llm=llm_cfg) return bot # ========================================================= # Below is the gradio service: front-end and back-end logic # ========================================================= app_global_para = { 'messages': [], 'messages_create': [], 'is_first_upload': False, 'uploaded_file': '', 'user_interrupt': True } # Initialized group chat configuration CFGS = { 'background': '一个陌生人互帮互助群聊', 'agents': [ { 'name': '小塘', 'description': '一个勤劳的打工人,每天沉迷工作,日渐消瘦。(这是一个真实用户)', 'is_human': True # mark this as a real person }, { 'name': '甄嬛', 'description': '一位后宫妃嫔', 'instructions': '你是甄嬛,你正在想办法除掉皇后,你说话风格为文言文,每次说完话会调image_gen工具画一幅图,展示心情。', 'knowledge_files': [], 'selected_tools': ['image_gen'] }, { 'name': 'ikun', 'description': '熟悉蔡徐坤的动态', 'instructions': '你是蔡徐坤的粉丝,说话很简短,喜欢用颜文字表达心情,你最近迷恋看《甄嬛传》', 'knowledge_files': [], 'selected_tools': [] }, { 'name': '大头.........完整代码请登录后点击上方下载按钮下载查看
网友评论0