当前位置: 首页 > news >正文

【技术前沿】MetaGPT入门安装部署——用多个大语言模型解决任务!一键安装,只需填写OpenAI API

项目简介

MetaGPT 是一个多智能体框架,旨在构建全球首家 “AI 软件公司”。该项目通过为 GPT 分配不同的角色,模拟产品经理、架构师、工程师等职业,协同完成复杂的软件开发任务。MetaGPT 将一个简单的需求转化为完整的软件开发流程,包括用户故事、需求分析、数据结构设计和 API 文档生成等。其核心理念是将标准操作程序(SOP)应用于由多智能体组成的团队,使得自然语言编程成为可能。

项目地址:MetaGPT on GitHub


由于项目是英文的,博主在这里做一版中文教程,给后来人一些参考。
关注CSDN心若为城,获得计算机领域与人工智能领域的前沿技术。
博主碎碎念,可跳过:
打算重新做做自己这个老号,高中时候开始做CSDN,那会儿写的是NOIP/NOI相关的算法东西,纯粹是写给自己看的;现在时隔多年,我也在清华站稳了脚跟,在互联网开发和量化交易领域都算是小有成就了。
接下来这个号(也许也不止这个号)应该会做三个方向:
AI新技术(或者不局限于AI)的抢先浏览,会向大家说明当下热点论文、热点技术的部署等,以及做一些周报或者日报。(类似于AI Weekly)
量化交易相关,我在量化开发技术栈有着多年的开发经验,也拿过一些投资比赛的奖项。可以面向应届生给出就业规划,提供一些指导的同时分享一些含金量高的项目。
互联网面试相关,我应该会着重于分享一些面试的底层技术面,并且尽可能和2进行一些结合,让大家同时能handle住两边的技术。

在这里插入图片描述

安装说明

只需要一行!简单明了:

pip install --upgrade metagpt
# or `pip install --upgrade git+https://github.com/geekan/MetaGPT.git`
# or `git clone https://github.com/geekan/MetaGPT && cd MetaGPT && pip install --upgrade -e .`

然后运行下面的命令

# Check https://docs.deepwisdom.ai/main/en/guide/get_started/configuration.html for more details
metagpt --init-config  # it will create ~/.metagpt/config2.yaml, just modify it to your needs

这样会生成一个config文件,我们可以通过修改config文件来部署MetaGPT。

llm:api_type: "openai"  # or azure / ollama / groq etc. Check LLMType for more optionsmodel: "gpt-4-turbo"  # or gpt-3.5-turbobase_url: "https://api.openai.com/v1"  # or forward url / other llm urlapi_key: "YOUR_API_KEY"

MetaGPT 支持一系列 LLM 模型。根据需要配置模型 API 密钥。
也可以配置Claude:

llm:api_type: 'claude' # or anthropicbase_url: 'https://api.anthropic.com'api_key: 'YOUR_API_KEY'model: 'claude-3-opus-20240229'

额外工具的使用

除了 LLM 之外,我们还经常希望代理使用工具。这里将介绍这些工具的设置。

## Supported api_type: serpapi/google/serper/ddg
## serper: Visit https://serper.dev/ to get key.
## serpapi: Visit https://serpapi.com/ to get key.
## google: Visit https://console.cloud.google.com/apis/credentials to get key.
## ddg: it is free, no need to get key.
search:api_type: 'google' # serpapi/google/serper/ddgapi_key: 'YOUR_API_KEY'cse_id: 'YOUR_CSE_ID' # only for googleparams:engine: google # google/bing/yahoo/baidu/yandex, check https://serpapi.com/bing-search-api for more detailsgoogle_domain: 'google.com'gl: ushl: en

使用MetaGPT、导入已有的角色

我们可以用下面的代码来导入一个产品经理。
具体更复杂的用法,可以参考这个文档:Tutorials

import asynciofrom metagpt.context import Context
from metagpt.roles.product_manager import ProductManager
from metagpt.logs import loggerasync def main():msg = "Write a PRD for a snake game"context = Context()  # The session Context object is explicitly created, and the Role object implicitly shares it automatically with its own Action objectrole = ProductManager(context=context)while msg:msg = await role.run(msg)logger.info(str(msg))if __name__ == '__main__':asyncio.run(main())

使用MetaGPT进行数据分析与可视化

在这里,官方给了一些数据可视化的官方代码。

import asyncio
from metagpt.logs import logger
from metagpt.roles.di.data_interpreter import DataInterpreter
from metagpt.utils.recovery_util import save_historyasync def main(requirement: str = ""):di = DataInterpreter()rsp = await di.run(requirement)logger.info(rsp)save_history(role=di)if __name__ == "__main__":requirement = "Run data analysis on sklearn Iris dataset, include a plot"asyncio.run(main(requirement))

执行上述代码后,生成的计划和代码将分别保存在 data/output/current_time/plan.jsondata/output/current_time/code.ipynb 中。

执行结果

DataInterpreter 提出了以下解决方案任务:

[{"task_id": "1","dependent_task_ids": [],"instruction": "Load the Iris dataset from sklearn."},{"task_id": "2","dependent_task_ids": ["1"],"instruction": "Perform exploratory data analysis on the Iris dataset."},{"task_id": "3","dependent_task_ids": ["2"],"instruction": "Create a plot visualizing the Iris dataset features."}
]

DataInterpreter 能够将问题划分为逻辑任务,并按照加载数据、分析数据和绘制图表的步骤运行。

DataInterpreter 写入以下代码:

# ----------------------------------task1------------------------------------
from sklearn.datasets import load_iris
iris_data = load_iris()
iris_data.keys()
!pip install scikit-learn
from sklearn.datasets import load_iris
iris_data = load_iris()
iris_data.keys()
# ----------------------------------task2------------------------------------
import pandas as pd# Create a DataFrame from the iris dataset
iris_df = pd.DataFrame(iris_data['data'], columns=iris_data['feature_names'])
iris_df['species'] = pd.Categorical.from_codes(iris_data['target'], iris_data['target_names'])# Summary statistics
summary_statistics = iris_df.describe()# Check for missing values
missing_values = iris_df.isnull().sum()(summary_statistics, missing_values)
# ----------------------------------task3------------------------------------
import matplotlib.pyplot as plt
import seaborn as sns# Use seaborn's pairplot to visualize the dataset features
sns.set(style='whitegrid', context='notebook')
iris_pairplot = sns.pairplot(iris_df, hue='species', height=2.5)
plt.show()

在完成任务 1 的过程中,由于环境中没有安装 scikit-learn,第一次执行时发生了错误。不过, DataInterpreter 可以通过安装 scikit-learn 来分析并解决这个问题。在任务 3 中, DataInterpreter 使用 seaborn 中的 pairplot 函数创建散点图矩阵,该矩阵可视化数据集中不同特征之间的关系,并使用颜色区分不同物种的数据点。最后,使用 plt.show() 显示图表。
下图是 DataInterpreter 运行代码后绘制的图表。很明显,代码成功执行并生成了漂亮的可视化表格,可以帮助我们更有效地分析数据集的特征。
在这里插入图片描述希望查看更多内容,点这里进入官方文档查看。

总结

MetaGPT is all you need!

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • WPF 资源、引用命名空间格式、FrameworkElement、Binding、数据绑定
  • zdpgo_gin_sessions 专为zdpgo_gin打造的session框架,当需要使用session存储数据的时候可以考虑使用此框架
  • ZKRollup
  • 【LeetCode每日一题】——623.在二叉树中增加一行
  • 工厂模式和策略模式的使用策略及其优缺点比较
  • 【C#】委托/Lambda/事件
  • Python | Leetcode Python题解之第337题打家劫舍III
  • 单细胞课程01-课程简介
  • Qt题目知多少-4
  • 基于python 开发调试rabbitmq - 2
  • 鸿蒙前端开发——工具安装与项目创建
  • Vue2中watch与Vue3中watch对比
  • “论软件开发过程RUP及其应用”写作框架,软考高级,系统架构设计师
  • 使用 GPT-4 Vision 的 CLIP 嵌入来改进多模态 RAG
  • 【运维】JetBrains Gateway (Pycharm) SSH免密连接,改为免密连接
  • 【跃迁之路】【477天】刻意练习系列236(2018.05.28)
  • 230. Kth Smallest Element in a BST
  • docker-consul
  • eclipse(luna)创建web工程
  • E-HPC支持多队列管理和自动伸缩
  • Laravel Mix运行时关于es2015报错解决方案
  • opencv python Meanshift 和 Camshift
  • React组件设计模式(一)
  • Webpack4 学习笔记 - 01:webpack的安装和简单配置
  • XML已死 ?
  • 测试开发系类之接口自动化测试
  • 从输入URL到页面加载发生了什么
  • 官方新出的 Kotlin 扩展库 KTX,到底帮你干了什么?
  • 使用common-codec进行md5加密
  • 使用Gradle第一次构建Java程序
  • 数据库写操作弃用“SELECT ... FOR UPDATE”解决方案
  • 微信小程序:实现悬浮返回和分享按钮
  • 线上 python http server profile 实践
  • UI设计初学者应该如何入门?
  • ​卜东波研究员:高观点下的少儿计算思维
  • # AI产品经理的自我修养:既懂用户,更懂技术!
  • #ifdef 的技巧用法
  • #Z0458. 树的中心2
  • $redis-setphp_redis Set命令,php操作Redis Set函数介绍
  • (5)STL算法之复制
  • (done) ROC曲线 和 AUC值 分别是什么?
  • (补充)IDEA项目结构
  • (附源码)php投票系统 毕业设计 121500
  • (附源码)spring boot智能服药提醒app 毕业设计 102151
  • (附源码)ssm考生评分系统 毕业设计 071114
  • (附源码)计算机毕业设计高校学生选课系统
  • (三)c52学习之旅-点亮LED灯
  • (十三)Maven插件解析运行机制
  • (一)、python程序--模拟电脑鼠走迷宫
  • (一)SvelteKit教程:hello world
  • (已解决)报错:Could not load the Qt platform plugin “xcb“
  • (原創) X61用戶,小心你的上蓋!! (NB) (ThinkPad) (X61)
  • .net core 控制台应用程序读取配置文件app.config
  • .net 逐行读取大文本文件_如何使用 Java 灵活读取 Excel 内容 ?
  • .NET:自动将请求参数绑定到ASPX、ASHX和MVC(菜鸟必看)