TinyTroupe:微软推出的多智能体角色模拟库,支持虚拟人物之间的互动,模拟复杂的社交场景

396 阅读4分钟

❤️ 如果你也关注大模型与 AI 的发展现状,且对大模型应用开发非常感兴趣,我会快速跟你分享最新的感兴趣的 AI 应用和热点信息,也会不定期分享自己的想法和开源实例,欢迎关注我哦!

🥦 微信公众号|搜一搜:蚝油菜花 🥦


🚀 快速阅读

  1. TinyTroupe 是一款实验性 Python 库,用于模拟具有特定个性、兴趣和目标的虚拟人物(TinyPersons)在模拟环境(TinyWorld)中的互动。
  2. 基于大型语言模型(如 GPT-4)生成逼真的行为,研究人类行为和消费者类型。
  3. 应用场景广泛,包括广告评估、软件测试、数据训练、市场机会分析等。

正文(附运行示例)

TinyTroupe 是什么

TinyTroupe

TinyTroupe 是微软推出的一款实验性 Python 库,用于模拟具有特定个性、兴趣和目标的虚拟人物(TinyPersons)在模拟环境(TinyWorld)中的互动。TinyTroupe 基于大型语言模型(如 GPT-4)生成逼真的行为,研究人类行为和消费者类型,旨在理解人类行为,为企业和生产力场景提供启示。

TinyTroupe 的主要功能

  1. 模拟人物行为:模拟具有特定个性、兴趣和目标的虚拟人物(TinyPerson)在模拟环境(TinyWorld)中的行为。
  2. 多智能体互动:支持虚拟人物之间的互动,模拟复杂的社交场景。
  3. 高度可定制的虚拟角色:用户根据需求定制虚拟角色的各种属性,如年龄、性别、职业、性格、兴趣等。
  4. 广泛的应用场景:应用场景广泛,包括广告评估、软件测试、数据训练、市场机会分析等。

TinyTroupe 的技术原理

  1. 基于大型语言模型(LLM):特别是 GPT-4,生成具有逻辑和连贯性的模拟行为。
  2. TinyPerson 与 TinyWorld:包含两个核心组件,TinyPerson 用于创建具有独特性格的虚拟角色,TinyWorld 构建角色互动的环境。
  3. 内容过滤与安全机制:内置内容过滤机制和严格的使用准则,确保工具的安全性。
  4. 个性建模:根据用户定义的性格、兴趣和目标,构建 TinyPerson 的个性模型。
  5. 行为生成:用 GPT-4 生成 TinyPerson 在特定场景下的行为和反应。
  6. 环境互动:在 TinyWorld 环境中,TinyPerson 与其他虚拟角色进行互动,模拟真实世界的行为模式。

如何运行 TinyTroupe

安装步骤

  1. 创建 Python 环境
conda create -n tinytroupe python=3.10
conda activate tinytroupe
  1. 设置 API 密钥
  • 对于 Azure OpenAI Service,设置 AZURE_OPENAI_KEYAZURE_OPENAI_ENDPOINT 环境变量。
  • 对于 OpenAI,设置 OPENAI_API_KEY 环境变量。
  1. 克隆仓库
git clone https://github.com/microsoft/TinyTroupe
cd TinyTroupe
  1. 安装库
pip install .

示例代码

from tinytroupe.examples import create_lisa_the_data_scientist
from tinytroupe.world import TinyWorld

# 创建虚拟角色
lisa = create_lisa_the_data_scientist()

# 创建模拟环境
world = TinyWorld("Chat Room", [lisa])

# 设置对话
lisa.listen("Talk to Oscar to know more about him")
world.run(4)

运行结果

USER --> Lisa: [CONVERSATION]
          > Talk to Oscar to know more about him
────────────────────────────────────────────── Chat Room step 1 of 4 ──────────────────────────────────────────────
Lisa --> Lisa: [THOUGHT]
          > I will now act a bit, and then issue DONE.
Lisa acts: [TALK]
          > Hi Oscar, I'd love to know more about you. Could you tell me a bit about yourself?
Lisa --> Lisa: [THOUGHT]
          > I will now act a bit, and then issue DONE.
Lisa acts: [DONE]

Lisa --> Oscar: [CONVERSATION]
          > Hi Oscar, I'd love to know more about you. Could you tell me a bit about yourself?
Oscar --> Oscar: [THOUGHT]
           > I will now act a bit, and then issue DONE.
Oscar acts: [TALK]
           > Hi Lisa! Sure, I'd be happy to share a bit about myself. I'm Oscar, a 30-year-old
           > architect from Germany. I work at a company called Awesome Inc., where I focus on
           > designing standard elements for new apartment buildings. I love modernist architecture,
           > new technologies, and sustainable practices. In my free time, I enjoy traveling to
           > exotic places, playing the guitar, and reading science fiction books. How about you?
Oscar --> Oscar: [THOUGHT]
           > I will now act a bit, and then issue DONE.
Oscar acts: [DONE]

Oscar --> Lisa: [CONVERSATION]
           > Hi Lisa! Sure, I'd be happy to share a bit about myself. I'm Oscar, a 30-year-old
           > architect from Germany. I work at a company called Awesome Inc., where I focus on
           > designing standard elements for new apartment buildings. I love modernist architecture,
           > new technologies, and sustainable practices. In my free time, I enjoy traveling to
           > exotic places, playing the guitar, and reading science fiction books. How about you?

资源

  1. GitHub 仓库:github.com/microsoft/T…

❤️ 如果你也关注大模型与 AI 的发展现状,且对大模型应用开发非常感兴趣,我会快速跟你分享最新的感兴趣的 AI 应用和热点信息,也会不定期分享自己的想法和开源实例,欢迎关注我哦!

🥦 微信公众号|搜一搜:蚝油菜花 🥦