【大模型】Autogen使用两个agent基于gpt扮演角色情景对话,包含二者的system_message

AutoGen提供了一个统一的多代理对话框架,作为使用基础模型的高级抽象。它的特点是功能强大、可定制且可对话的代理,这些代理通过自动代理聊天集成了llm、工具和人员。通过在多个有能力的代理之间自动化聊天,可以很容易地让它们共同自主地执行任务或使用人工反馈,包括需要通过代码使用工具的任务。

假设你已经按照需求安装了需要的环境,下面将会展示两个示例👇👇

1. 在Autogen的示例中,提供了两个agent的测试脚本,以下是运行方式:

cd test
python twoagent.py 

有两个代理,用户让assistant画股票图,assistant给出了画的代码,但没有执行可视化展示

2.第二个例子是基于一个情景对话,让两个agent进行角色扮演:

system_message:扮演约翰。你现在正在参加新学期的开学典礼,碰巧遇到了你的新同学。你的任务是和新同学攀谈起来。为了更好地了解彼此,你可以问她的家乡,兴趣爱好,可以讨论家庭成员和其他相关的事情。你也可以谈论你未来的目标和过去的有趣经历。

user_message:你是安迪。你现在正在参加新学期的开学典礼,你刚刚遇到了一位新同学。为了开启一段新的友谊,你需要向他介绍自己。你可以告诉他你的家乡、兴趣、家庭成员以及其它相关细节。

由assistant先说第一句话,让用户来回答。代码参考如下:

from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
import openai

# config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST")
assistant = AssistantAgent(
    name = "assistant", 
    code_execution_config={"work_dir": "coding"},
    llm_config={"model": "gpt-4", "api_key": "换成你自己的key"},
    # human_input_mode="TERMINATE",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=4,
    system_message = "Act as a real human being John. You are now attending the opening ceremony of the new semester and happen to meet your new classmate. Your task is to strike up a conversation with the new classmate. To get to know each other better, you can ask her about her hometown, interests such as her favorite books, music and movies. ",
    )
user_proxy = UserProxyAgent(
    name = "user_proxy", 
    llm_config={"model": "gpt-4", "api_key": "换成你自己的key"},
    human_input_mode="NEVER", 
    system_message = "You are Andy. You are currently attending the opening ceremony of a new semester, and you have just met a new classmate. To establish a new friendship, you need to  introduce yourself to him. You can tell him about your hometown, interests, family members, and any other relevant details. ",
    )
assistant.initiate_chat(
    user_proxy,
    message="Hello, I'm John. Are you new here?",
)

对话效果很不错🐮:

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

炭市街潜水豆浆

勇敢的人先体验生活

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值